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 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 255
Template28IndividualResultGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
1406.00
0.00% covered (danger)
0.00%
0 / 255
 __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
56.00
0.00% covered (danger)
0.00%
0 / 34
 renderIndividualMarkCardResult
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 47
 processStudentData
0.00% covered (danger)
0.00%
0 / 1
342.00
0.00% covered (danger)
0.00%
0 / 122
 getExamRegistrationDetailsData
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 45
<?php
// Template Individual Generator For Ramaiaha Colleges
namespace com\linways\ec\core\service\RegularIndividualMarkCardGenerator;
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\service\RegularIndividualMarkCardGenerator\RegularIndividualMarkCardResultDataGenerator;
use com\linways\core\ams\professional\service\StudentService;
class Template28IndividualResultGenerator extends RegularIndividualMarkCardResultDataGenerator
{
    public function __construct(){}
     /**
     * get Template Name
     * @param $request
     * @param $templateName
     */
    protected function getTemplateName($request){
        $templateName = "Template_28";
        $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 = [];
        $request->orderByCurriculum = 1;
        $studentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($request);
        $allStudentsMarkDetails = [];
        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;
        }
        $response->examRegistrationData = $this->getExamRegistrationDetailsData($request);
        if($response->examRegistrationData->enableNewFormat2021){
            $reqAllStudent = new \stdClass;
            $reqAllStudent->examRegistrationId = $request->examRegistrationId;
            $reqAllStudent->groupId = $request->groupId;
            $allStudentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($reqAllStudent);
        }
        $responseOfStudentData = $this->processStudentData($studentsMarkDetails,$request,$allStudentsMarkDetails);
        $response->studentData = $responseOfStudentData->studentsDetails;
        $response->totalStudentData = $responseOfStudentData->totalStudentDetails;
       
