Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 129 |
| AssignStaffToFalseNumberGroupService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
600.00 | |
0.00% |
0 / 129 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| saveAssignStaffToFalseNumberGroup | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 33 |
|||
| insertAssignStaffFalseNumberGroupRelation | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
| updateAssignStaffFalseNumberGroupRelation | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 17 |
|||
| deleteAssignStaffFalseNumberGroupRelation | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 26 |
|||
| deleteAssignStaffFalseNumberGroupWithAssignStaffExamGroupNameId | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 22 |
|||
| validateSaveAssignStaffToFalseNumberGroup | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| getAssignStaffIdsFalseNumberGroup | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 13 |
|||
| <?php | |
| namespace com\linways\ec\core\service; | |
| use com\linways\ec\core\dto\FalseNumberGroupRelation; | |
| use com\linways\ec\core\dto\FalseNumberGroupAssignStaffRelation; | |
| 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\core\ams\professional\logging\AMSLogger; | |
| use com\linways\ec\core\logging\Events; | |
| use com\linways\ec\core\logging\entities\Staff; | |
| class AssignStaffToFalseNumberGroupService extends BaseService | |
| { | |
| use MakeSingletonTrait; | |
| private function __construct() { | |
| $this->logger = AMSLogger::getLogger('exam-controller-log'); | |
| } | |
| /** | |
| * Save False Number Group Staff Assign Relation | |
| * @author Krishnajith | |
| * @param FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation | |
| * @throws ExamControllerException | |
| */ | |
| public function saveAssignStaffToFalseNumberGroup(FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation) | |
| { | |
| $falseNumberGroupAssignStaffRelation = $this->realEscapeObject($falseNumberGroupAssignStaffRelation); | |
| try{ | |
| $this->validateSaveAssignStaffToFalseNumberGroup($falseNumberGroupAssignStaffRelation); | |
| if(!empty($falseNumberGroupAssignStaffRelation->id)){ | |
| $falseNumberGroupAssignStaffRelation->id = $this->updateAssignStaffFalseNumberGroupRelation($falseNumberGroupAssignStaffRelation); | |
| } | |
| else{ | |
| $falseNumberGroupAssignStaffRelation->id = $this->insertAssignStaffFalseNumberGroupRelation($falseNumberGroupAssignStaffRelation); | |
| } | |
| AMSLogger::log_info($this->logger,Events::CREATE_FALSE_NUMBER_GROUP_STAFF_RELATION,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroupAssignStaffRelation, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| }catch(\Exception $e) { | |
| AMSLogger::log_error($this->logger,Events::CREATE_FALSE_NUMBER_GROUP_STAFF_RELATION,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroupAssignStaffRelation, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| if($e->getCode() !== ExamControllerException::INVALID_PARAMETERS_STAFF_ASSIGN_FALSE_NUMBER_GROUP && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS_STAFF_ASSIGN_FALSE_NUMBER_GROUP && $e->getCode() !== "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException($e->getCode(),"Failed to Assign Staff False Number Group! Please try again"); | |
| } else if ($e->getCode() === "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException (ExamControllerException::DUPLICATE_ENTRY_ASSIGN_STAFF_FALSE_NUMBER_GROUP,"Cannot create False Number Group.This Group Name is Already Taken!"); | |
| } else { | |
| throw new ExamControllerException ($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| return $falseNumberGroupRelation->id ; | |
| } | |
| /** | |
| * Insert False Number Group Assign Staff | |
| * @author Krishnajith | |
| * @param FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation | |
| * @return $id | |
| */ | |
| private function insertAssignStaffFalseNumberGroupRelation(FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation) | |
| { | |
| $query = "INSERT INTO assignstaff_exam_group_assign | |
| (assignstaff_exam_groupname_id,staffaccounts_id,external_examiners_id,isExternalFlag) | |
| VALUES | |
| ('$falseNumberGroupAssignStaffRelation->assignstaffExamGroupnameId','$falseNumberGroupAssignStaffRelation->staffaccountsId','$falseNumberGroupAssignStaffRelation->externalExaminersId','$falseNumberGroupAssignStaffRelation->isExternalFlag')"; | |
| try { | |
| $falseNumberGroupAssignStaffRelation->id = $this->executeQueryForObject($query,true); | |
| return $falseNumberGroupAssignStaffRelation->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Update False Number Group Assign Staff | |
| * @author Krishnajith | |
| * @param FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation | |
| * @return $id | |
| */ | |
| private function updateAssignStaffFalseNumberGroupRelation(FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation) | |
| { | |
| $query = "UPDATE | |
| assignstaff_exam_group_assign | |
| SET | |
| assignstaff_exam_groupname_id = '$falseNumberGroupAssignStaffRelation->assignstaffExamGroupnameId', | |
| staffaccounts_id = '$falseNumberGroupAssignStaffRelation->staffaccountsId', | |
| external_examiners_id = '$falseNumberGroupAssignStaffRelation->externalExaminersId', | |
| isExternalFlag = '$falseNumberGroupAssignStaffRelation->isExternalFlag' | |
| WHERE | |
| id = '$falseNumberGroupAssignStaffRelation->id'"; | |
| try { | |
| $this->executeQuery($query); | |
| return $falseNumberGroupAssignStaffRelation->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete falseNumberGroup Assign Staff | |
| * @param INT $id | |
| * @return NULL | |
| */ | |
| public function deleteAssignStaffFalseNumberGroupRelation($id) | |
| { | |
| $id = $this->realEscapeString($id); | |
| if(empty($id)) | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_STAFF_ASSIGN_FALSE_NUMBER_GROUP,"False Number Group is Missing"); | |
| $query = "DELETE FROM | |
| assignstaff_exam_group_assign | |
| WHERE | |
| id = '$id'"; | |
| try { | |
| $this->executeQuery($query); | |
| AMSLogger::log_info($this->logger,Events::DELETE_FALSE_NUMBER_GROUP_STAFF_RELATION,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroupAssignStaffRelation, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| } catch (\Exception $e) { | |
| AMSLogger::log_error($this->logger,Events::DELETE_FALSE_NUMBER_GROUP_STAFF_RELATION,[ | |
| "staff" => new Staff(["id" => $GLOBALS['userId']]), | |
| "request" => $falseNumberGroupAssignStaffRelation, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| throw new ExamControllerException(ExamControllerException::ERROR_DELETING_ASSIGN_STAFF_FALSE_NUMBER_GROUP,"Error deleting False Number Group! Please try again"); | |
| } | |
| } | |
| /** | |
| * Delete falseNumberGroup Assign Staff With assignstaff_exam_groupname_id | |
| * @param INT $id | |
| * @return NULL | |
| */ | |
| public function deleteAssignStaffFalseNumberGroupWithAssignStaffExamGroupNameId($assignstaffExamGroupNameId,$examinerType) | |
| { | |
| $assignstaffExamGroupNameId = $this->realEscapeString($assignstaffExamGroupNameId); | |
| $examinerType = $this->realEscapeString($examinerType); | |
| if(empty($assignstaffExamGroupNameId)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_STAFF_ASSIGN_FALSE_NUMBER_GROUP,"False Number Group is Missing"); | |
| } | |
| if($examinerType == 'INTERNAL'){ | |
| $whereQuery = " AND isExternalFlag = 0"; | |
| } | |
| else{ | |
| $whereQuery = " AND isExternalFlag = 1"; | |
| } | |
| $query = "DELETE FROM | |
| assignstaff_exam_group_assign | |
| WHERE | |
| assignstaff_exam_groupname_id = '$assignstaffExamGroupNameId'"; | |
| try { | |
| $this->executeQuery($query.$whereQuery); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException(ExamControllerException::ERROR_DELETING_ASSIGN_STAFF_FALSE_NUMBER_GROUP,"Error deleting False Number Group! Please try again"); | |
| } | |
| } | |
| /** | |
| * Validate False Number Group Assign Staff Request Before Saving | |
| * @param FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation | |
| * @return NULL | |
| */ | |
| private function validateSaveAssignStaffToFalseNumberGroup(FalseNumberGroupAssignStaffRelation $falseNumberGroupAssignStaffRelation) | |
| { | |
| if(empty($falseNumberGroupAssignStaffRelation->assignstaffExamGroupnameId) || empty($falseNumberGroupAssignStaffRelation->staffaccountsId)) | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_STAFF_ASSIGN_FALSE_NUMBER_GROUP," False Number Groups or Staffs is empty! Please choose name for False Number Group or Staff"); | |
| } | |
| /** | |
| * Select Staff ids From Assign Staff False Number Group | |
| * @param INT $assignstaffExamGroupnameId | |
| * @return NULL | |
| */ | |
| public function getAssignStaffIdsFalseNumberGroup($assignstaffExamGroupnameId){ | |
| $query = "SELECT | |
| staffaccounts_id as staffId | |
| FROM | |
| assignstaff_exam_group_assign | |
| WHERE | |
| assignstaff_exam_groupname_id = '$assignstaffExamGroupnameId'"; | |
| try { | |
| $staffIds = $this->executeQueryForList($query); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $staffIds; | |
| } | |
| } |