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 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 437
BlockStudentMappingService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 11
6972.00
0.00% covered (danger)
0.00%
0 / 437
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 saveBlockStudentMapping
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 30
 validateSaveBlockStudentMapping
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 4
 insertBlockStudentMapping
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 13
 deleteBlockStudentMapping
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 23
 getBlockStudentMappings
0.00% covered (danger)
0.00%
0 / 1
240.00
0.00% covered (danger)
0.00%
0 / 50
 getStudentsForBlockRegistration
0.00% covered (danger)
0.00%
0 / 1
132.00
0.00% covered (danger)
0.00%
0 / 42
 getExamRegistrationStudentDetails
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 68
 getRegisteredStudentDetails
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 65
 getRegisteredStudentSubjectDetails
0.00% covered (danger)
0.00%
0 / 1
90.00
0.00% covered (danger)
0.00%
0 / 89
 getStudentBlockReasonsDetails
0.00% covered (danger)
0.00%
0 / 1
182.00
0.00% covered (danger)
0.00%
0 / 50
<?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\BlockStudentMapping;
use com\linways\ec\core\logging\Events;
use com\linways\ec\core\logging\entities\Staff;
use com\linways\core\ams\professional\logging\AMSLogger;
use com\linways\core\ams\professional\service\StaffService;
use com\linways\ec\core\service\BlockStudentReasonService;
class BlockStudentMappingService extends BaseService
{
    use MakeSingletonTrait;
    private function __construct()
    {
        $this->logger = AMSLogger::getLogger('exam-controller-log');
    }
    /**
     * Save Block Student Reason
     * @param BlockStudentMapping $blockStudentMapping
     * @return $id
     */
    public function saveBlockStudentMapping(BlockStudentMapping $blockStudentMapping){
        $blockStudentMapping = $this->realEscapeObject($blockStudentMapping);
        $blockStudentMapping->createdBy = $GLOBALS['userId'];
        $blockStudentMapping->updatedBy = $GLOBALS['userId'];
        $staffId = $GLOBALS['userId'];
        try {
            $this->validateSaveBlockStudentMapping($blockStudentMapping);
            $blockStudentMapping->id = $this->insertBlockStudentMapping($blockStudentMapping);
            AMSLogger::log_info($this->logger,Events::EC_SAVE_STUDENT_BLOCK_STATUS, [
                "staff" => new Staff(["id" => $staffId]),
                "request" => $blockStudentMapping,
                "status" => StatusConstants::SUCCESS
            ]);
        } catch (\Exception $e) {
            AMSLogger::log_error($this->logger,Events::EC_SAVE_STUDENT_BLOCK_STATUS, [
                "staff" => new Staff(["id" => $staffId]),
                "request" => $blockStudentMapping,
                "errorCode" => $e->getCode(),
                "errorMessage" => $e->getMessage(),
                "status" => StatusConstants::FAILED
            ]);
            if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") {
                throw new ExamControllerException($e->getCode(), "Failed to save student block status Type! Please try again");
            } else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) {
                throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot create block status.This block status already created");
            } else {
                throw new ExamControllerException($e->getCode(), $e->getMessage());
            }
        }
        return $blockStudentMapping->id;
    }
    /**
     * Validate Block Student Reason Request Before Saving
     * @param BlockStudentMapping $blockStudentMapping
     * @return NULL
     */
    private function validateSaveBlockStudentMapping(BlockStudentMapping $blockStudentMapping){
        if (empty($blockStudentMapping->studentId) || empty($blockStudentMapping->examRegistrationId) || empty($blockStudentMapping->blockStudentReasonId) || empty($blockStudentMapping->blockingType)){
            throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, "Empty Parameter!");
        }
        
            
    }
    /**
     * Insert Block Student Reason 
     * @param BlockStudentMapping $blockStudentMapping
     * @return  $id
     */
    private function insertBlockStudentMapping(BlockStudentMapping $blockStudentMapping){
        $properties = !empty($blockStudentMapping->properties) ? "'" . json_encode($blockStudentMapping->properties) . "'" : "'{}'";
        $blockStudentMapping->academicPaperSubjectId = $blockStudentMapping->academicPaperSubjectId ? "'".$blockStudentMapping->academicPaperSubjectId ."'" : "NULL";
        $query = "INSERT INTO ec_student_block_reason_mapping
                  (student_id,exam_registration_id,cm_academic_paper_subjects_id,ec_block_student_reason_id,blocking_type,properties,created_by,updated_by)
                  VALUES
                  ('$blockStudentMapping->studentId','$blockStudentMapping->examRegistrationId',$blockStudentMapping->academicPaperSubjectId,'$blockStudentMapping->blockStudentReasonId','$blockStudentMapping->blockingType',$properties,'$blockStudentMapping->createdBy','$blockStudentMapping->updatedBy') ON DUPLICATE KEY UPDATE `updated_by` = VALUES(updated_by)";
        try {
            $blockStudentMapping->id = $this->executeQuery($query,true)->id;
            return $blockStudentMapping->id;
        } catch (\Exception $e) {
            throw new ExamControllerException($e->getCode(), $e->getMessage());
        }
    }
     /**
     * Delete Block Student Reason 
     * @param String $id
     * @return NULL
     */
    public function deleteBlockStudentMapping($id){
        $id = $this->realEscapeString($id);
        $staffId = $GLOBALS['userId'];
        $blockStudentMapping = new \stdClass();
        $blockStudentMapping->id = $id;
        $currentBlockStudentMappingDetails = reset($this->getBlockStudentMappings($blockStudentMapping));
        if(empty($currentBlockStudentMappingDetails)){
            throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS,"Can't delete ! Block reason missing.");
        }
        $query = "DELETE FROM
                    ec_student_block_reason_mapping
                WHERE
                    id = '$id'";
        try {
            $this->executeQuery($query);
             // LOGGING
            AMSLogger::log_info($this->logger,Events::EC_DELETE_STUDENT_BLOCK_STATUS, [
                "staff" => new Staff(["id" => $staffId]),
                "request" => $currentBlockStudentMappingDetails,
                "status" => StatusConstants::SUCCESS
            ]);
        }catch (\Exception $e) {
            throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Error deleting Block reason! Please try again");
        }
    }
    /**
     * get Block Student Reason 
     * @param $searchRequest
     * @return $blockStudentMappings
     */
    public function getBlockStudentMappings($searchRequest){
        $searchRequest = $this->realEscapeObject($searchRequest);
        try {
            $whereQuery = null;
            $whereQuery = "";
            if (!empty($searchRequest->id)) {
                $blockStudentMappingIdString = is_array($searchRequest->id) ? "'" . implode("','", $searchRequest->id) . "'" : "'" . $searchRequest->id . "'";
                $whereQuery .= " AND esbrm.id IN ( $blockStudentMappingIdString )";
            }
            if (!empty($searchRequest->studentId)) {
                $studentIdString = is_array($searchRequest->studentId) ? "'" . implode("','", $searchRequest->studentId) . "'" : "'" . $searchRequest->studentId . "'";
                $whereQuery .= " AND esbrm.student_id IN ( $studentIdString )";
            }
            if (!empty($searchRequest->examRegistrationId)) {
                $examRegistrationIdString = is_array($searchRequest->examRegistrationId) ? "'" . implode("','", $searchRequest->examRegistrationId) . "'" : "'" . $searchRequest->examRegistrationId . "'";
                $whereQuery .= " AND esbrm.exam_registration_id IN ( $examRegistrationIdString )";
            }
            if (!empty($searchRequest->blockStudentReasonId)) {
                $blockStudentReasonIdString = is_array($searchRequest->blockStudentReasonId) ? "'" . implode("','", $searchRequest->blockStudentReasonId) . "'" : "'" . $searchRequest->blockStudentReasonId . "'";
                $whereQuery .= " AND esbrm.ec_block_student_reason_id IN ( $blockStudentReasonIdString )";
            }
            if (!empty($searchRequest->blockingType)) {
                $blockingTypeString = is_array($searchRequest->blockingType) ? "'" . implode("','", $searchRequest->blockingType) . "'" : "'" . $searchRequest->blockingType . "'";
                $whereQuery .= " AND esbrm.blocking_type IN ( $blockingTypeString )";
            }
            if (!empty($searchRequest->academicPaperSubjectId)) {
                $academicPaperSubjectIdString = is_array($searchRequest->academicPaperSubjectId) ? "'" . implode("','", $searchRequest->academicPaperSubjectId) . "'" : "'" . $searchRequest->academicPaperSubjectId . "'";
                $whereQuery .= " AND esbrm.cm_academic_paper_subjects_id IN ( $academicPaperSubjectIdString )";
            }
            $query = "SELECT
                            DISTINCT 
                            esbrm.id as id,
                            esbrm.student_id as studentId,
                            esbrm.exam_registration_id as examRegistrationId,
                            esbrm.ec_block_student_reason_id as blockStudentReasonId,
                            esbrm.blocking_type as blockingType,
                            esbrm.cm_academic_paper_subjects_id as academicPaperSubjectId,
                            esbrm.properties
                        FROM
                            ec_student_block_reason_mapping esbrm
                        WHERE
                            1 = 1 ";
            $blockStudentMappings =  $this->executeQueryForList($query . $whereQuery);
        } catch (\Exception $e) {
            throw new ExamControllerException($e->getCode(), $e->getMessage());
        }
        foreach($blockStudentMappings as $blockStudentMapping){
            $blockStudentMapping->properties = json_decode($blockStudentMapping->properties);
        }
        return $blockStudentMappings;
    }
    /**
     * Get Student For Block Student Registration
     * @param $searchRequest
     * @return $id
     */
    public function getStudentsForBlockRegistration($searchRequest){
        // $searchRequest = $this->realEscapeObject($searchRequest);
        try {
            $students = [];
            $assignedStudents  = [];
            $assignedStudentsSubjects = [];
            switch ($searchRequest->blockingType) {
                case 'REGISTRATION_BLOCKING': 
                    $assignedStudents = $this->getExamRegistrationStudentDetails($searchRequest);
                    break;
                case 'HALL_TICKET_BLOCKING':
                    $assignedStudentsSubjects = $this->getRegisteredStudentSubjectDetails($searchRequest);
                    break;
                case 'RESULT_BLOCKING':
                    $assignedStudents = $this->getRegisteredStudentDetails($searchRequest);
                    break;
                default:
                    $students = [];
                    break;
            }
            foreach($assignedStudents as $student){
                $students[$student->id] = $student;
                foreach($student->blockingReasons as $reason){
                    $students[$student->id]->reasons[$reason->id]->id = $reason->id;
                    $students[$student->id]->reasons[$reason->id]->name = $reason->name;
                    $students[$student->id]->reasons[$reason->id]->isAssigned = in_array($reason->id,$students[$student->id]->blockReasonIds) ? 1 : 0;
                }
            }
            foreach($assignedStudentsSubjects as $student){
                $students[$student->id] = $student;
                foreach($student->blockingReasons as $reason){
                    $students[$student->id]->reasons[$reason->id]->id = $reason->id;
                    $students[$student->id]->reasons[$reason->id]->name = $reason->name;
                    $students[$student->id]->reasons[$reason->id]->isAssigned = in_array($reason->id,$students[$student->id]->blockReasonIds) ? 1 : 0;
                }
            }
            
            $students = array_values($students);
            array_walk($students, function($student){
                $students->reasons = array_values($students->reasons);
            });
            
        } catch (\Exception $e) {
            throw new ExamControllerException($e->getCode(), $e->getMessage());
        }
        return $students;
    }
    /**
     * get Availabe Students For Exam Registration
     * @param $request
     * @return $students
     */
    public function getExamRegistrationStudentDetails($request){
        $request = $this->realEscapeObject($request);
        $whereQuery = "";
        $students = [];
        $sortBy = " ORDER BY spa.properties->>'$.registerNumber' ASC";
        if(!empty($request->examRegistrationId)){
            $examRegistrationIdString = is_array($request->examRegistrationId) ? "'" . implode("','",$request->examRegistrationId) . "'" : "'".$request->examRegistrationId."'";
            $whereQuery .= " AND eer.id IN ( $examRegistrationIdString )";
        }
        if(!empty($request->groupId)){
            $groupIdString = is_array($request->groupId) ? "'" . implode("','",$request->groupId) . "'" : "'".$request->groupId."'";
            $whereQuery .= " AND g.id IN ( $groupIdString )";
        }
        $query = "SELECT DISTINCT
            sa.studentID as id,
            sa.studentName as name,
            spa.properties->>'$.registerNumber' as registerNumber,
            eer.id as examRegistrationId,
            eer.name as examRegistrationName,
            g.name AS groupName,
            esbrm.ec_block_student_reason_id as blockReasonId
        FROM
            ec_exam_registration eer
        INNER JOIN ec_exam_registration_batch eerb ON
            eerb.ec_exam_registration_id = eer.id 
        INNER JOIN academic_term act ON 
            act.id = eerb.academicTermId
        INNER JOIN `groups` g ON
            g.id = eerb.groups_id
            AND g.`type` = 'BATCH'
        INNER JOIN group_members gm ON
            gm.groups_id = g.id
        INNER JOIN student_program_account spa ON 
            spa.id  = gm.members->>'$.studentId' 
        INNER JOIN student_program_batch_log spbl ON
            spbl.batch_group_id = g.id AND
            spbl.term_id = CAST(eerb.properties ->> '$.academicTermId'AS CHAR) AND
            spbl.program_student_id = spa.id  AND 
            spbl.properties->>'$.academicStatus' IN ('ACTIVE','COMPLETED')
        INNER JOIN studentaccount sa ON
            sa.studentID = spa.student_id
        LEFT JOIN ec_student_block_reason_mapping esbrm ON
            esbrm.student_id = sa.studentID AND esbrm.exam_registration_id = eer.id AND
            esbrm.blocking_type = 'REGISTRATION_BLOCKING'
        WHERE
            eer.trashed IS NULL ";
        try {
            $studentsDetails = $this->executeQueryForList($query.$whereQuery.$sortBy);
        } catch (\Exception $e) {
            throw new ExamControllerException(ExamControllerException::ERROR_FETCHING_EXAM_REGISTRATION,"Cannot fetch Studentd.");
        }
        $searchRequest = new \stdClass();
        $searchRequest->type = 'SEMESTER_WISE';
        $reasons = BlockStudentReasonService::getInstance()->getBlockStudentReasons($searchRequest);
        foreach($studentsDetails as $student){
            $students[$student->id]->id = $student->id;
            $students[$student->id]->name = $student->name;
            $students[$student->id]->registerNumber = $student->registerNumber;
            $students[$student->id]->examRegistrationId = $student->examRegistrationId;
            $students[$student->id]->examRegistrationName = $student->examRegistrationName;
            $students[$student->id]->groupName = $student->groupName;
            if($student->blockReasonId){
                $students[$student->id]->blockReasonIds[$student->blockReasonId] = $student->blockReasonId;
            }
            $students[$student->id]->blockingReasons = $reasons;
        }
        $students = array_values($students);
        return $students;
    }
    /**
     * get Registered Students For Exam result Blocking
     * @param $request
     * @return $students
     */
    public function getRegisteredStudentDetails($request){
        $request = $this->realEscapeObject($request);
        $whereQuery = "";
        $students = [];
        $sortBy = " ORDER BY spa.properties->>'$.registerNumber' ASC";
        if(!empty($request->examRegistrationId)){
            $examRegistrationIdString = is_array($request->examRegistrationId) ? "'" . implode("','",$request->examRegistrationId) . "'" : "'".$request->examRegistrationId."'";
            $whereQuery .= " AND eer.id IN ( $examRegistrationIdString )";
        }
        if(!empty($request->groupId)){
            $groupIdString = is_array($request->groupId) ? "'" . implode("','",$request->groupId) . "'" : "'".$request->groupId."'";
            $whereQuery .= " AND g.id IN ( $groupIdString )";
        }
        $query = "SELECT DISTINCT
            sa.studentID as id,
            sa.studentName as name,
            spa.properties->>'$.registerNumber' as registerNumber,
            eer.id as examRegistrationId,
            eer.name as examRegistrationName,
            g.name AS groupName,
            esbrm.ec_block_student_reason_id as blockReasonId
        FROM
            ec_exam_registration eer
        INNER JOIN ec_exam_registration_batch eerb ON
            eerb.ec_exam_registration_id = eer.id 
        INNER JOIN ec_exam_registration_subject eers ON
            eers.ec_exam_registration_batch_id = eerb.id
        INNER JOIN `groups` g ON
            g.id = eerb.groups_id
            AND g.`type` = 'BATCH'
        INNER JOIN ec_student_assessment_registration esar ON
            esar.am_assessment_id = eers.am_assessment_id AND 
            esar.ec_exam_registration_type = eer.type AND 
            esar.properties ->> '$.registrationStatus' IN ('REGISTERED')
        INNER JOIN student_program_account spa ON
            spa.student_id = esar.student_id
        INNER JOIN studentaccount sa ON
            sa.studentID = esar.student_id
        LEFT JOIN ec_student_block_reason_mapping esbrm ON
            esbrm.student_id = sa.studentID AND esbrm.exam_registration_id = eer.id AND
            esbrm.blocking_type = 'RESULT_BLOCKING'
        WHERE
            eer.trashed IS NULL ";
        try {
            $studentsDetails = $this->executeQueryForList($query.$whereQuery.$sortBy);
        } catch (\Exception $e) {
            throw new ExamControllerException(ExamControllerException::ERROR_FETCHING_EXAM_REGISTRATION,"Cannot fetch Studentd.");
        }
        $searchRequest = new \stdClass();
        $searchRequest->type = 'SEMESTER_WISE';
        $reasons = BlockStudentReasonService::getInstance()->getBlockStudentReasons($searchRequest);
        foreach($studentsDetails as $student){
            $students[$student->id]->id = $student->id;
            $students[$student->id]->name = $student->name;
            $students[$student->id]->registerNumber = $student->registerNumber;
            $students[$student->id]->examRegistrationId = $student->examRegistrationId;
            $students[$student->id]->examRegistrationName = $student->examRegistrationName;
            $students[$student->id]->groupName = $student->groupName;
            if($student->blockReasonId){
                $students[$student->id]->blockReasonIds[$student->blockReasonId] = $student->blockReasonId;
            }
            $students[$student->id]->blockingReasons = $reasons;
        }
        $students = array_values($students);
        return $students;
    }
    /**
     * get Registered Students Subject For Exam hall ticket Blocking
     * @param $request
     * @return $students
     */
    public function getRegisteredStudentSubjectDetails($request){
        $request = $this->realEscapeObject($request);
        $whereQuery = "";
        $students = [];
        $sortBy = " ORDER BY spa.properties->>'$.registerNumber' ASC";
        if(!empty($request->examRegistrationId)){
            $examRegistrationIdString = is_array($request->examRegistrationId) ? "'" . implode("','",$request->examRegistrationId) . "'" : "'".$request->examRegistrationId."'";
            $whereQuery .= " AND eer.id IN ( $examRegistrationIdString )";
        }
        if(!empty($request->groupId)){
            $groupIdString = is_array($request->groupId) ? "'" . implode("','",$request->groupId) . "'" : "'".$request->groupId."'";
            $whereQuery .= " AND g.id IN ( $groupIdString )";
        }
        $query = "SELECT DISTINCT
            sa.studentID as id,
            sa.studentName as name,
            spa.properties->>'$.registerNumber' as registerNumber,
            eer.id as examRegistrationId,
            eer.name as examRegistrationName,
            g.name AS groupName,
            esbrmSem.ec_block_student_reason_id as blockReasonId,
            aps.id AS academicPaperSubjectId,
            s.code AS subjectCode,
            s.name AS subjectName,
            esbrmSub.ec_block_student_reason_id as subjectBlockReasonId
        FROM
            ec_exam_registration eer
        INNER JOIN ec_exam_registration_batch eerb ON
            eerb.ec_exam_registration_id = eer.id 
        INNER JOIN ec_exam_registration_subject eers ON
            eers.ec_exam_registration_batch_id = eerb.id
        INNER JOIN `groups` g ON
            g.id = eerb.groups_id
            AND g.`type` = 'BATCH'
        INNER JOIN  cm_academic_paper_subjects aps ON 
            eers.cm_academic_paper_subjects_id = aps.id
        INNER JOIN  v4_ams_subject s ON 
            aps.ams_subject_id = s.id
        INNER JOIN ec_student_assessment_registration esar ON
            esar.am_assessment_id = eers.am_assessment_id AND 
            esar.ec_exam_registration_type = eer.type AND 
            esar.properties ->> '$.registrationStatus' IN ('REGISTERED')
        INNER JOIN student_program_account spa ON
            spa.student_id = esar.student_id
        INNER JOIN studentaccount sa ON
            sa.studentID = esar.student_id
        LEFT JOIN ec_student_block_reason_mapping esbrmSem ON
            esbrmSem.student_id = sa.studentID AND esbrmSem.exam_registration_id = eer.id AND
            esbrmSem.cm_academic_paper_subjects_id IS NULL AND
            esbrmSem.blocking_type = 'HALL_TICKET_BLOCKING'
        LEFT JOIN ec_student_block_reason_mapping esbrmSub ON
            esbrmSub.student_id = sa.studentID AND esbrmSub.exam_registration_id = eer.id AND
            esbrmSub.cm_academic_paper_subjects_id = eers.cm_academic_paper_subjects_id AND
            esbrmSub.blocking_type = 'HALL_TICKET_BLOCKING'
        WHERE
            eer.trashed IS NULL ";
        try {
            $studentsDetails = $this->executeQueryForList($query.$whereQuery.$sortBy);
        } catch (\Exception $e) {
            throw new ExamControllerException(ExamControllerException::ERROR_FETCHING_EXAM_REGISTRATION,"Cannot fetch Studentd.");
        }
        $searchRequest = new \stdClass();
        $searchRequest->type = 'SEMESTER_WISE';
        $reasons = BlockStudentReasonService::getInstance()->getBlockStudentReasons($searchRequest);
        foreach($studentsDetails as $student){
            $students[$student->id]->id = $student->id;
            $students[$student->id]->name = $student->name;
            $students[$student->id]->registerNumber = $student->registerNumber;
            $students[$student->id]->examRegistrationId = $student->examRegistrationId;
            $students[$student->id]->examRegistrationName = $student->examRegistrationName;
            $students[$student->id]->groupName = $student->groupName;
            if($student->blockReasonId){
                $students[$student->id]->blockReasonIds[$student->blockReasonId] = $student->blockReasonId;
            }
            $students[$student->id]->blockingReasons = $reasons;
            $students[$student->id]->subjects[$student->academicPaperSubjectId]->id = $student->academicPaperSubjectId;
            $students[$student->id]->subjects[$student->academicPaperSubjectId]->academicPaperSubjectId = $student->academicPaperSubjectId;
            $students[$student->id]->subjects[$student->academicPaperSubjectId]->code = $student->subjectCode;
            $students[$student->id]->subjects[$student->academicPaperSubjectId]->name = $student->subjectName;
            if($student->subjectBlockReasonId){
                $students[$student->id]->subjects[$student->academicPaperSubjectId]->blockReasonIds[$student->subjectBlockReasonId] = $student->subjectBlockReasonId;
            }
        }
        $students = array_values($students);
        array_walk($students, function($student){
            array_walk($student->subjects, function($subject){
                $subject->blockReasonIds = array_values($subject->blockReasonIds);
            });
            $student->subjects = array_values($student->subjects);
        });
        return $students;
    }
    /**
     * get Student Block reason details
     * @param $searchRequest
     * @return $blockStudentMappings
     */
    public function getStudentBlockReasonsDetails($searchRequest){
        $searchRequest = $this->realEscapeObject($searchRequest);
        try {
            $whereQuery = null;
            $whereQuery = "";
            if (!empty($searchRequest->studentId)) {
                $studentIdString = is_array($searchRequest->studentId) ? "'" . implode("','", $searchRequest->studentId) . "'" : "'" . $searchRequest->studentId . "'";
                $whereQuery .= " AND esbrm.student_id IN ( $studentIdString )";
            }
            if (!empty($searchRequest->examRegistrationId)) {
                $examRegistrationIdString = is_array($searchRequest->examRegistrationId) ? "'" . implode("','", $searchRequest->examRegistrationId) . "'" : "'" . $searchRequest->examRegistrationId . "'";
                $whereQuery .= " AND esbrm.exam_registration_id IN ( $examRegistrationIdString )";
            }
            if (!empty($searchRequest->blockingType)) {
                $blockingTypeString = is_array($searchRequest->blockingType) ? "'" . implode("','", $searchRequest->blockingType) . "'" : "'" . $searchRequest->blockingType . "'";
                $whereQuery .= " AND esbrm.blocking_type IN ( $blockingTypeString )";
            }
            if (!empty($searchRequest->blockReasonType)) {
                $blockReasonTypeString = is_array($searchRequest->blockReasonType) ? "'" . implode("','", $searchRequest->blockReasonType) . "'" : "'" . $searchRequest->blockReasonType . "'";
                $whereQuery .= " AND ebsr.type IN ( $blockReasonTypeString )";
            }
            if (!empty($searchRequest->academicPaperSubjectId)) {
                $academicPaperSubjectIdString = is_array($searchRequest->academicPaperSubjectId) ? "'" . implode("','", $searchRequest->academicPaperSubjectId) . "'" : "'" . $searchRequest->academicPaperSubjectId . "'";
                $whereQuery .= " AND esbrm.cm_academic_paper_subjects_id IN ( $academicPaperSubjectIdString )";
            }
            $query = "SELECT
                            DISTINCT 
                            esbrm.id as id,
                            esbrm.student_id as studentId,
                            esbrm.exam_registration_id as examRegistrationId,
                            esbrm.ec_block_student_reason_id as blockStudentReasonId,
                            esbrm.blocking_type as blockingType,
                            esbrm.cm_academic_paper_subjects_id as academicPaperSubjectId,
                            esbrm.properties,
                            ebsr.id as blockReasonId,
                            ebsr.name as blockReasonName
                        FROM
                            ec_student_block_reason_mapping esbrm
                        INNER JOIN ec_block_student_reason ebsr ON 
                            ebsr.id = esbrm.ec_block_student_reason_id
                        WHERE
                            1 = 1 ";
            $blockStudentMappings =  $this->executeQueryForList($query . $whereQuery);
        } catch (\Exception $e) {
            throw new ExamControllerException($e->getCode(), $e->getMessage());
        }
        foreach($blockStudentMappings as $blockStudentMapping){
            $blockStudentMapping->properties = json_decode($blockStudentMapping->properties);
        }
        return $blockStudentMappings;
    }
    
}