Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 292 |
| FalseNumberGroupService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
2756.00 | |
0.00% |
0 / 292 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| saveFalseNumberGroup | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 32 |
|||
| insertFalseNumberGroup | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| updateFalseNumberGroup | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 16 |
|||
| deleteFalseNumberGroup | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 26 |
|||
| validateSaveFalseNumberGroup | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
| getAssignedSubjectByExamRegForFalseNumberGroup | |
0.00% |
0 / 1 |
182.00 | |
0.00% |
0 / 65 |
|||
| getAllAssignedGroupsByExamRegId | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 27 |
|||
| getSubjectFromFalseNumberGroupId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 20 |
|||
| getAllFalseNumberGroups | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 22 |
|||
| getAllAssignedGroupsFacultiesByExamRegId | |
0.00% |
0 / 1 |
182.00 | |
0.00% |
0 / 66 |
|||
| <?php | |
| namespace com\linways\ec\core\service; | |
| use com\linways\ec\core\dto\FalseNumberGroup; | |
| use com\linways\ec\core\dto\FalseNumberSettingExamLog; | |
| 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\mapper\FalseNumberGroupServiceMapper; | |
| use com\linways\core\ams\professional\logging\AMSLogger; | |
| use com\linways\ec\core\logging\Events; | |
| use com\linways\ec\core\logging\entities\Staff; | |
| class FalseNumberGroupService extends BaseService | |
| { | |
| use MakeSingletonTrait; | |
| private function __construct() { | |
| $this->mapper = FalseNumberGroupServiceMapper::getInstance()->getMapper(); | |
| $this->logger = AMSLogger::getLogger('exam-controller-log'); | |
| } | |
| /** | |
| * Save False Number Group | |
| * @author Krishnajith | |
| * @param FalseNumberGroup $falseNumberGroup | |
| * @throws ExamControllerException | |
| */ | |
| public function saveFalseNumberGroup(FalseNumberGroup $falseNumberGroup){ | |
| $falseNumberGroup = $this->realEscapeObject($falseNumberGroup); | |
| try{ | |
| $this->validateSaveFalseNumberGroup($falseNumberGroup); | |
| if(!empty($falseNumberGroup->id)){ | |
| $falseNumberGroup->id = $this->updateFalseNumberGroup($falseNumberGroup); | |
| } | |
| else{ | |
| $falseNumberGroup->id = $this->insertFalseNumberGroup($falseNumberGroup); | |
| } | |
| AMSLogger::log_info($this->logger,Events::CREATE_FALSE_NUMBER_GROUP,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroup, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| }catch(\Exception $e) { | |
| AMSLogger::log_error($this->logger,Events::CREATE_FALSE_NUMBER_GROUP,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroupRelation, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| if($e->getCode() !== ExamControllerException::INVALID_PARAMETERS_FALSE_NUMBER_GROUP && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS_FALSE_NUMBER_GROUP && $e->getCode() !== "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException($e->getCode(),"Failed to save False Number Group! Please try again"); | |
| } else if ($e->getCode() === "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException (ExamControllerException::DUPLICATE_ENTRY_FALSE_NUMBER_GROUP,"Cannot create False Number Group.This Group Name is Already Taken!"); | |
| } else { | |
| throw new ExamControllerException ($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| return $falseNumberGroup->id ; | |
| } | |
| /** | |
| * Insert False Number Group | |
| * @author Krishnajith | |
| * @param FalseNumberGroup $falseNumberGroup | |
| * @return $id | |
| */ | |
| private function insertFalseNumberGroup(FalseNumberGroup $falseNumberGroup){ | |
| $query = "INSERT INTO assignstaff_exam_groupname | |
| (group_name,examTypeFlag,thirdValuationFlag) | |
| VALUES | |
| ('$falseNumberGroup->groupName','$falseNumberGroup->examTypeFlag','$falseNumberGroup->thirdValuationFlag')"; | |
| try { | |
| $falseNumberGroup->id = $this->executeQueryForObject($query,true); | |
| return $falseNumberGroup->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Update False Number Group | |
| * @author Krishnajith | |
| * @param FalseNumberGroup $falseNumberGroup | |
| * @return $id | |
| */ | |
| private function updateFalseNumberGroup(FalseNumberGroup $falseNumberGroup) | |
| { | |
| $query = "UPDATE | |
| assignstaff_exam_groupname | |
| SET | |
| group_name = '$falseNumberGroup->groupName', | |
| examTypeFlag = $falseNumberGroup->examTypeFlag, | |
| thirdValuationFlag = '$falseNumberGroup->thirdValuationFlag' | |
| WHERE | |
| id = '$falseNumberGroup->id'"; | |
| try { | |
| $this->executeQuery($query); | |
| return $falseNumberGroup->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete falseNumberGroup (Soft Delete) | |
| * @param String $id | |
| * @return NULL | |
| */ | |
| public function deleteFalseNumberGroup($id){ | |
| $id = $this->realEscapeString($id); | |
| if(empty($id)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_FALSE_NUMBER_GROUP,"False Number Group is Missing"); | |
| } | |
| $query = "DELETE FROM | |
| assignstaff_exam_groupname | |
| WHERE | |
| id = '$id'"; | |
| try { | |
| $this->executeQuery($query); | |
| AMSLogger::log_info($this->logger,Events::DELETE_FALSE_NUMBER_GROUP,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $query, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| } catch (\Exception $e) { | |
| AMSLogger::log_error($this->logger,Events::DELETE_FALSE_NUMBER_GROUP,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $query, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| throw new ExamControllerException(ExamControllerException::ERROR_DELETING_FALSE_NUMBER_GROUP,"Error deleting False Number Group! Please try again"); | |
| } | |
| } | |
| /** | |
| * Validate False Number Group Request Before Saving | |
| * @param FalseNumberGroup $falseNumberGroup | |
| * @return NULL | |
| */ | |
| private function validateSaveFalseNumberGroup(FalseNumberGroup $falseNumberGroup) | |
| { | |
| if(empty($falseNumberGroup->groupName)) | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_FALSE_NUMBER_GROUP," False Number Group name is empty! Please choose name for False Number Group"); | |
| } | |
| /** | |
| * Get Exam Registration Subject For False Number Group | |
| * *@param ExamRegisrationId @examRegisrationId | |
| * @return assignedSubjects | |
| */ | |
| public function getAssignedSubjectByExamRegForFalseNumberGroup($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $orderBy = " ORDER BY s.code ASC "; | |
| $whereQuery = null; | |
| if($searchRequest->isAvoidPracticalSub){ | |
| $whereQuery .= " AND JSON_CONTAINS(aps.properties, '{\"isPractical\":\"false\"}') "; | |
| } | |
| if(!empty($searchRequest->academicPaperSubjectId)) { | |
| $academicPaperSubjectIdString = is_array($searchRequest->academicPaperSubjectId) ? "'" . implode("','",$searchRequest->academicPaperSubjectId) . "'" : "'".$searchRequest->academicPaperSubjectId."'"; | |
| $whereQuery .= " AND eers.cm_academic_paper_subjects_id IN ( $academicPaperSubjectIdString )"; | |
| } | |
| if(!empty($searchRequest->groupId)) { | |
| $groupIdString = is_array($searchRequest->groupId) ? "'" . implode("','",$searchRequest->groupId) . "'" : "'".$searchRequest->groupId."'"; | |
| $whereQuery .= " AND g.id IN ( $groupIdString )"; | |
| } | |
| if(!empty($searchRequest->examRegistrationId)) { | |
| $examRegistrationIdString = is_array($searchRequest->examRegistrationId) ? "'" . implode("','",$searchRequest->examRegistrationId) . "'" : "'".$searchRequest->examRegistrationId."'"; | |
| $whereQuery .= " AND eerb.ec_exam_registration_id IN ( $examRegistrationIdString )"; | |
| } | |
| if(!empty($searchRequest->academicTermId)) { | |
| $academicTermIdString = is_array($searchRequest->academicTermId) ? "'" . implode("','",$searchRequest->academicTermId) . "'" : "'".$searchRequest->academicTermId."'"; | |
| $whereQuery .= " AND eerb.properties ->> '$.academicTermId' IN ( $academicTermIdString )"; | |
| } | |
| if(!empty($searchRequest->slotId)) { | |
| $slotIdString = is_array($searchRequest->slotId) ? "'" . implode("','",$searchRequest->slotId) . "'" : "'".$searchRequest->slotId."'"; | |
| $whereQuery .= " AND aps.slot_id IN ( $slotIdString )"; | |
| } | |
| $query = "SELECT DISTINCT | |
| eers.am_assessment_id as id, | |
| eers.am_assessment_id as assessmentId, | |
| eers.cm_academic_paper_subjects_id as academicPaperSubjectId, | |
| s.code as subjectCode, | |
| s.name as subjectName, | |
| g.name as groupName, | |
| g.id as groupId, | |
| aegn.id as falseNoGroupNameId, | |
| aegr.id as falseNoGroupRelationId, | |
| cclo.name as slot, | |
| aegn.group_name as falseNoGroupName | |
| FROM | |
| `groups` g | |
| INNER JOIN ec_exam_registration_batch eerb ON | |
| eerb.groups_id = g.id | |
| INNER JOIN ec_exam_registration_subject eers ON | |
| eers.ec_exam_registration_batch_id = eerb.id | |
| INNER JOIN cm_academic_paper_subjects aps ON | |
| eers.cm_academic_paper_subjects_id = aps.id | |
| INNER JOIN v4_ams_subject s ON | |
| aps.ams_subject_id = s.id | |
| LEFT JOIN assignstaff_exam_group_relation aegr ON | |
| eers.am_assessment_id = aegr.am_assessment_id | |
| LEFT JOIN assignstaff_exam_groupname aegn ON | |
| aegr.assignstaff_exam_groupname_id = aegn.id | |
| LEFT JOIN cm_common_list_object cclo ON | |
| aps.slot_id = cclo.id AND cclo.type = 'SLOT' | |
| WHERE | |
| 1 = 1 "; | |
| $assignedSubjects = $this->executeQueryForList($query.$whereQuery.$orderBy, $this->mapper[FalseNumberGroupServiceMapper::GET_FALSE_NUMBER_GROUP]); | |
| } | |
| catch (\Exception $e) | |
| { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $assignedSubjects; | |
| } | |
| /** | |
| * Get Groups For False Number Group | |
| * @param ExamRegisrationId @examRegisrationId | |
| * @param AssessmentId @assessmentId | |
| * @param ExamType @examType | |
| * @return assignedGroups | |
| */ | |
| public function getAllAssignedGroupsByExamRegId($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| $whereQuery = ""; | |
| $orderBy = " ORDER BY aeg.group_name ASC "; | |
| if(!empty($searchRequest->examRegistrationId)) { | |
| $examRegistrationIdString = is_array($searchRequest->examRegistrationId) ? "'" . implode("','",$searchRequest->examRegistrationId) . "'" : "'".$searchRequest->examRegistrationId."'"; | |
| $whereQuery .= " AND aegr.ec_exam_registration_id IN ( $examRegistrationIdString )"; | |
| } | |
| $query = "SELECT DISTINCT | |
| aeg.id, | |
| aeg.group_name AS groupName, | |
| aeg.examTypeFlag | |
| FROM | |
| assignstaff_exam_groupname aeg | |
| INNER JOIN assignstaff_exam_group_relation aegr ON | |
| aegr.assignstaff_exam_groupname_id = aeg.id | |
| WHERE | |
| 1= 1"; | |
| try | |
| { | |
| $assignedGroups = $this->executeQueryForList($query.$whereQuery.$orderBy); | |
| } | |
| catch (\Exception $e) | |
| { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $assignedGroups; | |
| } | |
| /** | |
| * Get Subject From False Number GroupId | |
| * *@param FalseNoGroupId @falseNoGroupId | |
| * @return Subjects | |
| */ | |
| public function getSubjectFromFalseNumberGroupId($falseNoGroupId) | |
| { | |
| try { | |
| $query = "SELECT DISTINCT | |
| aps.id, | |
| s.name AS subjectName | |
| FROM | |
| assignstaff_exam_group_relation aegr | |
| INNER JOIN cm_academic_paper_subjects aps ON | |
| aegr.cm_academic_paper_subjects_id = aps.id | |
| INNER JOIN v4_ams_subject s ON | |
| aps.ams_subject_id = s.id | |
| WHERE | |
| aegr.assignstaff_exam_groupname_id ='$falseNoGroupId'"; | |
| $assignedSubjects = $this->executeQueryForList($query); | |
| } | |
| catch (\Exception $e){ | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $assignedSubjects; | |
| } | |
| /** | |
| * Get All False Number Groups | |
| * @return falseNoGroups | |
| */ | |
| public function getAllFalseNumberGroups($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| $whereQuery = ""; | |
| if(!empty($searchRequest->name)) { | |
| $whereQuery .= " AND aegn.group_name = '$searchRequest->name' "; | |
| } | |
| $query = "SELECT | |
| distinct aegn.id as id, | |
| aegn.group_name AS falseNoGroupName | |
| FROM | |
| assignstaff_exam_groupname aegn | |
| WHERE | |
| 1= 1"; | |
| try | |
| { | |
| $falseNoGroups = $this->executeQueryForList($query.$whereQuery ); | |
| } | |
| catch (\Exception $e) | |
| { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $falseNoGroups; | |
| } | |
| /** | |
| * Get False Number Group Faculties | |
| * *@param ExamRegisrationId @examRegisrationId | |
| * @return assignedSubjects | |
| */ | |
| public function getAllAssignedGroupsFacultiesByExamRegId($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $orderBy = " ORDER BY s.code ASC "; | |
| $whereQuery = null; | |
| if($searchRequest->isAvoidPracticalSub){ | |
| $whereQuery .= " AND JSON_CONTAINS(aps.properties, '{\"isPractical\":\"false\"}') "; | |
| } | |
| if(!empty($searchRequest->academicPaperSubjectId)) { | |
| $academicPaperSubjectIdString = is_array($searchRequest->academicPaperSubjectId) ? "'" . implode("','",$searchRequest->academicPaperSubjectId) . "'" : "'".$searchRequest->academicPaperSubjectId."'"; | |
| $whereQuery .= " AND eers.cm_academic_paper_subjects_id IN ( $academicPaperSubjectIdString )"; | |
| } | |
| if(!empty($searchRequest->groupId)) { | |
| $groupIdString = is_array($searchRequest->groupId) ? "'" . implode("','",$searchRequest->groupId) . "'" : "'".$searchRequest->groupId."'"; | |
| $whereQuery .= " AND g.id IN ( $groupIdString )"; | |
| } | |
| if(!empty($searchRequest->examRegistrationId)) { | |
| $examRegistrationIdString = is_array($searchRequest->examRegistrationId) ? "'" . implode("','",$searchRequest->examRegistrationId) . "'" : "'".$searchRequest->examRegistrationId."'"; | |
| $whereQuery .= " AND eerb.ec_exam_registration_id IN ( $examRegistrationIdString )"; | |
| } | |
| if(!empty($searchRequest->academicTermId)) { | |
| $academicTermIdString = is_array($searchRequest->academicTermId) ? "'" . implode("','",$searchRequest->academicTermId) . "'" : "'".$searchRequest->academicTermId."'"; | |
| $whereQuery .= " AND eerb.properties ->> '$.academicTermId' IN ( $academicTermIdString )"; | |
| } | |
| if(!empty($searchRequest->slotId)) { | |
| $slotIdString = is_array($searchRequest->slotId) ? "'" . implode("','",$searchRequest->slotId) . "'" : "'".$searchRequest->slotId."'"; | |
| $whereQuery .= " AND aps.slot_id IN ( $slotIdString )"; | |
| } | |
| $query = "SELECT DISTINCT | |
| eers.am_assessment_id as id, | |
| eers.am_assessment_id as assessmentId, | |
| eers.cm_academic_paper_subjects_id as academicPaperSubjectId, | |
| s.code as subjectCode, | |
| s.name as subjectName, | |
| g.name as groupName, | |
| g.id as groupId, | |
| aegn.id as falseNoGroupNameId, | |
| aegr.id as falseNoGroupRelationId, | |
| aegn.group_name as falseNoGroupName, | |
| aega.staffaccounts_id as staffId, | |
| aega.external_examiners_id as externalExaminersId | |
| FROM | |
| `groups` g | |
| INNER JOIN ec_exam_registration_batch eerb ON | |
| eerb.groups_id = g.id | |
| INNER JOIN ec_exam_registration_subject eers ON | |
| eers.ec_exam_registration_batch_id = eerb.id | |
| INNER JOIN cm_academic_paper_subjects aps ON | |
| eers.cm_academic_paper_subjects_id = aps.id | |
| INNER JOIN v4_ams_subject s ON | |
| aps.ams_subject_id = s.id | |
| INNER JOIN assignstaff_exam_group_relation aegr ON | |
| eers.am_assessment_id = aegr.am_assessment_id | |
| INNER JOIN assignstaff_exam_groupname aegn ON | |
| aegr.assignstaff_exam_groupname_id = aegn.id | |
| LEFT JOIN assignstaff_exam_group_assign aega ON | |
| aega.assignstaff_exam_groupname_id = aegn.id | |
| WHERE | |
| 1 = 1 "; | |
| $assignedSubjects = $this->executeQueryForList($query.$whereQuery.$orderBy, $this->mapper[FalseNumberGroupServiceMapper::GET_FALSE_NUMBER_GROUPS_FACULTIES]); | |
| } | |
| catch (\Exception $e) | |
| { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $assignedSubjects; | |
| } | |
| } |