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 / 260
Template5SupplementaryIndividualResultGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
3080.00
0.00% covered (danger)
0.00%
0 / 260
 __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 / 7
 processData
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 31
 renderIndividualMarkCardResult
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 30
 processSupplementaryRegularStudentData
0.00% covered (danger)
0.00%
0 / 1
2070.00
0.00% covered (danger)
0.00%
0 / 192
<?php
//Template Individual Generator For MBCET 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\constant\AttendanceStatusConstant;
use com\linways\core\ams\professional\constant\examcontroller\CourseTypeConstants;
class Template5SupplementaryIndividualResultGenerator extends SupplementaryIndividualMarkCardResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_5";
        $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 = [];
        $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->orderByCurriculum = 1;
        $searchRequest->excludeMinorHonor = 1;
        $studentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($searchRequest);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $studentsMarkDetails = $this->processSupplementaryRegularStudentData($studentsMarkDetails,$request,$examRegistrationData);
        $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;
        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{
            $responseHtml = TwigRenderer::renderTemplateFileToHtml(realpath(DOCUMENT_ROOT."../examcontroller-api/src/com/linways/web/templates/SupplementaryIndividualMarkCards/Template5/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "<style>
                
                </style>";
            $prtContent .= '</head><title>Supplementary MarkList</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' => "9mm",
                'margin-right' => "9mm",
                '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);
        return  $programResult;
        }
       
    }
    /**
     * processSupplementaryStudentData
     * @param studentDetails
     * @return studentDetails
     */
public function processSupplementaryRegularStudentData($studentMarkDetails,$examRegistrationRequest,$examRegistrationDetails){
        $response = new \stdClass;
        $totalStudentDetails = new \stdClass;
        $totalStudentDetails->totalStudents = count($studentMarkDetails);
        $displaySubjectArray = [];
        $displaySubjectCategories = [];
        $studentsDetails = [];
        $batchRequest =  new \stdClass;
        $batchRequest->examRegistrationId = $examRegistrationRequest->examRegistrationId;
        $batchRequest->batchStartYear = $examRegistrationDetails->batchStartYear;
        $batchRequest->deptId = $examRegistrationDetails->deptID;
        $batches = CommonExamService::getInstance()->getExambatchesByRequest($batchRequest);
        $registeredStudentsInDepartment = [];
        foreach($batches as $batch){
            $batchRequest->groupId = $batch->groupId;
            $students = CommonExamService::getInstance()->getstudentRegisteredForExam($batchRequest);
            $registeredStudentsInDepartment = array_merge($registeredStudentsInDepartment,$students);
        }
        $registeredStudentsInDepartment  = array_values($registeredStudentsInDepartment);
        $serialNos = ["C1" =>"1001", "R1" => "2001", "E1" => "3001", "T1" => "4001", "M1" => "5001"];
        foreach($studentMarkDetails as $student){
            $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;
            $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 = $student->studentDetails->myImage;
            $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
            $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
            foreach($student->academicTerms as $academicTerm){
                $currentAcademicTerm = reset(array_filter(reset($student->academicTerms)->markHistory,function($value)use($examRegistrationRequest){
                    return $value->examRegistrationId == $examRegistrationRequest->examRegistrationId;
                }));
                // need to remove this condition after seral number is corrected
                $regularExamDetails = reset(array_filter(reset($student->academicTerms)->markHistory,function($value){
                    return $value->historyType == 'REGULAR';
                }));
                $studentSubjectRequest = new \stdClass(); 
                $studentSubjectRequest->studentId = $student->id;
                $studentSubjectRequest->examMonthLimit = $examRegistrationDetails->examMonth;
                $studentSubjectRequest->examYearLimit = $examRegistrationDetails->examYear;
                $studentSubjectRequest->upToAcademicTermOrderNo = $examRegistrationDetails->academicOrderNo;
                
                $studentSubjectHistory = StudentMarkListService::getInstance()->getAllStudentSubjectMarkDetailsByRequest($studentSubjectRequest);
                $subjectHistory = [];
                $totalCredit = 0;
                $earnedCredit = 0;
                $earnedCreditPoint = 0;
                $semesterCgpa = 0;
                $hadSupply = false;
                foreach($studentSubjectHistory as $studentHistory){
                    if($subjectHistory[$studentHistory->paperSubjectId]){
                        if($studentHistory->subjectFailedStatus == "FAILED" AND $studentHistory->subjectAttendanceStatus != "ABSENT" && $studentHistory->academicTermId == $examRegistrationDetails->academicTermId){
                            $hadSupply = true;
                        }
                        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" && $examRegistrationDetails->academicTermId == $studentHistory->academicTermId ){
                                    $earnedCredit += $studentHistory->credit;
                                }
                            }
                            else{
                                // if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationDetails->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" && $examRegistrationDetails->academicTermId == $studentHistory->academicTermId ){
                                $earnedCredit += $studentHistory->credit;
                            }
                        }
                        else{
                            // if($studentHistory->subjectFailedStatus == "PASSED" && $examRegistrationDetails->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";
                }));
                $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]->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]->overallFailedStatus = $overallFailedHistory ? "FAILED" : "PASSED";
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterGrade = $currentAcademicTerm->grade;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                $studentsDetails[$student->id]->earnedCredits = $earnedCredit;
                $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]->semesterCgpa = sprintf('%0.2f', $semesterCgpa);
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamMonth = $currentAcademicTerm->examMonth;
                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->latestExamYear = $currentAcademicTerm->examYear;
                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)); 
                    });
                    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)));
                    });
                    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)));
                    });
                    $subject->latestMarkHistory = reset($subject->markHistory);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id] = $subject;
                    $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]->latestExamMonthName = ExamRegistrationService::getInstance()->getMonthName($subject->latestMarkHistory->examMonth);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isProjectGroupSubject = $subject->consolidatedMarkDetails->isProjectGroupSubject;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isFinalSemSubject = $subject->consolidatedMarkDetails->isFinalSemSubject;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->credit = sprintf('%0.2f', $subject->credit);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->studentSubjectStatus = $subject->latestMarkHistory->resultStatus == 'FAILED' ? 'Fail': 'Pass';
                    if($subject->latestMarkHistory->resultStatus == 'FAILED'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'F';
                    }
                    if($subject->latestMarkHistory->internalAttendanceStatus == AttendanceStatusConstant::ABSENT){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->internalMark = 'AB';
                    }
                    if($subject->latestMarkHistory->internalAttendanceStatus == AttendanceStatusConstant::INCOMPLETE){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'I';
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->studentSubjectStatus = 'I';
                        if($examRegistrationDetails->courseTypeName == CourseTypeConstants::PG){
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->studentSubjectStatus = 'Incomplete';
                        }
                    }
                    if($subject->latestMarkHistory->attendanceStatus == AttendanceStatusConstant::ABSENT){
                        if($examRegistrationDetails->courseTypeName == CourseTypeConstants::PG && $subject->classType == "THEORY" && $examRegistrationDetails->batchStartYear >= 2022){
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'AB';
                        }
                    }
                    if($subject->latestMarkHistory->attendanceStatus == AttendanceStatusConstant::INCOMPLETE){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'I';
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->studentSubjectStatus = 'I'; 
                    }
                    if($subject->consolidatedMarkDetails->excludeSubjectFromTotal == '1'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = $subject->latestMarkHistory->resultStatus == "PASSED" ? 'P' : 'F' ;
                    }
                    if($subject->latestMarkHistory->studentInternalAttendanceStatus == 'FE'){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->grade = 'FE';
                    }
                }
                // $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = array_sum(array_column($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects,'creditGradePoint'));
            }
            // serial number - required for failed and passed students
            $slNoRequest =  new \stdClass;
            $slNoRequest->studentId = $student->id;
            $slNoRequest->examRegistrationId = $examRegistrationRequest->examRegistrationId;
            $slNoRequest->checkExistance = true;
            $slNo = CommonExamService::getInstance()->getStudentExamMarkListSerialNumber($slNoRequest)->markListSerialNo;
            if ( empty($slNo)) {
                $studentId = $student->id;
                $deptStudentFetched = array_filter($registeredStudentsInDepartment, function ($studentObj) use ($studentId) {
                    return $studentObj->studentId == $studentId;
                });
                $position= current(array_keys($deptStudentFetched));
                $slNo = (int)$serialNos[$examRegistrationDetails->departmentSpecialization] + $position;
            }
            $studentsDetails[$student->id]->slNo = $slNo;
            $slNoType  = $hadSupply ? "S" : "R";
            // $studentsDetails[$student->id]->certicifateNo = 'No.CoE/Ex/'.$student->latestExamYear.'/'.$examRegistrationDetails->courseTypeName.'/S'.$studentsDetails[$student->id]->semInSemNumber.$slNoType.'/'.$studentsDetails[$student->id]->slNo;
            $studentsDetails[$student->id]->certicifateNo = 'No.CoE/Ex/'.reset($studentsDetails[$student->id]->academicTerms)->latestExamYear.'/'.$examRegistrationDetails->courseTypeName.'/S'.reset($studentsDetails[$student->id]->academicTerms)->semInSemNumber.$slNoType.'/'.$studentsDetails[$student->id]->slNo;
            
            
            // $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, 4, "0", STR_PAD_LEFT);
            // }
            // $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->certicifateNo = 'No:GC/'.reset($studentsDetails[$student->id]->academicTerms)->latestExamYear.'/S'.reset($studentsDetails[$student->id]->academicTerms)->semInSemNumber.'/'.$studentsDetails[$student->id]->slNo;
        }
        // uasort($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects, function($a, $b) {
        //     return ($a->priority > $b->priority);
        // });
        $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;
    }
}