Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 39 |
| GroupPriorityService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
156.00 | |
0.00% |
0 / 39 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| saveGroupPriority | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 18 |
|||
| validateSaveGroupPriority | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 3 |
|||
| insertGroupPriority | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 15 |
|||
| <?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\GroupPriority; | |
| use com\linways\ec\core\logging\Events; | |
| use com\linways\ec\core\logging\entities\Staff; | |
| use com\linways\core\ams\professional\logging\AMSLogger; | |
| class GroupPriorityService extends BaseService | |
| { | |
| use MakeSingletonTrait; | |
| private function __construct() | |
| { | |
| $this->logger = AMSLogger::getLogger('exam-controller-log'); | |
| } | |
| /** | |
| * Save Group priority | |
| * @param GroupPriority $groupPriority | |
| * @return $id | |
| */ | |
| public function saveGroupPriority(GroupPriority $groupPriority){ | |
| $groupPriority = $this->realEscapeObject($groupPriority); | |
| $groupPriority->createdBy = $GLOBALS['userId'] ?? $groupPriority->createdBy; | |
| $groupPriority->updatedBy = $GLOBALS['userId'] ?? $groupPriority->updatedBy; | |
| $staffId = $GLOBALS['userId']; | |
| try { | |
| $this->validateSaveGroupPriority($groupPriority); | |
| $groupPriority->id = $this->insertGroupPriority($groupPriority); | |
| } catch (\Exception $e) { | |
| if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException($e->getCode(), "Failed to save batch priority ! Please try again"); | |
| } else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) { | |
| throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot save batch priority."); | |
| } else { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| return $groupPriority->id; | |
| } | |
| /** | |
| * validate Save Group Priority | |
| * @param GroupPriority $groupPriority | |
| * @return NULL | |
| */ | |
| private function validateSaveGroupPriority(GroupPriority $groupPriority){ | |
| if (empty($groupPriority->groupId) || empty($groupPriority->priority)) | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " empty parameter. can't save batch priority ! "); | |
| } | |
| /** | |
| * Insert Group Priority | |
| * @param GroupPriority $groupPriority | |
| * @return $id | |
| */ | |
| private function insertGroupPriority(GroupPriority $groupPriority){ | |
| $query = "INSERT INTO ec_group_priority | |
| (groups_id,priority,created_by,updated_by) | |
| VALUES | |
| ('$groupPriority->groupId','$groupPriority->priority','$groupPriority->createdBy','$groupPriority->updatedBy') | |
| ON DUPLICATE KEY | |
| UPDATE | |
| updated_by = VALUES(created_by), | |
| priority = VALUES(priority)"; | |
| try { | |
| $groupPriority->id = $this->executeQuery($query,true)->id; | |
| return $groupPriority->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| } |