Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 242 |
ExamStudentAdditionalDetailsService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
2162.00 | |
0.00% |
0 / 242 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
saveExamStudentAdditionalDetails | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 30 |
|||
validateSaveExamStudentAdditionalDetails | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 3 |
|||
insertExamStudentAdditionalDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 11 |
|||
deleteExamStudentAdditionalDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 23 |
|||
getExamStudentAdditionalDetails | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 49 |
|||
getStudentAdditionalCredit | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 62 |
|||
getAllStudentDetailsByAdditionalDetails | |
0.00% |
0 / 1 |
90.00 | |
0.00% |
0 / 61 |
<?php | |
namespace com\linways\ec\core\service; | |
use com\linways\base\util\MakeSingletonTrait; | |
use com\linways\base\util\SecurityUtils; | |
use com\linways\ec\core\constant\StatusConstants; | |
use com\linways\ec\core\exception\ExamControllerException; | |
use com\linways\ec\core\dto\ExamStudentAdditionalDetails; | |
use com\linways\ec\core\logging\Events; | |
use com\linways\ec\core\logging\entities\Staff; | |
use com\linways\core\ams\professional\logging\AMSLogger; | |
class ExamStudentAdditionalDetailsService extends BaseService | |
{ | |
use MakeSingletonTrait; | |
private function __construct() | |
{ | |
$this->logger = AMSLogger::getLogger('exam-controller-log'); | |
} | |
/** | |
* Save fee Type | |
* @param ExamStudentAdditionalDetails $examStudentAdditionalDetails | |
* @return $id | |
*/ | |
public function saveExamStudentAdditionalDetails(ExamStudentAdditionalDetails $examStudentAdditionalDetails){ | |
$examStudentAdditionalDetails = $this->realEscapeObject($examStudentAdditionalDetails); | |
$staffId = $GLOBALS['userId']; | |
$examStudentAdditionalDetails->createdBy = $GLOBALS['userId']; | |
$examStudentAdditionalDetails->updatedBy = $GLOBALS['userId']; | |
try { | |
$this->validateSaveExamStudentAdditionalDetails($examStudentAdditionalDetails); | |
$examStudentAdditionalDetails->id = $this->insertExamStudentAdditionalDetails($examStudentAdditionalDetails); | |
AMSLogger::log_info($this->logger,Events::EC_SAVE_STUDENT_ADDITIONAL_DETAILS, [ | |
"staff" => new Staff(["id" => $staffId]), | |
"request" => $examStudentAdditionalDetails, | |
"status" => StatusConstants::SUCCESS | |
]); | |
} catch (\Exception $e) { | |
AMSLogger::log_error($this->logger,Events::EC_SAVE_STUDENT_ADDITIONAL_DETAILS, [ | |
"staff" => new Staff(["id" => $staffId]), | |
"request" => $examStudentAdditionalDetails, | |
"errorCode" => $e->getCode(), | |
"errorMessage" => $e->getMessage(), | |
"status" => StatusConstants::FAILED | |
]); | |
if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") { | |
throw new ExamControllerException($e->getCode(), "Failed to save student details! Please try again"); | |
} else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) { | |
throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot create student details.This student details already created"); | |
} else { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
} | |
return $examStudentAdditionalDetails->id; | |
} | |
/** | |
* Validate exam Student Additional Details Request Before Saving | |
* @param ExamStudentAdditionalDetails $examStudentAdditionalDetails | |
* @return NULL | |
*/ | |
private function validateSaveExamStudentAdditionalDetails(ExamStudentAdditionalDetails $examStudentAdditionalDetails){ | |
if (empty($examStudentAdditionalDetails->studentId) || empty($examStudentAdditionalDetails->programId) || empty($examStudentAdditionalDetails->type)) | |
throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " Empty Parameter"); | |
} | |
/** | |
* Insert Exam Student Additional Details | |
* @param ExamStudentAdditionalDetails $examStudentAdditionalDetails | |
* @return $id | |
*/ | |
private function insertExamStudentAdditionalDetails(ExamStudentAdditionalDetails $examStudentAdditionalDetails){ | |
$properties = !empty($examStudentAdditionalDetails->properties) ? "'" . json_encode($examStudentAdditionalDetails->properties) . "'" : "'{}'"; | |
$query = "INSERT INTO ec_student_additional_details | |
(student_id,program_id,`type`,properties,created_by,updated_by) | |
VALUES ('$examStudentAdditionalDetails->studentId','$examStudentAdditionalDetails->programId','$examStudentAdditionalDetails->type',$properties,'$examStudentAdditionalDetails->createdBy','$examStudentAdditionalDetails->updatedBy') ON DUPLICATE KEY UPDATE `properties` = VALUES(properties),`updated_by` = VALUES(created_by)"; | |
try { | |
$examStudentAdditionalDetails->id = $this->executeQuery($query,true)->id; | |
return $examStudentAdditionalDetails->id; | |
} catch (\Exception $e) { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* Delete Exam Fee Type | |
* @param String $id | |
* @return NULL | |
*/ | |
public function deleteExamStudentAdditionalDetails($id){ | |
$id = $this->realEscapeString($id); | |
$staffId = $GLOBALS['userId']; | |
$examStudentAdditionalDetails = new \stdClass(); | |
$examStudentAdditionalDetails->id = $id; | |
$currentExamStudentAdditionalDetails = reset($this->getExamStudentAdditionalDetails($examStudentAdditionalDetails)); | |
if(empty($currentExamStudentAdditionalDetails)){ | |
throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS,"Can't delete ! Fee Type missing."); | |
} | |
$query = "DELETE FROM | |
ec_student_additional_details | |
WHERE | |
id = '$id'"; | |
try { | |
$this->executeQuery($query); | |
// LOGGING | |
AMSLogger::log_info($this->logger,Events::EC_DELETE_STUDENT_ADDITIONAL_DETAILS,[ | |
"staff" => new Staff(["id" => $staffId]), | |
"request" => $currentExamStudentAdditionalDetails, | |
"status" => StatusConstants::SUCCESS | |
]); | |
}catch (\Exception $e) { | |
throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Error deleting mderation rule! Please try again"); | |
} | |
} | |
/** | |
* get exam Student Additional Details | |
* @param $searchRequest | |
* @return $examStudentAdditionalDetails | |
*/ | |
public function getExamStudentAdditionalDetails($searchRequest){ | |
$searchRequest = $this->realEscapeObject($searchRequest); | |
try { | |
$whereQuery = null; | |
$whereQuery = ""; | |
if (!empty($searchRequest->id)) { | |
$examStudentAdditionalDetailsIdString = is_array($searchRequest->id) ? "'" . implode("','", $searchRequest->id) . "'" : "'" . $searchRequest->id . "'"; | |
$whereQuery .= " AND esad.id IN ( $examStudentAdditionalDetailsIdString )"; | |
} | |
if (!empty($searchRequest->studentId)) { | |
$studentIdString = is_array($searchRequest->studentId) ? "'" . implode("','", $searchRequest->studentId) . "'" : "'" . $searchRequest->studentId . "'"; | |
$whereQuery .= " AND esad.student_id IN ( $studentIdString )"; | |
} | |
if (!empty($searchRequest->programId)) { | |
$programIdString = is_array($searchRequest->programId) ? "'" . implode("','", $searchRequest->programId) . "'" : "'" . $searchRequest->programId . "'"; | |
$whereQuery .= " AND esad.program_id IN ( $programIdString )"; | |
} | |
if (!empty($searchRequest->type)) { | |
$typeString = is_array($searchRequest->type) ? "'" . implode("','", $searchRequest->type) . "'" : "'" . $searchRequest->type . "'"; | |
$whereQuery .= " AND esad.type IN ( $typeString )"; | |
} | |
$query = "SELECT | |
DISTINCT | |
esad.id as id, | |
esad.student_id as studentId, | |
esad.program_id as programId, | |
esad.type as type, | |
esad.properties as properties | |
FROM | |
ec_student_additional_details esad | |
WHERE | |
1 = 1 "; | |
$examStudentAdditionalDetails = $this->executeQueryForList($query . $whereQuery); | |
AMSLogger::log_info($this->logger,Events::EC_SEARCH_STUDENT_ADDITIONAL_DETAILS, [ | |
"staff" => new Staff(["id" => $staffId]), | |
"request" => $examStudentAdditionalDetails, | |
"status" => StatusConstants::SUCCESS | |
]); | |
} catch (\Exception $e) { | |
AMSLogger::log_error($this->logger,Events::EC_SEARCH_STUDENT_ADDITIONAL_DETAILS, [ | |
"staff" => new Staff(["id" => $staffId]), | |
"request" => $examStudentAdditionalDetails, | |
"errorCode" => $e->getCode(), | |
"errorMessage" => $e->getMessage(), | |
"status" => StatusConstants::FAILED | |
]); | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
return $examStudentAdditionalDetails; | |
} | |
/** | |
* get All Student additional Credit Details | |
* @param $request | |
* @return studentDetails | |
*/ | |
public function getStudentAdditionalCredit($request){ | |
$request = $this->realEscapeObject($request); | |
try{ | |
$sortBy = " ORDER BY spa.properties->>'$.registerNumber' ASC "; | |
$joinQueary .= " LEFT JOIN ec_student_additional_details esad ON | |
esad.student_id = sa.studentID AND esad.program_id = p.id AND esad.type = 'ADDITIONAL_CREDIT' "; | |
if(!empty($request->studentId)){ | |
$whereQuery .= " AND sa.studentID = '$request->studentId'"; | |
} | |
if(!empty($request->registerNo)){ | |
$whereQuery .= " AND spa.properties->>'$.registerNumber' = '$request->registerNo'"; | |
} | |
if(!empty($request->groupId)){ | |
$groupIdString = is_array($request->groupId) ? "'" . implode("','",$request->groupId) . "'" : "'".$request->groupId."'"; | |
$whereQuery .= " AND g.id IN ( $groupIdString )"; | |
} | |
$query = "SELECT DISTINCT | |
sa.studentID as studentId, | |
sa.studentName as name, | |
sa.studentEmail as email, | |
sa.studentPhone as phone, | |
spa.properties->>'$.registerNumber' AS registerNo, | |
p.id AS programId, | |
g.id AS groupId, | |
g.name AS groupName, | |
d.deptName as deptCode, | |
d.departmentDesc as deptName, | |
esad.properties as additionalCreditProperties | |
FROM | |
`groups` g | |
INNER JOIN group_members gm ON | |
gm.groups_id = g.id | |
INNER JOIN program p ON | |
p.id = g.properties->>'$.programId' | |
INNER JOIN student_program_account spa ON | |
spa.id = gm.members->>'$.studentId' AND | |
spa.current_program_id = p.id AND | |
spa.current_batch_id = g.id AND | |
spa.properties->>'$.academicStatus' IN ('ACTIVE','COMPLETED') | |
INNER JOIN studentaccount sa ON | |
sa.studentID = spa.student_id | |
INNER JOIN department d ON | |
d.deptID = g.properties ->> '$.departmentId' | |
$joinQueary | |
WHERE | |
g.`type` = 'BATCH' "; | |
$studentDetails = $this->executeQueryForList($query.$whereQuery.$sortBy.$limitQuery); | |
} | |
catch(\Exception $e) { | |
throw new ExamControllerException ($e->getCode(),$e->getMessage()); | |
} | |
array_walk($studentDetails,function($student){ | |
$student->creditActivity = ""; | |
$student->credit = ""; | |
$student->additionalCreditProperties = $student->additionalCreditProperties ? json_decode($student->additionalCreditProperties) : new \stdClass; | |
if($student->additionalCreditProperties){ | |
$student->creditActivity = $student->additionalCreditProperties->creditActivity ? $student->additionalCreditProperties->creditActivity : ''; | |
$student->credit = $student->additionalCreditProperties->credit != NULL ? $student->additionalCreditProperties->credit : '' ; | |
} | |
}); | |
$searchResponse = new \stdClass; | |
$searchResponse->students = $studentDetails; | |
return $searchResponse; | |
} | |
/** | |
* get All Student Details By additional Details | |
* @param $request | |
* @return studentDetails | |
*/ | |
public function getAllStudentDetailsByAdditionalDetails($request){ | |
$request = $this->realEscapeObject($request); | |
try{ | |
$whereQuery = ""; | |
$limitQuery = ""; | |
$joinQueary = ""; | |
$sortBy = " ORDER BY spa.properties->>'$.registerNumber' ASC "; | |
if(($request->isFetchAppliedStudentsOnly)){ | |
$joinQueary .= " INNER JOIN ec_student_additional_details esad ON | |
esad.student_id = sa.studentID AND esad.program_id = p.id "; | |
} | |
else{ | |
$joinQueary .= " LEFT JOIN ec_student_additional_details esad ON | |
esad.student_id = sa.studentID AND esad.program_id = p.id "; | |
} | |
if(!empty($request->studentId)){ | |
$whereQuery .= " AND sa.studentID = '$request->studentId'"; | |
} | |
if(!empty($request->groupId)){ | |
$groupIdString = is_array($request->groupId) ? "'" . implode("','",$request->groupId) . "'" : "'".$request->groupId."'"; | |
$whereQuery .= " AND g.id IN ( $groupIdString )"; | |
} | |
if(!empty($request->type)){ | |
$typeString = is_array($request->type) ? "'" . implode("','",$request->type) . "'" : "'".$request->type."'"; | |
$whereQuery .= " AND esad.type IN ( $typeString )"; | |
} | |
$query = "SELECT DISTINCT | |
sa.studentID as studentId, | |
sa.studentName as name, | |
sa.studentEmail as email, | |
sa.studentPhone as phone, | |
spa.properties->>'$.registerNumber' AS registerNo, | |
p.id AS programId, | |
g.id AS groupId, | |
g.name AS groupName, | |
esad.properties as properties | |
FROM | |
`groups` g | |
INNER JOIN group_members gm ON | |
gm.groups_id = g.id | |
INNER JOIN program p ON | |
p.id = g.properties->>'$.programId' | |
INNER JOIN student_program_account spa ON | |
spa.id = gm.members->>'$.studentId' AND | |
spa.current_program_id = p.id AND | |
spa.current_batch_id = g.id AND | |
spa.properties->>'$.academicStatus' IN ('ACTIVE','COMPLETED') | |
INNER JOIN studentaccount sa ON | |
sa.studentID = spa.student_id | |
$joinQueary | |
WHERE | |
g.`type` = 'BATCH' "; | |
$studentDetails = $this->executeQueryForList($query.$whereQuery.$sortBy.$limitQuery); | |
} | |
catch(\Exception $e) { | |
throw new ExamControllerException ($e->getCode(),$e->getMessage()); | |
} | |
array_walk($studentDetails,function($student){ | |
$student->isSelected = false; | |
$student->properties = $student->properties ? json_decode($student->properties) : new \stdClass; | |
}); | |
return $studentDetails; | |
} | |
} |