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 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 437
Template5ConsolidatedResultGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
9120.00
0.00% covered (danger)
0.00%
0 / 437
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getTemplateName
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 processData
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 16
 renderConsolidatedMarkListResult
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 70
 processStudentData
0.00% covered (danger)
0.00%
0 / 1
1806.00
0.00% covered (danger)
0.00%
0 / 176
 getExamRegistrationDetailsData
0.00% covered (danger)
0.00%
0 / 1
462.00
0.00% covered (danger)
0.00%
0 / 105
 processStudentSubjectDataForCourseFileTemplate
0.00% covered (danger)
0.00%
0 / 1
506.00
0.00% covered (danger)
0.00%
0 / 62
<?php
// Template Consilidated Generator For  MBCET Colleges
namespace com\linways\ec\core\service\RegularConsolidatedMarkListGenerator;
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\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\service\CommonExamService;
use com\linways\ec\core\constant\AttendanceStatusConstant;
use com\linways\core\ams\professional\constant\examcontroller\CourseTypeConstants;
use com\linways\ec\core\service\RegularConsolidatedMarkListGenerator\RegularConsolidatedMarkListResultDataGenerator;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\core\ams\professional\service\examcontroller\CommonExamService as CoreCommonExamService;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
class Template5ConsolidatedResultGenerator extends RegularConsolidatedMarkListResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_5";
        $examRegistrationDetails = new \stdClass;
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        return $templateName;
    }
     /**
     * Process Student data college base
     *
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $studentsMarkDetails = [];
        $studentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($request);
        $examRegistrationData =  $this->getExamRegistrationDetailsData($request);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $responseOfStudentData = $this->processStudentData($studentsMarkDetails,$request, $examRegistrationData);
        $response->studentData = $responseOfStudentData->studentsDetails;
        $response->totalStudentData = $responseOfStudentData->totalStudentDetails;
        $response->examRegistrationData = $examRegistrationData;
        $response->hideExternalOrInternalMark = $request->hideExternalOrInternalMark;
        $response->hideSeal = $request->hideSeal;
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails($request);
        return $response;
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderConsolidatedMarkListResult($templateName, $data){
        if(empty($data)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        else{
            $responseHtml = "";
            if($data->hideExternalOrInternalMark){
                $responseHtml .= "<style>
                .hideExternalOrInternalMark {display:none;} 
                .hideMarks {display:none;} 
                </style>";
            }
            if($data->hideSeal){
                $responseHtml .= "<style>
                .hideImages {display:none;} 
                </style>";
            }
            $responseHtml .= TwigRenderer::renderTemplateFileToHtml(realpath(DOCUMENT_ROOT."../examcontroller-api/src/com/linways/web/templates/RegularConsolidatedMarkList/Template5/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "<style>
                        .border-black td, .border-black th{
                            border:1px solid #000 !important;
                            height:9mm;
                            vertical-align:middle;
                            background-color: #fff !important;
                            word-break: normal !important;
                        }
                        td, th{
                            padding: 5px !important;
                        }
                        .bold{
                            font-weight: 700 !important;
                        }
                        .no-border{
                            border:1px solid #fff !important;
                            
                        }
                        .no-border-top{
                            border-top:1px solid #fff !important;
                            border-left:1px solid #fff !important;
                            border-right:1px solid #fff !important;
                            border-bottom:1px solid #000 !important;
                        }
                        table{
                            border:1px solid #000 !important;
                        }
                        
                </style>";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            
            $totalSubjectsCount = count($data->examRegistrationData->subjects) < 7 ? 7 : count($data->examRegistrationData->subjects);
            $totalWidth = ( $totalSubjectsCount * 5 * 15 ) + 100;
            $totalHeight =  $totalWidth / 1.414;;
            $options = array(
                'page-width'     => $totalWidth."mm",
                'page-height'    => $totalHeight."mm",
                'dpi'            => 96,
                'margin-top' => "9mm",
                'margin-left' => "1mm",
                'margin-right' => "1mm",
                'margin-bottom' => "9mm",
                // '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);
            $programResult->isShowHideExternalOrInternalMark = true;
            $programResult->isShowHideSeal = false;
        return  $programResult;
        }
       
    }
    protected function processStudentData($studentsMarkDetails,$examRegistrationRequest,$examRegistrationData){
        $response = new \stdClass;
        $totalStudentDetails = new \stdClass;
        $totalStudentDetails->totalStudents = count($studentsMarkDetails);
        $studentsDetails = [];
        foreach($studentsMarkDetails as $student){
            $currentAcademicTerm = reset(array_filter(reset($student->academicTerms)->markHistory,function($value)use($examRegistrationRequest){
                return $value->examRegistrationId == $examRegistrationRequest->examRegistrationId;
            }));
            $studentsDetails[$student->id]->id = $student->id;
            $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]->failedStatus = $currentAcademicTerm->failedStatus;
            $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
            $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
            $studentSubjectRequest = new \stdClass(); 
            $studentSubjectRequest->studentId = $student->id;
            $studentSubjectRequest->examMonthLimit = $examRegistrationData->examMonth;;
            $studentSubjectRequest->examYearLimit = $examRegistrationData->examYear;
            $studentSubjectRequest->examRegistrationType = "REGULAR";
            $studentSubjectRequest->academicTermId = $examRegistrationData->academicTermId;
            $studentSubjectRequest->isHonorCourse = $examRegistrationData->isHonorCourse;
            $studentSubjectRequest->isMinorCourse = $examRegistrationData->isMinorCourse;
            $studentSubjectHistory = StudentMarkListService::getInstance()->getAllStudentSubjectMarkDetailsByRequest($studentSubjectRequest);
            if ( !$examRegistrationData->isHonorCourse && !$examRegistrationData->isMinorCourse  ){
                $studentSubjectRequest = new \stdClass(); 
                $studentSubjectRequest->studentId = $student->id;
                $studentSubjectRequest->upToAcademicTermOrderNoExceptCurrent = $examRegistrationData->academicOrderNo;
                $studentSubjectRequest->isHonorCourse = $examRegistrationData->isHonorCourse;
                $studentSubjectRequest->isMinorCourse = $examRegistrationData->isMinorCourse;
                $studentSubjectHistory2 = StudentMarkListService::getInstance()->getAllStudentSubjectMarkDetailsByRequest($studentSubjectRequest);
                $studentSubjectHistory = array_merge($studentSubjectHistory,$studentSubjectHistory2); 
            }   
            $subjectHistory = [];
            $totalCredit = 0;
            $earnedCredit = 0;
            $earnedCreditPoint = 0;
            $semesterCgpa = 0;
            foreach($studentSubjectHistory as $studentHistory){
                if($subjectHistory[$studentHistory->paperSubjectId]){
                    if($subjectHistory[$studentHistory->paperSubjectId]->subjectCreditGradePoint < $studentHistory->subjectCreditGradePoint){
                        if($studentHistory->excludeSubjectFromTotal != 1){
                            if(($studentHistory->isFinalSemSubject === "true" && $studentHistory->isProjectGroupSubject  === "true") || $studentHistory->isProjectGroupSubject !== "true"){
                                $earnedCreditPoint += ($studentHistory->subjectCreditGradePoint - $subjectHistory[$studentHistory->paperSubjectId]->subjectCreditGradePoint);
                            }
                            $subjectHistory[$studentHistory->paperSubjectId] = $studentHistory;
                            if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationData->academicTermId == $studentHistory->academicTermId ){
                                $earnedCredit += $studentHistory->credit;
                            }
                        }
                        else{
                            // if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationData->academicTermId == $studentHistory->academicTermId ){
                                $subjectHistory[$studentHistory->paperSubjectId] = $studentHistory;
                            // }
                        }
                    }
                }
                else{ 
                    if($studentHistory->excludeSubjectFromTotal != 1){
                        if(($studentHistory->isFinalSemSubject === "true" && $studentHistory->isProjectGroupSubject  === "true") ||  $studentHistory->isProjectGroupSubject !== "true"){
                            if($studentHistory->isFinalSemSubject === "true" && $studentHistory->isProjectGroupSubject  === "true"){
                                $earnedCreditPoint += $studentHistory->creditGradePointProject;
                                $totalCredit += $studentHistory->finalSemProjectCredit;
                            } 
                            else{
                                $earnedCreditPoint += $studentHistory->subjectCreditGradePoint;
                                $totalCredit += $studentHistory->credit;
                            }
                        }
                        $subjectHistory[$studentHistory->paperSubjectId] = $studentHistory;
                        if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationData->academicTermId == $studentHistory->academicTermId ){
                            $earnedCredit += $studentHistory->credit;
                        }
                    }
                    else{
                        // if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationData->academicTermId == $studentHistory->academicTermId ){
                            $subjectHistory[$studentHistory->paperSubjectId] = $studentHistory;
                            // $earnedCreditForDisplay += $studentHistory->credit;
                        // }
                    }
                }
            }
            $semesterCgpa =  sprintf('%0.2f', round(($earnedCreditPoint/$totalCredit), 2));
            $overallFailedHistory = reset(array_filter($subjectHistory,function($value){
                return $value->subjectFailedStatus == "FAILED";
            }));
            foreach($student->academicTerms[0]->markHistory as $semMarkHistory){
                if($semMarkHistory->examRegistrationId == $examRegistrationRequest->examRegistrationId){
                    $studentsDetails[$student->id]->examRegistrationWiseFailedStatus = $semMarkHistory->failedStatus;
                    $studentsDetails[$student->id]->failedStatus = $semMarkHistory->failedStatus;
                    $studentsDetails[$student->id]->overallFailedStatus = $overallFailedHistory ? "FAILED" : "PASSED";
                    $studentsDetails[$student->id]->semesterGrade = $semMarkHistory->grade;
                    $studentsDetails[$student->id]->semesterCreditGradePoint = $semMarkHistory->gradePoint;
                    $studentsDetails[$student->id]->semesterCredit = $earnedCredit;
                    $studentsDetails[$student->id]->semesterSgpa = sprintf('%0.2f', $semMarkHistory->sgpa);
                    $studentsDetails[$student->id]->semesterCgpa = $semMarkHistory->failedStatus  == 'FAILED' ? '' : $semesterCgpa;
                    
                    $studentsDetails[$student->id]->semesterMarkObtained = $semMarkHistory->totalMark;
                    $studentsDetails[$student->id]->semesterPercentage = round($semMarkHistory->percentage,2);
                    $studentsDetails[$student->id]->semesterClass = $semMarkHistory->class;
                    $studentsDetails[$student->id]->overallClass =  $semMarkHistory->class;
                    $studentsDetails[$student->id]->overallGrade= $semMarkHistory->grade;
                }
            }
            foreach($student->academicTerms[0]->subjects as $subject){
                $studentsDetails[$student->id]->subjects[$subject->id]->id = $subject->id;
                $studentsDetails[$student->id]->subjects[$subject->id]->name = $subject->name;
                $studentsDetails[$student->id]->subjects[$subject->id]->code = $subject->code;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMaxMark = $subject->externalMaxMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMaxMark = $subject->internalMaxMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->class = $subject->class;
                $studentsDetails[$student->id]->subjects[$subject->id]->grade = $subject->grade;
                $studentsDetails[$student->id]->subjects[$subject->id]->percentage = round($subject->percentage,2);
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMark = $subject->internalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = $subject->externalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->totalMarks = $subject->totalMarks;
                $studentsDetails[$student->id]->subjects[$subject->id]->markObtained = $subject->markObtained;
                $studentsDetails[$student->id]->subjects[$subject->id]->failedStatus = $subject->isFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->credit = $subject->credit;
                $studentsDetails[$student->id]->subjects[$subject->id]->wgpa = $subject->wgpa;
                $studentsDetails[$student->id]->subjects[$subject->id]->isExternalFailed = $subject->isExternalFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->isInternalFailed = $subject->isInternalFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->isInternal = $subject->isInternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->isExternal = $subject->isExternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->categoryId = $subject->categoryId;
                $studentsDetails[$student->id]->subjects[$subject->id]->categoryName = $subject->categoryName;
                $studentsDetails[$student->id]->subjects[$subject->id]->attendanceStatus = $subject->attendanceStatus;
                $studentsDetails[$student->id]->subjects[$subject->id]->isProjectGroupSubject = $subject->consolidatedMarkDetails->isProjectGroupSubject;
                $studentsDetails[$student->id]->subjects[$subject->id]->isFinalSemSubject = $subject->consolidatedMarkDetails->isFinalSemSubject;
                $studentsDetails[$student->id]->subjects[$subject->id]->studentSubjectStatus = $subject->isFailed == 'FAILED' ? 'Fail': 'Pass';
                if($subject->isFailed == 'FAILED'){
                    $studentsDetails[$student->id]->subjects[$subject->id]->grade = 'F';
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentage = '-';
                }
                if($subject->internalAttendanceStatus == AttendanceStatusConstant::ABSENT){
                    $studentsDetails[$student->id]->subjects[$subject->id]->internalMark = 'AB';
                }
                if($subject->internalAttendanceStatus == AttendanceStatusConstant::INCOMPLETE){
                    $studentsDetails[$student->id]->subjects[$subject->id]->internalMark = 'I';
                    $studentsDetails[$student->id]->subjects[$subject->id]->grade = 'I';
                    $studentsDetails[$student->id]->subjects[$subject->id]->studentSubjectStatus = 'I';
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentage = '-';
                    $studentsDetails[$student->id]->subjects[$subject->id]->markObtained = '-';
                    if($examRegistrationData->courseTypeName == CourseTypeConstants::PG){
                        $studentsDetails[$student->id]->subjects[$subject->id]->studentSubjectStatus = 'Incomplete';
                    }
                }
                if($subject->attendanceStatus == AttendanceStatusConstant::MALPRACTICE){
                    $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = "MAL";
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentage = '-';
                }
                if($subject->attendanceStatus == AttendanceStatusConstant::ABSENT){
                    $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = 'AB';
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentage = '-';
                    if($examRegistrationData->courseTypeName == CourseTypeConstants::PG && $subject->classType == "THEORY" && $examRegistrationData->batchStartYear >= 2022){
                        $studentsDetails[$student->id]->subjects[$subject->id]->grade = 'AB';
                    }
                }
                if($subject->attendanceStatus == AttendanceStatusConstant::INCOMPLETE){
                    $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = 'I';
                    $studentsDetails[$student->id]->subjects[$subject->id]->grade = 'I';
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentage = '-';
                    $studentsDetails[$student->id]->subjects[$subject->id]->studentSubjectStatus = 'I'; 
                }
                if($subject->consolidatedMarkDetails->excludeSubjectFromTotal == '1'){
                    $studentsDetails[$student->id]->subjects[$subject->id]->grade = $subject->isFailed == "PASSED" ? 'P' : 'F' ;
                }
                if($subject->studentInternalAttendanceStatus == 'FE'){
                    $studentsDetails[$student->id]->subjects[$subject->id]->grade = 'FE';
                    $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = '-';
                }
            }
            
        }
        $totalStudentDetails->passPercentage = round(100 * ( $totalStudentDetails->passStudents / $totalStudentDetails->totalStudents),2);
        $studentsDetails = array_values($studentsDetails); 
        foreach($studentsDetails as $student){
            $student->subjects = array_values($student->subjects); 
        }
        $response->studentsDetails = $studentsDetails;
        $response->totalStudentDetails = $totalStudentDetails;
        return $response;
    }
    protected function getExamRegistrationDetailsData($request){
        $examRegistrationDetails = new \stdClass;
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $examRegistrationDetails->name = reset($examRegistrationDetailsArray)->name;
        $examRegistrationDetails->examYear = reset($examRegistrationDetailsArray)->examYear;
        $examRegistrationDetails->examMonth = reset($examRegistrationDetailsArray)->examMonth;
        $examRegistrationDetails->examMonthName = reset($examRegistrationDetailsArray)->examMonthName;
        $examRegistrationDetails->type = reset($examRegistrationDetailsArray)->type;
        $examRegistrationDetails->groupId = reset($examRegistrationDetailsArray)->groups[0]->groupId;
        $examRegistrationDetails->groupName = reset($examRegistrationDetailsArray)->groups[0]->groupName;
        $examRegistrationDetails->courseTypeID = reset($examRegistrationDetailsArray)->groups[0]->courseTypeID;
        $examRegistrationDetails->courseTypeName = reset($examRegistrationDetailsArray)->groups[0]->courseTypeName;
        $examRegistrationDetails->academicTermName = reset($examRegistrationDetailsArray)->groups[0]->academicTermName;
        $examRegistrationDetails->academicTermYear = reset($examRegistrationDetailsArray)->groups[0]->academicTermYear;
        $examRegistrationDetails->academicTermYearRoman = strtoupper(CommonUtil::convertNumberToRoman($examRegistrationDetails->academicTermYear));
        $examRegistrationDetails->academicTermId = reset($examRegistrationDetailsArray)->groups[0]->academicTermId;
        $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($examRegistrationDetails->academicTermName);
        $examRegistrationDetails->isHonorCourse = reset($examRegistrationDetailsArray)->properties->isHonorCourse == "1" ? true : false;
        $examRegistrationDetails->isMinorCourse = reset($examRegistrationDetailsArray)->properties->isMinorCourse == "1" ? true : false;
        if ( $examRegistrationDetails->isHonorCourse || $examRegistrationDetails->isMinorCourse ){
            $examRegistrationDetails->isShortCourse = true;
        }
        $examRegistrationDetails->academicOrderNo = reset($examRegistrationDetailsArray)->groups[0]->academicOrderNo;
        $examRegistrationDetails->semInRomanLetter = $semesterNames->romanLetter;
        $examRegistrationDetails->semInFullName = $semesterNames->fullName;
        $examRegistrationDetails->semInSemNumber = $semesterNames->semNumber;
        $examRegistrationDetails->batchStartYear = reset($examRegistrationDetailsArray)->groups[0]->batchStartYear;
        $examRegistrationDetails->deptID = reset($examRegistrationDetailsArray)->groups[0]->deptID;
        $examRegistrationDetails->deptName = reset($examRegistrationDetailsArray)->groups[0]->deptName;
        $examRegistrationDetails->degreeName = reset($examRegistrationDetailsArray)->groups[0]->degreeName;
        foreach(reset($examRegistrationDetailsArray)->groups[0]->subjects as $subject){
            $examRegistrationDetails->subjects[$subject->id]->id = $subject->id;
            $examRegistrationDetails->subjects[$subject->id]->code = $subject->code;
            $examRegistrationDetails->subjects[$subject->id]->name = $subject->name;
            $examRegistrationDetails->subjects[$subject->id]->isInternal = $subject->isInternal;
            $examRegistrationDetails->subjects[$subject->id]->isExternal = $subject->isExternal;
            $examRegistrationDetails->subjects[$subject->id]->credit = $subject->credit;
            $examRegistrationDetails->subjects[$subject->id]->id = $subject->id;
            $examRegistrationDetails->subjects[$subject->id]->externalMaxMark = $subject->externalMaxMark;
            $examRegistrationDetails->subjects[$subject->id]->internalMaxMark = $subject->internalMaxMark;
            $examRegistrationDetails->subjects[$subject->id]->totalSubjectMark = $subject->totalSubjectMark;
            if(!$request->hideExternalOrInternalMark){
                $examRegistrationDetails->subjects[$subject->id]->subColSpan = 4;
                $examRegistrationDetails->subjects[$subject->id]->subColSpan = $examRegistrationDetails->subjects[$subject->id]->isInternal ? $examRegistrationDetails->subjects[$subject->id]->subColSpan + 1 : $examRegistrationDetails->subjects[$subject->id]->subColSpan;
                $examRegistrationDetails->subjects[$subject->id]->subColSpan = $examRegistrationDetails->subjects[$subject->id]->isExternal ? $examRegistrationDetails->subjects[$subject->id]->subColSpan + 1 : $examRegistrationDetails->subjects[$subject->id]->subColSpan;
            }
            else{
                $examRegistrationDetails->subjects[$subject->id]->subColSpan = 1;
            }
        }
        $examRegistrationDetails->totalColSpan = 8;
        if(!$request->hideExternalOrInternalMark){
            $examRegistrationDetails->totalColSpan = 8;
        }
        foreach($examRegistrationDetails->subjects as $subject){
            $examRegistrationDetails->totalColSpan = $examRegistrationDetails->totalColSpan + $subject->subColSpan;
        }
        $requestForSubjectGroup = new \stdClass;
        $requestForSubjectGroup->examRegId = $request->examRegistrationId;
        $requestForSubjectGroup->batchId = $request->groupId;
        $requestForSubjectGroup->termId = reset($examRegistrationDetailsArray)->groups[0]->academicTermId;
        $subjectGroups = CoreCommonExamService::getInstance()->getGroupedHeaderDetails($requestForSubjectGroup);
        if(!empty($subjectGroups->paperDetails)){
            foreach($subjectGroups->paperDetails as $subjectGroup){
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->id = $subjectGroup->id;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->name = $subjectGroup->paperName;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->academicPaperSubjectIds = $subjectGroup->paperSubjectIds;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->isGrouped = $subjectGroup->isgrouped == '1' ? true : false;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->subjectColSpan = 4;
            }
            foreach($subjectGroups->paperDetailsMinor as $subjectGroup){
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->id = $subjectGroup->id;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->name = $subjectGroup->paperName;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->academicPaperSubjectIds = $subjectGroup->paperSubjectIds;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->isGrouped = $subjectGroup->isgrouped == '1' ? true : false;
                $examRegistrationDetails->subjectGroups[$subjectGroup->id]->subjectColSpan = 4;
            }
            foreach($examRegistrationDetails->subjectGroups as $subjectGroup){
                $subjectGroup->academicPaperSubjectIds = array_values($subjectGroup->academicPaperSubjectIds);
                foreach($subjectGroup->academicPaperSubjectIds as $subjectId){
                    if($examRegistrationDetails->subjects[$subjectId]){
                        if(!$subjectGroup->isGrouped){
                            $subjectGroup->name = $examRegistrationDetails->subjects[$subjectId]->name;
                            $subjectGroup->code = $examRegistrationDetails->subjects[$subjectId]->code;
                        }
                        else{
                            $subjectGroup->codeArr[$examRegistrationDetails->subjects[$subjectId]->code] = $examRegistrationDetails->subjects[$subjectId]->code;
                            $subjectGroup->code = implode(",",$subjectGroup->codeArr);
                        }
                        $subjectGroup->isInternal = $examRegistrationDetails->subjects[$subjectId]->isInternal;
                        $subjectGroup->isExternal = $examRegistrationDetails->subjects[$subjectId]->isExternal;
                        $subjectGroup->externalMaxMark = $examRegistrationDetails->subjects[$subjectId]->externalMaxMark;
                        $subjectGroup->internalMaxMark = $examRegistrationDetails->subjects[$subjectId]->internalMaxMark;
                        $subjectGroup->totalSubjectMark = $examRegistrationDetails->subjects[$subjectId]->totalSubjectMark;
                        $subjectGroup->subColSpan = $examRegistrationDetails->subjects[$subjectId]->subColSpan;
                    }
                }
            }
            $examRegistrationDetails->subjects = array_values($examRegistrationDetails->subjects); 
            $examRegistrationDetails->subjectGroups = array_values($examRegistrationDetails->subjectGroups);
        }
        return $examRegistrationDetails;
    }
    protected function processStudentSubjectDataForCourseFileTemplate($studentsList){
        $response = new \stdClass;
        $studentBatchList = [];
        foreach($studentsList as $studentKey => $student){
            $student->errorMsg = "";
            $student->isRemoved = false;
            usort($student->subjectMarkHistory, 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)));
            });
            foreach($student->examRegistrations as $key => $examRegistration){
                if( !($examRegistration->batchProperties->isResultPublished ) ||  (($examRegistration->batchProperties->isResultPublished) && (strtotime($examRegistration->batchProperties->publishingStartDate) > strtotime(date("Y-m-d H:i"))))) {
                    unset($student->examRegistrations[$key]);
                }
                else if(($examRegistration->examType) != 'REGULAR'){
                    if(!empty($examRegistration->blockReasons) || $examRegistration->isResultWithHeld == '1'){
                        unset($student->examRegistrations[$key]);
                    }
                }
                else{
                    if(!empty($examRegistration->blockReasons)) {
                        $student->errorMsg = "Result Blocked";
                    }
                    else if($examRegistration->isResultWithHeld == '1'){
                        $student->errorMsg = "Result Withheld";
                    }
                }
            }
            $student->examRegistrationIds = array_column($student->examRegistrations,'id');
            if(empty($student->examRegistrations)){
                unset($studentsList[$studentKey]);
                $student->isRemoved = true;
            }
            if(empty($student->errorMsg)){
                foreach($student->subjectMarkHistory as $subjectMarkHistory){
                    if(in_array($subjectMarkHistory->examRegistrationId,$student->examRegistrationIds)){
                        $student->grade = $subjectMarkHistory->grade;
                        if($student->subjectMarkDetails->excludeSubjectFromTotal == '1'){
                            $student->grade = $subjectMarkHistory->resultStatus == "PASSED" ? 'P' : 'F' ;
                        }
                        if($subjectMarkHistory->attendanceStatus == 'ABSENT'){
                            $student->grade = $student->courseTypeName != 'MBA' ? 'I' : 'AB';
                        }
                         else if($subjectMarkHistory->resultStatus == 'FAILED'){
                            $student->grade = 'F';
                        }
                        if($subjectMarkHistory->studentAttendanceStatus == 'FE'){
                            $student->grade = 'FE';
                        }
                        $student->examYear = $subjectMarkHistory->examYear;
                        $student->examMonth = $subjectMarkHistory->examMonth;
                        $student->examMonthName = date("F", mktime(0, 0, 0, $student->examMonth, 10));
                        break;
                    }  
                }
            }
            if(!$student->isRemoved){
                $studentBatchList[$student->groupId]->id = $student->groupId;
                $studentBatchList[$student->groupId]->name = $student->groupName;
                $studentBatchList[$student->groupId]->students[] = $student;
            }
        }  
        $studentBatchList = array_values($studentBatchList);
        return $studentBatchList;
    }
}