Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 45 |
| ExamBatchAdditionalDetailsService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
110.00 | |
0.00% |
0 / 45 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| saveExamBatchAdditionalDetails | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 28 |
|||
| validateSaveExamBatchAdditionalDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| insertExamBatchAdditionalDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
| <?php | |
| namespace com\linways\ec\core\service; | |
| use com\linways\ec\core\dto\ExamBatchAdditionalDetails; | |
| use com\linways\base\util\MakeSingletonTrait; | |
| 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 ExamBatchAdditionalDetailsService extends BaseService | |
| { | |
| use MakeSingletonTrait; | |
| private function __construct() { | |
| $this->logger = AMSLogger::getLogger('exam-controller-log'); | |
| } | |
| /** | |
| * saveExamBatchAdditionalDetails | |
| * @param ExamBatchAdditionalDetails $examBatchAdditionalDetails | |
| * @return true | |
| */ | |
| public function saveExamBatchAdditionalDetails (ExamBatchAdditionalDetails $examBatchAdditionalDetails) | |
| { | |
| $examBatchAdditionalDetails = $this->realEscapeObject($examBatchAdditionalDetails); | |
| $examBatchAdditionalDetails->createdBy = $GLOBALS['userId']; | |
| $examBatchAdditionalDetails->updatedBy = $GLOBALS['userId']; | |
| $staffId = $GLOBALS['userId']; | |
| try{ | |
| $this->validateSaveExamBatchAdditionalDetails($examBatchAdditionalDetails); | |
| $this->insertExamBatchAdditionalDetails($examBatchAdditionalDetails); | |
| AMSLogger::log_info($this->logger,Events::EC_SAVE_EXAM_BATCH_ADDITIONAL_DETAILS,[ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $examBatchAdditionalDetails, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| }catch(\Exception $e) { | |
| AMSLogger::log_error($this->logger,Events::EC_SAVE_EXAM_BATCH_ADDITIONAL_DETAILS, [ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $examBatchAdditionalDetails, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| if($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS ) { | |
| throw new ExamControllerException($e->getCode(),"Failed to assign batch properties! Please try again"); | |
| } else { | |
| throw new ExamControllerException ($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| } | |
| /** | |
| * validate SaveExamBatchAdditionalDetails Before Saving | |
| * @param ExamBatchAdditionalDetails $examBatchAdditionalDetails | |
| * @return NULL | |
| */ | |
| private function validateSaveExamBatchAdditionalDetails(ExamBatchAdditionalDetails $examBatchAdditionalDetails){ | |
| if(empty($examBatchAdditionalDetails->groupId)) | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS," Batch is empty! Please choose any Batch"); | |
| } | |
| /** | |
| * Insert ExamBatchAdditionalDetails | |
| * @param ExamBatchAdditionalDetails $examBatchAdditionalDetails | |
| */ | |
| private function insertExamBatchAdditionalDetails(ExamBatchAdditionalDetails $examBatchAdditionalDetails){ | |
| $properties = !empty($examBatchAdditionalDetails->properties) ? "'" . json_encode($examBatchAdditionalDetails->properties) . "'" : "NULL"; | |
| try { | |
| $sql = "INSERT INTO ec_batch_additional_details (groups_id,properties,created_by) | |
| VALUES ('$examBatchAdditionalDetails->groupId',$properties,$examBatchAdditionalDetails->createdBy) | |
| ON DUPLICATE KEY UPDATE | |
| updated_by = VALUES(created_by), | |
| properties = VALUES(properties)"; | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| } |