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 / 145
Template15RegularTabulationRegisterGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
650.00
0.00% covered (danger)
0.00%
0 / 145
 __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
6.00
0.00% covered (danger)
0.00%
0 / 16
 renderRegularTabulationRegisterResult
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 30
 processStudentDataForRegularTabulationRegister
0.00% covered (danger)
0.00%
0 / 1
342.00
0.00% covered (danger)
0.00%
0 / 89
<?php
// Template For TR in CCM 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 Template15RegularTabulationRegisterGenerator extends RegularTabulationRegisterResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_15_pg";
        $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;
        $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/Template15/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $totalWidth = 707;
            $totalHeight=500;
            $options = array(
                'page-width'     => $totalWidth . "mm",
                'page-height'    => $totalHeight . "mm",
                'dpi'            => 96,
                'margin-top' => "20mm",
                'margin-left' => "10mm",
                'margin-right' => "10mm",
                'margin-bottom' => "10mm",
                'header-spacing' => "5",
                // '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 $studKey => $student) {
                foreach($student->academicTerms[0]->subjects as $subject){
                    $subjectTotalMark[$subject->id]->subjectTotalMarksOfStudents[$student->id] = $subject->markObtained;
                }
            }
            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;
                $studentsDetails[$student->id]->degree = $student->studentDetails->degree;
                $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]->examMonthName = date("F", mktime(0, 0, 0, $semMarkHistory->examMonth, 10));
                                $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 = round($semMarkHistory->sgpa, 2);
                                $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]->sgpa = round($semMarkHistory->sgpa, 2);
                                $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]->subjects[$subject->id]->creditGradePoint =   sprintf('%0.2f', $subject->creditGradePoint);
                            $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->internalGrade = $subject->isInternal ? $subject->internalGrade : "-";
                            $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;
                            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]->academicTerms[$academicTerm->id]->subjects[$subject->id]->percentile = round(100 * $position / $subjectStudentCount);
                            }
                           
                        }
                    }
                }
            }
            $response->studentsDetails = $studentsDetails;
            $response->displaySubjects = $displaySubjectArray;
            return $response;
        }
        catch (\Exception $e){
            throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    } 
}