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 / 203
Template13RegularTabulationRegisterGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
992.00
0.00% covered (danger)
0.00%
0 / 203
 __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 / 10
 processData
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 21
 renderRegularTabulationRegisterResult
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 32
 processStudentDataForRegularTabulationRegister
0.00% covered (danger)
0.00%
0 / 1
462.00
0.00% covered (danger)
0.00%
0 / 140
<?php
// Template For TR in ASSUMPTION College
namespace com\linways\ec\core\service\RegularTabulationRegisterGenerator;
use com\linways\ec\core\service\StudentMarkListService;
use com\linways\ec\core\service\TabulationRegisterService;
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\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\service\RegularTabulationRegisterGenerator\RegularTabulationRegisterResultDataGenerator;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
class Template13RegularTabulationRegisterGenerator extends RegularTabulationRegisterResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_13";
        $examRegistrationDetails = new \stdClass;
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $examRegistrationDetails->courseTypeName = $examRegistrationDetailsArray[0]->groups[0]->courseTypeName;
        $examRegistrationDetails->batchStartYear = $examRegistrationDetailsArray[0]->groups[0]->batchStartYear;
        return $templateName; 
    }
     /**
     * Process Student data college base
     *
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $studentsMarkDetails = [];
        $studentsMarkDetails = TabulationRegisterService::getInstance()->getAllRegistredStudentMarkDetailsForTabulationRegister($request);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $studentsMarkDetails = $this->processStudentDataForRegularTabulationRegister($studentsMarkDetails,$request);
        $response->studentData = $studentsMarkDetails->studentsDetails;
        $response->examRegistrationData = TabulationRegisterService::getInstance()->getExamRegistrationDetailsForTabulationRegisterReports($request);
        usort($studentsMarkDetails->displaySubjects,function($a,$b){
            return $a->priority > $b->priority;
        });
        $response->examRegistrationData->subjects =  $studentsMarkDetails->displaySubjects;
        array_walk($response->examRegistrationData->subjects, function($subject){
            $subject->colspan = 5;
            if($subject->isInternal && $subject->isExternal){
                $subject->colspan = 6;
            }
        });
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails();
        $response->displayContentOptions = $request->displayContentOptions;
        return $response;
       
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderRegularTabulationRegisterResult($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/TablationRegister/RegularTR/Template13/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $pageNumberPrefix = "Page [page] of [toPage]";
            $totalWidth = (count($data->examRegistrationData->subjects) * 6 * 8) + 100;
            $totalWidth = $totalWidth < 297 ? 297 : $totalWidth;
            $totalHeight = $totalWidth / 1.414;
            $options = array(
                'page-width'     => $totalWidth . "mm",
                'page-height'    => $totalHeight . "mm",
                'dpi'            => 96,
                'margin-top' => "5mm",
                'margin-left' => "5mm",
                'margin-right' => "5mm",
                'margin-bottom' => "5mm",
                'footer-center' => $pageNumberPrefix,
                // '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;
        }
       
    }
     /**
     * processStudentDataForRegularTabulationRegister
     * @param studentDetails
     * @return studentDetails
     * @author Krishnajith
     */
    public function processStudentDataForRegularTabulationRegister($studentMarkDetails,$request,$examRegistrationDetails = null){
        try{ 
            $response = new \stdClass;
            $displaySubjectArray = [];
            $studentsDetails = [];
            $isCurrentSemester = true;
            foreach($studentMarkDetails as $student){
                $student->roundOff = 2;
                $studentsDetails[$student->id]->id = $student->id;
                $studentsDetails[$student->id]->name = $student->studentDetails->name;
                $studentsDetails[$student->id]->cgpa = $student->cgpa;
                $studentsDetails[$student->id]->grade = $student->grade;
                $customFields = AmsCustomFieldsService::getInstance()->getAmsCustomFieldValue(AmsCustomFieldsEntities::STUDENT, $student->id, []);
                if( $customFields ){
                    $studentsDetails[$student->id]->ktuCode = CommonExamService::getInstance()->getCustomFieldObjectList($customFields)->studentData->KTU_CODE;
                }
                
                $studentsDetails[$student->id]->myImage = $student->studentDetails->myImage;
                $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
                $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
                $studentsDetails[$student->id]->roundOff = $student->studentDetails->academicYear < 2019 ?  2 : 3;
                foreach($student->academicTerms as $academicTerm){
                    if($request->fetchAllSemesterDetails){
                        $isCurrentSemester = $examRegistrationDetails->academicTermId == $academicTerm->id ? true : false;
                    }
                    if($isCurrentSemester){
                        $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;
                        foreach($academicTerm->markHistory as $semMarkHistory){
                            if($semMarkHistory->examRegistrationId == $request->examRegistrationId){
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->failedStatus = $semMarkHistory->failedStatus;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterGrade = $semMarkHistory->grade;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = $semMarkHistory->gradePoint;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->examMonth = $semMarkHistory->examMonth;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->examYear = $semMarkHistory->examYear;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditPoint = $semMarkHistory->creditPoint;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterSgpa = sprintf('%0.2f', $semMarkHistory->sgpa);
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterTotalMarks = $academicTerm->totalMarks;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtained = $semMarkHistory->totalMark;
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($semMarkHistory->totalMark))." ONLY";
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterPercentage = round($semMarkHistory->percentage,2);
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterClass = $semMarkHistory->class;
                                $studentsDetails[$student->id]->overallClass =  $semMarkHistory->class;
                                $studentsDetails[$student->id]->overallGrade= $semMarkHistory->grade;
                                $studentsDetails[$student->id]->failedStatus = $semMarkHistory->failedStatus; 
                                $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->examType = $semMarkHistory->historyType;
                            }
                        }
                        foreach( $academicTerm->subjects as $subject){ 
                            $displaySubjectArray[$subject->id]= $subject;
                            $subject->internalMaxMark = $subject->isInternal ? $subject->internalMaxMark : '-';
                            $subject->externalMaxMark = $subject->isExternal ? $subject->externalMaxMark : '-';
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id] = $subject;
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMark = (float)$subject->externalMark;
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->percentage = round($subject->percentage,2);
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->markObtainedInWord =  strtoupper(CommonUtil::convertNumberToWords((int)$subject->markObtained));
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjectCategories[$subject->categoryId]->categoryId = $subject->categoryId;
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjectCategories[$subject->categoryId]->categoryName = $subject->categoryName;
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjectCategories[$subject->categoryId]->subjects[$subject->id] = $subject;
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->excludeSubjectFromTotal = $subject->consolidatedMarkDetails->excludeSubjectFromTotal == '1' ? 1 : 0;
                        }
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = array_sum(array_column($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects,'creditGradePoint'));
                    }
                    else{
                        $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->id = $academicTerm->id;
                        $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($academicTerm->name);
                        $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semInRomanLetter = $semesterNames->romanLetter;
                        $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semInFullName = $semesterNames->fullName;
                        $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semInSemNumber = $semesterNames->semNumber;
                        if($request->considerSupplementary){
                            if($request->supplementaryMonthUpperLimit && $request->supplementaryYearUpperLimit){
                                $lastSemMonthYear = date("Y-m", strtotime($request->supplementaryYearUpperLimit . "-" . $request->supplementaryMonthUpperLimit));
                                $tempMonthYear = "";
                                $currentMonthYear = "";
                                array_walk($academicTerm->markHistory,function($term,$key)use($student,$academicTerm,$studentsDetails,$lastSemMonthYear,$tempMonthYear,$currentMonthYear){
                                    if($lastSemMonthYear > date("Y-m", strtotime($term->examYear . "-" . $term->examMonth))){
                                        $currentMonthYear = date("Y-m", strtotime($term->examYear . "-" . $term->examMonth)); 
                                        if($currentMonthYear > $tempMonthYear){
                                            $tempMonthYear = $currentMonthYear;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->failedStatus = $term->failedStatus;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->examMonth = $term->examMonth;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->examYear = $term->examYear;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterGrade = $term->grade;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCredit = $term->credit;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCreditGradePoint = $term->gradePoint;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterSgpa = sprintf('%0.2f', $term->sgpa);
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtained = $term->markObtained;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($term->markObtained))." ONLY";
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterPercentage = round($term->percentage,2);
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterClass = $term->class;
                                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->examType = $term->historyType;
                                        }
                                    }
                                });
                            }
                            else{
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->failedStatus = $academicTerm->isFailed;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterGrade = $academicTerm->grade;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCreditGradePoint = $academicTerm->gradePoint;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterSgpa = round($academicTerm->sgpa, $studentsDetails[$student->id]->roundOff);
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtained = $academicTerm->markObtained;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($academicTerm->markObtained))." ONLY";
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterPercentage = round($academicTerm->percentage,2);
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterClass = $academicTerm->class;
                                $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->examType = $academicTerm->historyType;
                            }
                        }
                        else{
                            $semMarkHistory = reset(array_filter($academicTerm->markHistory,function($semMarkHistory){
                                return $semMarkHistory->historyType == "REGULAR";
                            }));
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->failedStatus = $semMarkHistory->failedStatus;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterGrade = $semMarkHistory->grade;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterCreditGradePoint = $semMarkHistory->gradePoint;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterSgpa = round($semMarkHistory->sgpa, $studentsDetails[$student->id]->roundOff);
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterTotalMarks = $academicTerm->totalMarks;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtained = $semMarkHistory->markObtained;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($semMarkHistory->markObtained))." ONLY";
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterPercentage = round($semMarkHistory->percentage,2);
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->semesterClass = $semMarkHistory->class;
                            $studentsDetails[$student->id]->otherAcademicTerms[$academicTerm->id]->examType = $semMarkHistory->historyType;
                        }
                    }
                }
                if(count($student->academicTerms) > 1){
                    $studentsDetails[$student->id]->overallClass = $student->class;
                    $studentsDetails[$student->id]->overallGrade= $student->grade;
                    $studentsDetails[$student->id]->failedStatus = $student->isFailed;
                }
            }
            
            $response->studentsDetails = $studentsDetails;
            $response->displaySubjects = $displaySubjectArray;
            return $response;
        }
        catch (\Exception $e){
            throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
   
   
}