        $response->examRegistrationData->currentDate = date("F j, Y");
        $response->collegeAndOtherData = CommonExamService::getInstance()->getCollegeDetails($request);
        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/RegularIndividualMarkCards/Template28/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $responseHtml .= '<script>
                                var file1 = document.getElementById("backgroundImg").files[0];
                                var reader1 = new FileReader();
                                console.log(reader1);
                                reader1.onloadend = function() {
                                    $(".pages").css({
                                        "backgroundImage": "url(" + reader1.result + ")"
                                    });
                                }
                                if (file1) {
                                    reader1.readAsDataURL(file1);
                                } else {}
                            </script>';
            $prtContent .= '<html><head>';
            if($data->examRegistrationData->enableNewFormat2021){
                $prtContent .= '';
            }
            else{
                $prtContent .= '';
            }
            $prtContent .= '</head><title>Individual Mark Card</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $totalWidth = 297;
            $totalHeight = 210;
            $options = array(
                'page-width'     => $totalWidth."mm",
                'page-height'    => $totalHeight."mm",
                'dpi'            => 96,
                'margin-top' => "9mm",
                'margin-left' => "5mm",
                'margin-right' => "5mm",
                '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 = $prtContent;
            $programResult->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $programResult;
        }
    }
    /**
     * processStudentData
     * @param $studentsMarkDetails
     * @param $studentsDetails
     */
    protected function processStudentData($studentsMarkDetails,$request,$allStudentsMarkDetails){
        $response = new \stdClass;
        $totalStudentDetails = new \stdClass;
        $totalStudentDetails->totalStudents = count($studentsMarkDetails);
        $studentsDetails = [];
        if($allStudentsMarkDetails){
            foreach ($allStudentsMarkDetails as $studKey => $student) {
                foreach($student->academicTerms[0]->subjects as $subject){
                    $subjectTotalMark[$subject->id]->subjectTotalMarksOfStudents[$student->id] = $subject->markObtained;
                }
            }
        }
        foreach($studentsMarkDetails as $student){
            $slNoRequest =  new \stdClass;
            $slNoRequest->studentId = $student->id;
            $slNoRequest->examRegistrationId = $request->examRegistrationId;
            $studentsDetails[$student->id]->slNo = CommonExamService::getInstance()->getStudentExamMarkListSerialNumber($slNoRequest)->markListSerialNo;
            $studentsDetails[$student->id]->id = $student->id;
            $studentsDetails[$student->id]->name = $student->studentDetails->name;
            $studentsDetails[$student->id]->isResultBlocked = $student->isResultBlocked;
            $studentsDetails[$student->id]->myImage = StudentService::getInstance()->getStudentProfilePic($student->id)->docpath;
            $studentsDetails[$student->id]->failedStatus = $student->academicTerms[0]->isFailed;
            $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
            $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
            $student->blockingMsg = "";
            if($student->blockReasons && $student->isResultBlocked){
                foreach($student->blockReasons as $reason){
                    if ($reason->contactPersonName) {
                        $student->blockingMsg .= "<div class='text-danger alert-student'>Your result is withheld due to " . $reason->name . ". Kindly meet " . $reason->contactPersonName . " " . $reason->contactPersonDecription . "</div></br>";
                    } else if ($reason->name) {
                        $student->blockingMsg .= "<div class='text-danger alert-student'>Result has been withheld due to " . $reason->name."</div></br>";
                    }
                    else{
                        $student->blockingMsg .= "<div class='text-danger alert-student'>Result has been withheld</div></br>";
                    }
                }
            }
            $studentsDetails[$student->id]->blockingMsg = $student->blockingMsg;
            
            $academicTerm = reset(array_filter(reset($student->academicTerms)->markHistory,function($value)use($request){
                return $value->examRegistrationId == $request->examRegistrationId;
            }));
            if(empty($academicTerm)){
                $academicTerm = reset(array_filter(reset($student->academicTerms)->markHistory,function($value)use($request){
                    return $value->historyType == 'REGULAR';
                }));
            }
            $studentsDetails[$student->id]->semesterGrade = $academicTerm->grade;
            $studentsDetails[$student->id]->semesterCredit = $student->academicTerms[0]->credit;
            $studentsDetails[$student->id]->semesterCreditGradePoint = $academicTerm->creditGradePoint;
            $studentsDetails[$student->id]->semesterGradePoint = array_sum(array_column(array_filter($student->academicTerms[0]->subjects, function($subject) {
                return $subject->excludeSubjectFromTotal != 1;
            }), 'gradePoint'));
            // $studentsDetails[$student->id]->semesterSgpa = $academicTerm->sgpa;
            $studentsDetails[$student->id]->semesterPercentage = $academicTerm->percentage;
            $studentsDetails[$student->id]->semesterSgpa = bcdiv($academicTerm->rawSgpa, 1, 2);
            $studentsDetails[$student->id]->semesterpassPercentage = $academicTerm->passPercentage;
            $studentsDetails[$student->id]->semesterTotalMinimumMarks = $academicTerm->totalMarks *  $academicTerm->passPercentage / 100;
            $studentsDetails[$student->id]->semesterTotalMarks = $academicTerm->totalMarks;
            $studentsDetails[$student->id]->semesterMarkObtained = $academicTerm->markObtained;
            $studentsDetails[$student->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($academicTerm->markObtained));
            $studentsDetails[$student->id]->semesterPercentage = round($academicTerm->percentage,2);
            $studentsDetails[$student->id]->semesterClass = $academicTerm->class;
            if($studentsDetails[$student->id]->failedStatus == "PASSED"){
                $totalStudentDetails->passStudents ++;
            }
            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 = round($subject->externalMaxMark, 2);
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMinimumMark = round($subject->externalMaxMark * $subject->externalPassPercentage / 100, 2);
                $studentsDetails[$student->id]->externalMinimumMark += $studentsDetails[$student->id]->subjects[$subject->id]->externalMinimumMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMaxMark = round($subject->internalMaxMark, 2);
                $studentsDetails[$student->id]->subjects[$subject->id]->class = $subject->class;
                $studentsDetails[$student->id]->subjects[$subject->id]->grade = $subject->grade;
                $studentsDetails[$student->id]->subjects[$subject->id]->classType = $subject->classType;
                $studentsDetails[$student->id]->subjects[$subject->id]->percentage = $subject->percentage;
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMark = $subject->internalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = $subject->externalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->totalMaxMark = $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]->attendanceStatus = $subject->attendanceStatus;
                $studentsDetails[$student->id]->subjects[$subject->id]->credit = $subject->credit;
                $studentsDetails[$student->id]->subjects[$subject->id]->creditGradePoint = $subject->creditGradePoint;
                $studentsDetails[$student->id]->gradePoint += $subject->gradePoint;
                $studentsDetails[$student->id]->subjects[$subject->id]->gradePoint = $subject->gradePoint;
                $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]->internalLetterGrade = $subject->internalLetterGrade;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalLetterGrade = $subject->externalLetterGrade;
                $studentsDetails[$student->id]->subjects[$subject->id]->excludeSubjectFromTotal = $subject->excludeSubjectFromTotal == '1' ? 1 : 0;
                $studentsDetails[$student->id]->internalMaxMark += $subject->internalMaxMark;
                $studentsDetails[$student->id]->externalMaxMark += $subject->externalMaxMark;
                $studentsDetails[$student->id]->internalMark += $subject->internalMark;
                $studentsDetails[$student->id]->externalMark += $subject->externalMark;
                if($subjectTotalMark[$subject->id]){
                    $subjectTotalMarksOfStudents = $subjectTotalMark[$subject->id]->subjectTotalMarksOfStudents;
                    asort($subjectTotalMarksOfStudents);
                    $subjectStudentCount = count($subjectTotalMarksOfStudents);
                    $keys = array_keys($subjectTotalMarksOfStudents);
                    $position = array_search($student->id, $keys);
                    $position = $position + 1;
                    $studentsDetails[$student->id]->subjects[$subject->id]->percentile = round(100 * $position / $subjectStudentCount);
                }
            }
            
        }
        $totalStudentDetails->passPercentage = round(100 * ( $totalStudentDetails->passStudents / $totalStudentDetails->totalStudents),2);
        $studentsDetails = array_values($studentsDetails); 
        foreach($studentsDetails as $student){
            $student->subjects = array_values($student->subjects); 
            $student->subjectCategories = array_values($student->subjectCategories);
            foreach($student->subjectCategories as $subCategory){
                $subCategory->subjects = array_values($subCategory->subjects); 
                $subCategory->totalSubjects=count($subCategory->subjects);
                $subCategory->totalCategoryAwardedMark = 0;
                foreach($subCategory->subjects as $subject){
                    $subCategory->totalCategoryAwardedMark += $subject->internalMark + $subject->externalMark;
                }
            } 
        }
        $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->headingOfTemplate = "STATEMENT OF MARKS";
        $examRegistrationDetails->gpaOrSgpa = "SGPA";
        $examRegistrationDetails->pgCriteria = "";
        $examRegistrationDetails->name = $examRegistrationDetailsArray[0]->name;
        $examRegistrationDetails->examYear = $examRegistrationDetailsArray[0]->examYear;
        $examRegistrationDetails->examMonth = $examRegistrationDetailsArray[0]->examMonth;
        $examRegistrationDetails->examMonthName = strtoupper($examRegistrationDetailsArray[0]->examMonthName);
        $examRegistrationDetails->type = $examRegistrationDetailsArray[0]->type;
        $examRegistrationDetails->groupId = $examRegistrationDetailsArray[0]->groups[0]->groupId;
        $examRegistrationDetails->groupName = $examRegistrationDetailsArray[0]->groups[0]->groupName;
        $examRegistrationDetails->courseTypeID = $examRegistrationDetailsArray[0]->groups[0]->courseTypeID;
        $examRegistrationDetails->courseTypeName = $examRegistrationDetailsArray[0]->groups[0]->courseTypeName;
        $examRegistrationDetails->academicTermName = $examRegistrationDetailsArray[0]->groups[0]->academicTermName;
        $examRegistrationDetails->academicTermYear = $examRegistrationDetailsArray[0]->groups[0]->academicTermYear;
        $examRegistrationDetails->academicTermYearRoman = strtoupper(CommonUtil::convertNumberToRoman($examRegistrationDetails->academicTermYear));
        $examRegistrationDetails->academicTermId = $examRegistrationDetailsArray[0]->groups[0]->academicTermId;
        $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($examRegistrationDetails->academicTermName);
        $examRegistrationDetails->semInRomanLetter = $semesterNames->romanLetter;
        $examRegistrationDetails->semInFullName = strtoupper($semesterNames->fullName);
        $examRegistrationDetails->semInSemNumber = $semesterNames->semNumber;
        $examRegistrationDetails->batchStartYear = $examRegistrationDetailsArray[0]->groups[0]->batchStartYear;
        $examRegistrationDetails->deptID = $examRegistrationDetailsArray[0]->groups[0]->deptID;
        $examRegistrationDetails->deptName = $examRegistrationDetailsArray[0]->groups[0]->deptName;
        $examRegistrationDetails->degreeName = strtoupper($examRegistrationDetailsArray[0]->groups[0]->degreeName);
        $examRegistrationDetails->programName = $examRegistrationDetailsArray[0]->groups[0]->programName;
        $examRegistrationDetails->enableNewFormat2021 = $examRegistrationDetails->batchStartYear > 2020 ? true : false;
        if($examRegistrationDetails->courseTypeName == "PG"){
            $examRegistrationDetails->pgCriteria = "Aggregate minimum for pass in each semester is 50%.";
        }
        if($request->isStudentSideExamResult == '1' ){
            if($examRegistrationDetailsArray[0]->groups[0]->examBatchProperties->isResultFinalized == 1){
                $examRegistrationDetails->headingOfTemplate = "STATEMENT OF MARKS";
            }
            else{
                $examRegistrationDetails->headingOfTemplate = "PROVISIONAL STATEMENT OF MARKS";
            }
        }
        $examRegistrationDetails->subjects = array_values($examRegistrationDetails->subjects); 
        return $examRegistrationDetails;
    }
   
   
}