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 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 307
Template20SupplementaryIndividualResultGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
2070.00
0.00% covered (danger)
0.00%
0 / 307
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getTemplateName
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 processData
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 38
 renderIndividualMarkCardResult
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 64
 processSupplementaryRegularStudentData
0.00% covered (danger)
0.00%
0 / 1
930.00
0.00% covered (danger)
0.00%
0 / 193
<?php
//Template Individual Generator For PRESIDENCY Colleges
namespace com\linways\ec\core\service\SupplementaryIndividualMarkCardGenerator;
use com\linways\ec\core\service\StudentMarkListService;
use com\linways\ec\core\service\ExamRegistrationService;
use com\linways\ec\core\exception\ExamControllerException;
use com\linways\base\util\TwigRenderer;
use com\linways\core\ams\professional\util\PdfUtil;
use com\linways\ec\core\service\CommonExamService;
use com\linways\ec\core\service\SupplementaryIndividualMarkCardGenerator\SupplementaryIndividualMarkCardResultDataGenerator;
use com\linways\core\ams\professional\util\CommonUtil;
use TCPDFBarcode;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
use com\linways\ec\core\service\StudentSpecializationService;
use com\linways\ec\core\request\SearchExamRegistrationRequest;
use com\linways\core\ams\professional\templateEngine\twig\TwigCustomFunctions;
use Twig\TwigFunction;
use com\linways\core\ams\professional\service\StudentService;
class Template20SupplementaryIndividualResultGenerator extends SupplementaryIndividualMarkCardResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        if( $request->isStudentSideExamResult == '1' ){
            $templateName = "template_20_student_side";
        }
        else{
            $templateName = "template_20_controller_side";
        }
        return $templateName;
    }
     /**
     * Process Student data college base
     *
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $studentsMarkDetails = [];
        $examRegistrationData = StudentMarkListService::getInstance()->getExamRegistrationDetailsDataForConsolidatedAndIndividualReports($request);
        if(empty($examRegistrationData)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Exam Found");
        }
        $searchRequest = new \stdClass();
        $searchRequest->groupId = $request->groupId;
        $searchRequest->studentId = $request->studentId;
        $searchRequest->selectedSemesters = $examRegistrationData->academicTermId;
        $searchRequest->excludeMinorHonor = 1;
        $studentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($searchRequest);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        if( $request->isStudentSideExamResult == '1' && !$request->groupId){
            $request->groupId = reset($studentsMarkDetails)->studentDetails->batchId;
        }
        $studentsMarkDetails = $this->processSupplementaryRegularStudentData($studentsMarkDetails,$request,$examRegistrationData);
        $examRegistrationData->disableCollegeRegisterNumber = false;
        if($examRegistrationData->batchStartYear >= '2023'){
            $examRegistrationData->disableCollegeRegisterNumber = true;
        }
        $response->studentData = $studentsMarkDetails->studentsDetails;
        $response->examRegistrationData = $examRegistrationData;
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails();
        if( $request->displayContentOptions->enableDateFlag == '1'){
            if(!$request->displayContentOptions->markListDate ){
                $request->displayContentOptions->markListDate = date("d-m-Y");
            }
            else{
                $request->displayContentOptions->markListDate = date("d-m-Y", strtotime($request->displayContentOptions->markListDate));
            }
        }
        $response->displayContentOptions = $request->displayContentOptions;
        $response->isStudentSideExamResult = $request->isStudentSideExamResult;
        return $response;
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderIndividualMarkCardResult($templateName, $data){
        if(empty($data)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        else{
            $twigFunctions = [
                new TwigFunction('getQr', [TwigCustomFunctions::class, 'getQr']),
                // Add more functions here as needed
            ];
            $responseHtml = TwigRenderer::renderTemplateFileToHtml(realpath(DOCUMENT_ROOT."../examcontroller-api/src/com/linways/web/templates/SupplementaryIndividualMarkCards/Template20/$templateName.twig"), [ 'data'=>$data ],null,$twigFunctions);
            $prtContent = NULL;
            if($data->isStudentSideExamResult){
                $prtContent .= '<html><head>';
                $prtContent .= "<style>
                    h6 {font-size: 26px;} .text-center { text-align: center;} .align-middle {vertical-align: middle;}; tr.noBorder td {border: 0;  border-collapse:collapse;}
                    table, th, td {border: 1px solid black;border-collapse: collapse;} 
                    </style>";
                $prtContent .= '</head><title>Individual Mark Card</title><body>';
                $prtContent .= $responseHtml;
                $prtContent .= '</body></html>';
           
                $totalWidth = 210;
                $totalHeight = 297;
                $options = array(
                    'page-width'     => $totalWidth."mm",
                    'page-height'    => $totalHeight."mm",
                    'dpi'            => 96,
                    'margin-top' => "9mm",
                    'margin-left' => "10mm",
                    'margin-right' => "10mm",
                    'margin-bottom' => "9mm",
                    // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac
                    'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css")
                );
            }
            else{
                $prtContent .= '<html><head>';
                $prtContent .= "<style>
                    .single-page { height: 185mm !important;}
                    h6 {font-size: 26px;} 
                    .text-center { text-align: center;} 
                    .align-middle {vertical-align: middle;}; 
                    table, th, td {border: 1px solid black;border-collapse: collapse;} 
                    .no-border-tr td, .no-border-table tbody tr td { border-right:1px solid #fff !important; border-left:1px solid #fff !important; border-top:1px solid #fff !important;border-bottom:1px solid #fff !important;};
                    </style>";
                $prtContent .= '</head><title>Individual Mark Card</title><body>';
                $prtContent .= $responseHtml;
                $prtContent .= '</body></html>';
                
            $prtContent .= '</head><title>Individual Mark Card</title><body>';
                $totalWidth = 210;
                $totalHeight = 297;
                $options = array(
                    'page-width'     => $totalHeight."mm",
                    'page-height'    => $totalWidth."mm",
                    'dpi'            => 96,
                    'margin-top' => "2cm",
                    'margin-left' => "7mm",
                    'margin-right' => "7mm",
                    'margin-bottom' => "5mm",
                    // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac
                    'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css")
                );
            }
            $programResult = new \stdClass;
            $programResult->dispalyHtmlData = $responseHtml;
            $programResult->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $programResult;
        }
       
    }
    /**
     * processSupplementaryRegularStudentData
     * @param studentDetails
     * @return studentDetails
     * @author Krishnajith
     */
    public function processSupplementaryRegularStudentData($studentMarkDetails,$examRegistrationRequest,$examRegistrationDetails){
        $response = new \stdClass;
        $totalStudentDetails = new \stdClass;
        $totalStudentDetails->totalStudents = count($studentMarkDetails);
        $displaySubjectArray = [];
        $displaySubjectCategories = [];
        $studentsDetails = [];
        if( $request->isStudentSideExamResult == '1' ){
            $requestForExamRegistration = new SearchExamRegistrationRequest;
            $requestForExamRegistration->groupId = $examRegistrationRequest->groupId;
            $revaluationRegistrations = ExamRegistrationService::getInstance()->getAllExamRevaluation($requestForExamRegistration);
        }
        foreach($studentMarkDetails as $student){
            $requestForSpecialization = new \stdClass;
            $requestForSpecialization->studentId = $student->id;
            $requestForSpecialization->groupId = $student->studentDetails->batchId;
            $requestForSpecialization->academicTermId = $student->academicTerms[0]->id;
            $barcodeObj = new TCPDFBarcode($student->studentDetails->registerNo, 'C128');
            $studentsDetails[$student->id]->slNo = "";
            $studentsDetails[$student->id]->barcodeObj = $barcodeObj->getBarcodeHTML($w = 1, $h = 30, $color = 'black');
            $studentsDetails[$student->id]->id = $student->id;
            $studentsDetails[$student->id]->admissionNo = $student->studentDetails->admissionNo;
            $studentsDetails[$student->id]->qrCodeContents = "MARKSHEET/".$GLOBALS['COLLEGE_NAME']."/".$student->studentDetails->startYear."/". $student->studentDetails->registerNo."/".reset($student->academicTerms)->academicOrderNo;
            $customFields = AmsCustomFieldsService::getInstance()->getAmsCustomFieldValue(AmsCustomFieldsEntities::STUDENT, $student->id, []);
            if( $customFields ){
                $studentsDetails[$student->id]->ktuCode = CommonExamService::getInstance()->getCustomFieldObjectList($customFields)->studentData->KTU_CODE;
            }
            $studentsDetails[$student->id]->name = $student->studentDetails->name;
            $studentsDetails[$student->id]->myImage  = StudentService::getInstance()->getStudentProfilePic($student->id)->docpath;
            $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
            $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
            // this case for check the revaluation result is published or not in student side
            foreach($student->academicTerms as $academicTerm){
                $currentAcademicTerm = reset(array_filter(reset($student->academicTerms)->markHistory,function($value)use($examRegistrationRequest){
                    return $value->examRegistrationId == $examRegistrationRequest->examRegistrationId;
                }));
                $regularExamDetails = reset(array_filter(reset($student->academicTerms)->markHistory,function($value){
                    return $value->historyType == 'REGULAR';
                }));
                if( $request->isStudentSideExamResult == '1' ){
                    if ( $currentAcademicTerm->hasRevaluationMark ){
                        $currentRegistration = reset(array_filter($revaluationRegistrations,function($value)use($currentAcademicTerm){
                            return $value->id == $currentAcademicTerm->revaluationId;
                        }));
                        $revaluationBatch = reset($currentRegistration->groups);
                        if ( $revaluationBatch->properties->isResultPublished == 1 && strtotime($revaluationBatch->properties->publishingStartDate) < strtotime(date("Y-m-d H:i"))){
                            $currentAcademicTerm->sgpa = $currentAcademicTerm->sgpa;
                            $currentAcademicTerm->failedStatus = $currentAcademicTerm->failedStatus;
                        }
                        else{
                            $currentAcademicTerm->sgpa = $currentAcademicTerm->withoutRevaluationsgpa;
                            $currentAcademicTerm->markObtained = $currentAcademicTerm->withoutRevaluationMarkObtained;
                            $currentAcademicTerm->percentage = $currentAcademicTerm->withoutRevaluationPercentage;
                            $currentAcademicTerm->class = $currentAcademicTerm->withoutRevaluationClass;
                            $currentAcademicTerm->failedStatus = $currentAcademicTerm->withoutRevaluationFailedStatus == '1' ? 'FAILED' : 'PASSED';
                            $currentAcademicTerm->grade = $currentAcademicTerm->withoutRevaluationGrade;
                        }
                    }
                    else{
                        $currentAcademicTerm->sgpa = $currentAcademicTerm->sgpa;
                        $currentAcademicTerm->failedStatus = $currentAcademicTerm->failedStatus;
                    }
                }
                $studentsDetails[$student->id]->regularExamRegistrationId = $regularExamDetails->examRegistrationId;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->id = $academicTerm->id;
                $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($academicTerm->name);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterPercentage = round($currentAcademicTerm->percentage,2);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semInRomanLetter = $semesterNames->romanLetter;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semInFullName = $semesterNames->fullName;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semInSemNumber = $semesterNames->semNumber;
                $studentsDetails[$student->id]->failedStatus = $currentAcademicTerm->failedStatus;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->failedStatus = $currentAcademicTerm->failedStatus;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterGrade = $currentAcademicTerm->grade;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterClass = $currentAcademicTerm->class;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterTotalMarks = $currentAcademicTerm->totalMarks;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtained = $currentAcademicTerm->markObtained;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtainedInWords = CommonUtil::convertNumberToWords($currentAcademicTerm->markObtained);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->creditGradePoint = $currentAcademicTerm->creditGradePoint;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterGradePoint = $academicTerm->gradePoint;
                $studentsDetails[$student->id]->semesterSgpa = sprintf('%0.2f', $currentAcademicTerm->sgpa);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterSgpa =sprintf('%0.2f', $currentAcademicTerm->sgpa);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamMonth = $currentAcademicTerm->examMonth;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamYear = $currentAcademicTerm->examYear;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterExamMonthName = ExamRegistrationService::getInstance()->getMonthName($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamMonth);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->qrcodeValue = $studentsDetails[$student->id]->registerNo .",".$studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterExamMonthName."-".$studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamYear.",S".$studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semInSemNumber;
                $studentsDetails[$student->id]->qrcodeAllString = $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->qrcodeValue;
              
                
                foreach( $academicTerm->subjects as $subject){
                    $subject->markHistory = array_filter($subject->subjectMarkHistory,function($value)use($examRegistrationDetails){
                        return $value->examYear."-".date("m", mktime(0, 0, 0, (int)$value->examMonth, 10))  <= $examRegistrationDetails->examYear."-".date("m", mktime(0, 0, 0, (int)$examRegistrationDetails->examMonth, 10)); 
                    });
                    // $isMarkExist = array_filter(array_column($subject->markHistory, 'externalMark'));
                    // if (!empty($isMarkExist)){
                    //     usort($subject->markHistory, function($a, $b) {
                    //         return ($a->externalMark < $b->externalMark); 
                    //     });
                    // }
                    // else{
                        // usort($subject->markHistory, function($a, $b) {
                        //     return ($a->examYear."-".date("m", mktime(0, 0, 0, (int)$a->examMonth, 10))) < ($b->examYear."-".date("m", mktime(0, 0, 0, (int)$b->examMonth, 10)));
                        // });
                        $regularHistory = array_filter($subject->markHistory,function($value){
                            return $value->examMarkType == "REGULAR";
                        });
                        $supplyHistory = array_filter($subject->markHistory,function($value){
                            return $value->examMarkType == "SUPPLY";
                        });
                        usort($supplyHistory, function($a, $b) {
                            return ($a->examYear."-".date("m", mktime(0, 0, 0, (int)$a->examMonth, 10))) < ($b->examYear."-".date("m", mktime(0, 0, 0, (int)$b->examMonth, 10)));
                        });
                        $subject->markHistory = array_merge($supplyHistory, $regularHistory);
                    // }
               
                    $subject->latestMarkHistory = reset($subject->markHistory);
                    $subjectMarkHistory = $subject->latestMarkHistory;
                    $subject->gradePoint = $subjectMarkHistory->gradePoint;
                    $subject->creditGradePoint = $subjectMarkHistory->creditGradePoint;
                    if($request->isStudentSideExamResult == '1'){
                        if ( $subjectMarkHistory->hasRevaluationMark ){
                            $currentRegistration = reset(array_filter($revaluationRegistrations,function($value)use($subjectMarkHistory){
                                return $value->id == $subjectMarkHistory->revaluationId;
                            }));
                            $revaluationBatch = reset($currentRegistration->groups);
                            if ( $revaluationBatch->properties->isResultPublished == 1 && strtotime($revaluationBatch->properties->publishingStartDate) < strtotime(date("Y-m-d H:i"))){
                                $subject->latestMarkHistory->grade = $subjectMarkHistory->grade;
                                $subject->latestMarkHistory->resultStatus = $subjectMarkHistory->resultStatus;
                                $subject->latestMarkHistory->externalMark = $subjectMarkHistory->externalMark;
                                $subject->latestMarkHistory->markObtained = $subjectMarkHistory->markObtained;
                            }
                            else{
                                $subject->latestMarkHistory->grade = $subjectMarkHistory->withoutRevaluationGrade;
                                $subject->latestMarkHistory->resultStatus = $subjectMarkHistory->withoutRevaluationIsFailed == 1 ? 'FAILED' : 'PASSED' ;
                                $subject->latestMarkHistory->externalMark = $subjectMarkHistory->externalMarkObtainedInExamMark;
                                $subject->latestMarkHistory->markObtained = $subject->internalMark + $subjectMarkHistory->externalMarkObtainedInExamMark;
                                $subject->latestMarkHistory->gradePoint = $subjectMarkHistory->withoutRevaluationGradePoint;
                            }
                        }
                        else{
                            $subject->grade = $subjectMarkHistory->grade;
                            $subject->isFailed = $subjectMarkHistory->resultStatus;
                        }
                    }
                    
                    
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id] = $subject;
                    // this case add the subject type name like DSE-DISCIPLINE SPECIFIC ELECTIVE  COURSE but want to show only DSE 
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->subjectTypeNameTrimmed = $subject->subjectTypeName ? explode('-', $subject->subjectTypeName)[0] : '';
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isAttendedSupply = false;
                    if($examRegistrationRequest->examRegistrationId && $subject->latestMarkHistory->examRegistrationId == $examRegistrationRequest->examRegistrationId){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isAttendedSupply = true;
                    }
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->priority = $subject->priority;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->internalPassPercentage = $subject->internalPassPercentage;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalPassPercentage = $subject->externalPassPercentage;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->aggregatePassPercentage = $subject->aggregatePassPercentage;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->internalMinimumMark = $subject->internalMaxMark * $subject->internalPassPercentage / 100;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMinimumMark = $subject->externalMaxMark * $subject->externalPassPercentage / 100;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->totalMinimumMark = $subject->totalMarks * $subject->aggregatePassPercentage / 100;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->credit = $subject->credit;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->id = $subject->id;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->totalMaxMark = $subject->totalMarks;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->percentage = round($subject->latestMarkHistory->percentage,2);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->failedStatus = $subject->latestMarkHistory->resultStatus;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = $subject->latestMarkHistory->grade;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->class = $subject->latestMarkHistory->class;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->latestExamYear = $subject->latestMarkHistory->examYear;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->latestexamMonth = $subject->latestMarkHistory->examMonth;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMark = $subject->latestMarkHistory->externalMark;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->markObtained = $subject->latestMarkHistory->markObtained;
                    $timestamp = mktime(0, 0, 0, $subject->latestMarkHistory->examMonth, 1);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->latestExamMonthName = date('M', $timestamp); 
                    if($subject->consolidatedMarkDetails->excludeSubjectFromTotal == '1'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = $subject->latestMarkHistory->resultStatus == "PASSED" ? 'P' : 'F' ;
                    }
                    if($subject->latestMarkHistory->attendanceStatus == 'ABSENT'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMark =  'AB';
                    }
                    else if($subject->latestMarkHistory->attendanceStatus == 'MALPRACTICE'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMark = 'MP';
                    }
                    else if($subject->latestMarkHistory->resultStatus == 'FAILED'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'F';
                    }
                    if($subject->latestMarkHistory->studentAttendanceStatus == 'FE'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'FE';
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->credit = '-';
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->latestExamYear = '-';
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->latestExamMonthName = '';
                    }
                }
                uasort($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects, function($a, $b) {
                    return ($a->priority > $b->priority);
                });
                // $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = array_sum(array_column($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects,'creditGradePoint'));
            }
            if($studentsDetails[$student->id]->failedStatus  == 'PASSED'){
                $slNoRequest =  new \stdClass;
                $slNoRequest->studentId = $student->id;
                $slNoRequest->examRegistrationId = $studentsDetails[$student->id]->regularExamRegistrationId;
                $studentsDetails[$student->id]->slNo = CommonExamService::getInstance()->getStudentExamMarkListSerialNumber($slNoRequest)->markListSerialNo;
                if ($studentsDetails[$student->id]->slNo) {
                    $studentsDetails[$student->id]->slNo = str_pad($studentsDetails[$student->id]->slNo, 6, "0", STR_PAD_LEFT);
                }
            }
        }
       
        $displaySubjectCategories = array_values($displaySubjectCategories); 
        foreach($displaySubjectCategories as $displaySubjectCategory){
            $displaySubjectCategory->subjects = array_values($displaySubjectCategory->subjects); 
        }
        uasort($displaySubjectArray, function($a, $b) {
            return ($a->priority > $b->priority);
        });
        foreach($studentsDetails as $student){
            $student->academicTerms = array_values($student->academicTerms); 
            foreach($student->academicTerms as $academicTerm){
                $academicTerm->subjects = array_values($academicTerm->subjects); 
            } 
        }
        $response->studentsDetails = $studentsDetails;
        return $response;
    }
}