Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 91
FalseNumberGroupRelationService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 7
462.00
0.00% covered (danger)
0.00%
0 / 91
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 saveFalseNumberGroupRelation
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 27
 insertFalseNumberGroupRelation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 12
 updateFalseNumberGroupRelation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 17
 deleteFalseNumberGroupRelation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 14
 deleteFalseNumberGroupRelationByAcademicPaperSubjectId
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 15
 validateSaveFalseNumberGroupRelation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 4
<?php
namespace com\linways\ec\core\service;
use com\linways\ec\core\dto\FalseNumberGroupRelation;
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 FalseNumberGroupRelationService extends BaseService
{
    use MakeSingletonTrait;
    private function __construct() {
        $this->logger = AMSLogger::getLogger('exam-controller-log');
    }
   
    
    /**
     * Save False Number Group Relation
     * @author Krishnajith
     *  @param FalseNumberGroupRelation $falseNumberGroupRelation
     * @throws ExamControllerException
     */
    public function saveFalseNumberGroupRelation(FalseNumberGroupRelation $falseNumberGroupRelation){
        $falseNumberGroupRelation = $this->realEscapeObject($falseNumberGroupRelation);
        try{
            $this->validateSaveFalseNumberGroupRelation($falseNumberGroupRelation);
            $falseNumberGroupRelation->id = $this->insertFalseNumberGroupRelation($falseNumberGroupRelation);
            AMSLogger::log_info($this->logger,Events::CREATE_FALSE_NUMBER_GROUP_RELATION,[
                "staff" => new Staff(["id" => $GLOBALS['userId']]),
                    "request" => $falseNumberGroupRelation,
                    "status" => StatusConstants::SUCCESS
            ]);
        }catch(\Exception $e) {
            AMSLogger::log_error($this->logger,Events::CREATE_FALSE_NUMBER_GROUP_RELATION,[
                "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 $falseNumberGroupRelation->id ;
        
    }
    /**
     * Insert False Number Group
     *  @author Krishnajith
     * @param FalseNumberGroupRelation $falseNumberGroupRelation
     * @return  $id
     */
    private function insertFalseNumberGroupRelation(FalseNumberGroupRelation $falseNumberGroupRelation){
        $this->deleteFalseNumberGroupRelationByAcademicPaperSubjectId($falseNumberGroupRelation->cmAcademicPaperSubjectsId,$falseNumberGroupRelation->ecExamRegistrationId,$falseNumberGroupRelation->amAssessmentId);
        $query = "INSERT INTO assignstaff_exam_group_relation
                  (assignstaff_exam_groupname_id,am_assessment_id,ec_exam_registration_id,cm_academic_paper_subjects_id)
                  VALUES
                  ('$falseNumberGroupRelation->assignstaffExamGroupnameId','$falseNumberGroupRelation->amAssessmentId','$falseNumberGroupRelation->ecExamRegistrationId','$falseNumberGroupRelation->cmAcademicPaperSubjectsId')";
        
        try {
            $falseNumberGroupRelation->id = $this->executeQueryForObject($query,true);
           return $falseNumberGroupRelation->id;
        } catch (\Exception $e) {
             throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
     /**
     * Update False Number Group Relation
     *  @author Krishnajith
     * @param FalseNumberGroupRelation $falseNumberGroupRelation
     * @return  $id
     */
    private function updateFalseNumberGroupRelation(FalseNumberGroupRelation $falseNumberGroupRelation)
    {
        $query = "UPDATE
                    assignstaff_exam_group_relation
                SET
                    assignstaff_exam_groupname_id = '$falseNumberGroupRelation->assignstaffExamGroupnameId',
                    am_assessment_id = '$falseNumberGroupRelation->amAssessmentId',
                    ec_exam_registration_id = '$falseNumberGroupRelation->ecExamRegistrationId',
                    cm_academic_paper_subjects_id = '$falseNumberGroupRelation->cmAcademicPaperSubjectsId'
                WHERE
                    id = '$falseNumberGroupRelation->id'";
        try {
             $this->executeQuery($query);
           return $falseNumberGroupRelation->id;
        } catch (\Exception $e) {
             throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
    /**
     * Delete falseNumberGroupRelation
     * @param String $id
     * @return NULL
     */
    public function deleteFalseNumberGroupRelation($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_group_relation
                WHERE
                    id = '$id'";
        try {
            $this->executeQuery($query);
        } catch (\Exception $e) {
            throw new ExamControllerException(ExamControllerException::ERROR_DELETING_FALSE_NUMBER_GROUP,"Error deleting False Number Group! Please try again");
        }
    }
     /**
     * Delete falseNumberGroupRelation By academic paper subject id and exam registration id and assessment id
     * @param String $id
     * @return NULL
     */
    public function deleteFalseNumberGroupRelationByAcademicPaperSubjectId($academicPaperSubjectId,$examRegistrationId,$assessmentId){
        $academicPaperSubjectId = $this->realEscapeString($academicPaperSubjectId);
        $examRegistrationId = $this->realEscapeString($examRegistrationId);
        $assessmentId = $this->realEscapeString($assessmentId);
        if(empty($academicPaperSubjectId) || empty($examRegistrationId) || empty($assessmentId))
            throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_FALSE_NUMBER_GROUP,"False Number Group is Missing");
        $query = "DELETE FROM
                    assignstaff_exam_group_relation
                WHERE
                    cm_academic_paper_subjects_id = '$academicPaperSubjectId' AND ec_exam_registration_id = '$examRegistrationId' AND am_assessment_id = '$assessmentId'";
        try {
            $this->executeQuery($query);
        } catch (\Exception $e) {
            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 FalseNumberGroupRelation $falseNumberGroupRelation
     * @return NULL
     */
    private function validateSaveFalseNumberGroupRelation(FalseNumberGroupRelation $falseNumberGroupRelation)
    {
        if(empty($falseNumberGroupRelation->assignstaffExamGroupnameId))
            throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS_FALSE_NUMBER_GROUP," False Number Groups is empty! Please choose name for False Number Group");
       
    }
   
 
}