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 / 80
ExamRevaluationParentMappingService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 7
210.00
0.00% covered (danger)
0.00%
0 / 80
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 saveExamRevaluationParentMapping
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 17
 validateSaveExamRevaluationParentMapping
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 3
 insertExamRevaluationParentMapping
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 15
 updateExamRevaluationParentMapping
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 16
 deleteExamRevaluationParentMapping
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 13
 getRevaluationParentName
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 14
<?php
namespace com\linways\ec\core\service;
use com\linways\ec\core\dto\ExamRevaluationParentMapping;
use com\linways\base\util\MakeSingletonTrait;
use com\linways\ec\core\exception\ExamControllerException;
use com\linways\ec\core\mapper\ExamRevaluationParentMappingServiceMapper;
class ExamRevaluationParentMappingService extends BaseService
{
    use MakeSingletonTrait;
    private function __construct() {
        $this->mapper = ExamRevaluationParentMappingServiceMapper::getInstance()->getMapper();
    }
    /**
     * Save ExamRevaluationParentMapping
     * @param ExamRevaluationParentMapping $examRegistration
     * @return $id
     */
    public function saveExamRevaluationParentMapping (ExamRevaluationParentMapping $examRevaluationParentMapping)
    {
        $examRevaluationParentMapping = $this->realEscapeObject($examRevaluationParentMapping);
        $examRevaluationParentMapping->createdBy = $GLOBALS['userId'] ?? $examRevaluationParentMapping->createdBy;
        $examRevaluationParentMapping->updatedBy = $GLOBALS['userId'] ?? $examRevaluationParentMapping->updatedBy;
        try{
            $this->validateSaveExamRevaluationParentMapping($examRevaluationParentMapping);
            if( $examRevaluationParentMapping->id){
                $examRevaluationParentMapping->id = $this->updateExamRevaluationParentMapping($examRevaluationParentMapping);
            }
            else{
                $examRevaluationParentMapping->id = $this->insertExamRevaluationParentMapping($examRevaluationParentMapping);
            }
        }catch(\Exception $e) {
            throw new ExamControllerException ($e->getCode(),$e->getMessage());   
        }
        return $examRevaluationParentMapping->id ;
        
    }
    /**
     * Validate Exam Revaluation Parent Mapping Request Before Saving
     * @param ExamRevaluationParentMapping $examRegistration
     * @return NULL
     */
    private function validateSaveExamRevaluationParentMapping(ExamRevaluationParentMapping $examRevaluationParentMapping){
        if(empty($examRevaluationParentMapping->examRegistrationId))
            throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS," Exam revaluation is empty! Please select exam revaluation");
    }
    /**
     * Insert ExamRevaluationParentMapping
     * @param ExamRevaluationParentMapping $examRevaluationParentMapping
     * @return  $id
     */
    private function insertExamRevaluationParentMapping(ExamRevaluationParentMapping $examRevaluationParentMapping){
        $query = "INSERT INTO ec_revaluation_parent_registration
                  (ec_exam_registration_id,parent_registration_id,revaluation_order,created_by,updated_by)
                  VALUES
                  ('$examRevaluationParentMapping->examRegistrationId','$examRevaluationParentMapping->parentRegistrationID',$examRevaluationParentMapping->order,'$examRevaluationParentMapping->createdBy','$examRevaluationParentMapping->updatedBy')
                  ON DUPLICATE KEY
                    UPDATE
                  updated_by = VALUES(created_by),
                  revaluation_order = VALUES(revaluation_order)";
        
        try {
            $examRevaluationParentMapping->id = $this->executeQuery($query,true)->id;
           return $examRevaluationParentMapping->id;
        } catch (\Exception $e) {
             throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
     /**
     * Update ExamRevaluationParentMapping
     * @param ExamRevaluationParentMapping $examRevaluationParentMapping
     * @return  $id
     */
    private function updateExamRevaluationParentMapping(ExamRevaluationParentMapping $examRevaluationParentMapping){
        $query = "UPDATE
                        ec_revaluation_parent_registration
                    SET
                        ec_exam_registration_id = '$examRevaluationParentMapping->examRegistrationId',
                        parent_registration_id = '$examRevaluationParentMapping->parentRegistrationID',
                        revaluation_order = $examRevaluationParentMapping->order,
                        updated_by = '$examRevaluationParentMapping->updatedBy'
                    WHERE
                        id = '$examRevaluationParentMapping->id'";
        try {
            $this->executeQuery($query);
           return $examRevaluationParentMapping->id;
        } catch (\Exception $e) {
             throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
    /**
     * Delete ExamRevaluationParentMapping
     * @param ExamRevaluationParentMapping $examRegistration
     * @return $id
     */
    public function deleteExamRevaluationParentMapping (ExamRevaluationParentMapping $examRevaluationParentMapping)
    {
        $examRevaluationParentMapping = $this->realEscapeObject($examRevaluationParentMapping);
        
        $query = "DELETE FROM
            ec_revaluation_parent_registration
        WHERE
            id = '$examRevaluationParentMapping->id'";
        try{
            $this->executeQuery($query);
        }catch(\Exception $e) {
            throw new ExamControllerException ($e->getCode(),$e->getMessage());   
        }
        return $examRevaluationParentMapping->id ;
        
    }
    /**
     * Delete ExamRevaluationParentMapping
     * @param $parentRegistrationIds
     * @return $id
     */
    public function getRevaluationParentName ($parentRegistrationIds)
    {
        $parentRegistrationIds = $this->realEscapeArray($parentRegistrationIds);
        $parentRegistrationIds = implode("', '", $parentRegistrationIds );
        $query = "SELECT name FROM
            ec_exam_registration
        WHERE
            id IN ('$parentRegistrationIds')";
        try{
            $revaluationParentDetails = $this->executeQueryForList($query);
        }catch(\Exception $e) {
            throw new ExamControllerException ($e->getCode(),$e->getMessage());   
        }
        return $revaluationParentDetails ;
        
    }
    
}