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 / 183
Template14SupplementaryTabulationRegisterGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
870.00
0.00% covered (danger)
0.00%
0 / 183
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getTemplateName
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 processData
0.00% covered (danger)
0.00%
0 / 1
110.00
0.00% covered (danger)
0.00%
0 / 53
 renderSupplementaryTabulationRegisterResult
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 56
 processStudentDataForTabulationRegister
0.00% covered (danger)
0.00%
0 / 1
210.00
0.00% covered (danger)
0.00%
0 / 71
<?php
// Template Supply TR Generator For SCEK 
namespace com\linways\ec\core\service\SupplementaryTabulationRegisterGenerator;
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\ec\core\service\GradeSchemeService;
use com\linways\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\service\SupplementaryTabulationRegisterGenerator\SupplementaryTabulationRegisterResultDataGenerator;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
class Template14SupplementaryTabulationRegisterGenerator extends SupplementaryTabulationRegisterResultDataGenerator{
    public function __construct(){}
    protected function getTemplateName($request){
        $templateName = "template_14";
        return $templateName;
    }
     /**
     * Process Student data college base
     *
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $studentsMarkDetails = [];
        $examRegistrationData = TabulationRegisterService::getInstance()->getExamRegistrationDetailsForTabulationRegisterReports($request);
        $examRegistrationData->totalCredit = 0;
        $examRegistrationData->programName = $examRegistrationData->degreeName.' '.$examRegistrationData->streamName;
        $examRegistrationData->academicExamYear = ( $examRegistrationData->examYear - 1) . "-" .   $examRegistrationData->examYear;
        if((int)$examRegistrationData->semInSemNumber % 2){
            $examRegistrationData->academicExamYear =  $examRegistrationData->examYear . "-" .  ( $examRegistrationData->examYear + 1);
        }
        $searchRequest = new \stdClass;
        $searchRequest->fetchAllSemesterDetails = $examRegistrationData->isFinalSemester ? true : false;
        $searchRequest->considerSupplementary = true;
        $searchRequest->studentId = $request->studentId;
        $searchRequest->groupId = $request->groupId;
        $searchRequest->examRegistrationId = $request->examRegistrationId;
        $searchRequest->academicTermId = $request->academicTermId;
        $searchRequest->considerGraceMark = true;
        $searchRequest->supplementaryMonthUpperLimit = $examRegistrationData->examMonth;
        $searchRequest->supplementaryYearUpperLimit = $examRegistrationData->examYear;
        if($examRegistrationData->isFinalSemester){
            $allSemesterDetails = CommonExamService::getInstance()->getAllAcademicTermsDetailsByBatch($searchRequest);
            $allSemesterDetails = array_filter($allSemesterDetails,function($academicTerm)use($examRegistrationData) {
                if($examRegistrationData->academicTermId != $academicTerm->id){
                    return $academicTerm;
                } 
            });
            uasort($allSemesterDetails, function($a, $b) {
                return ($a->orderNo > $b->orderNo);
            });
            $response->allSemesterDetails = $allSemesterDetails;
        }
        $studentsMarkDetails = TabulationRegisterService::getInstance()->getAllRegistredStudentMarkDetailsForTabulationRegister($searchRequest);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $studentsMarkDetails = $this->processStudentDataForTabulationRegister($studentsMarkDetails,$searchRequest,$examRegistrationData);
        $response->studentData = $studentsMarkDetails->studentsDetails;
        foreach($studentsMarkDetails->displaySubjects as $subject){
            $examRegistrationData->totalCredit += (int)$subject->credit; 
        }
        $response->examRegistrationData = $examRegistrationData ;
        usort($studentsMarkDetails->displaySubjects,function($a,$b){
            return $a->priority > $b->priority;
        });
        $response->displaySubjects = array_values($studentsMarkDetails->displaySubjects);
        $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;
        $response->isPrint = $request->isPrint ? true : false;
        return $response;
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderSupplementaryTabulationRegisterResult($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/SupplyTR/Template14/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $columnCount = (count($data->displaySubjects) * 6) + 5;
            $headerHTML = "<!DOCTYPE html>
            <html>
                <body>
                    <table id=\"sem-wise-result-sheet\" style=\"width:100%!important; border:none\">
                    <thead>
                        <tr>
                            <td class=\"removeTdBorder college-head no-border text-center\" style=\"text-align:center\" data-f-bold='true' data-a-h='center' colspan='$columnCount'>
                                <img style = 'width: auto; height: 90px; /* margin: 0 0 0 10%; */' src ='$data->collegeHeader'>
                            </td>
                        </tr>
                        <tr>
                            <td  class=\"removeTdBorder college-head no-border text-center\" style=\"text-align:center;padding-top:10px!important;text-transform: uppercase;\" data-f-bold='true' data-a-h='center' colspan=\"$columnCount\" >
                                <b style=\"font-size: 18px;\">PROVISIONAL TABULATION SHEET (SUPPLEMENTARY) ".$data->examRegistrationData->examMonthName." ".$data->examRegistrationData->examYear." - ".$data->examRegistrationData->degreeName." (SEMESTER ".$data->examRegistrationData->semInSemNumber.") </b>
                            </td>
                        </tr>
                    </thead>
                </table>
                </body>
            </html>";
            $pageNumberPrefix = "PAGE : [page] / [toPage]";
            $totalWidth = (count($data->examRegistrationData->subjects) * 6 * 8) + 100;
            $totalWidth = $totalWidth < 330 ? 330 : $totalWidth + 133;
            $totalHeight = $totalWidth / 1.414;
      
            $options = array(
                'page-width'     => $totalWidth . "mm",
                'page-height'    => $totalHeight . "mm",
                'dpi'            => 96,
                'margin-top' => "40mm",
                'margin-left' => "20mm",
                'margin-right' => "10mm",
                'margin-bottom' => "10mm",
                'footer-right' => $pageNumberPrefix,
                'header-html' => $headerHTML,
                '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->hideExportExcel = true;
            $programResult->enableSelectAllButton = true;
            $programResult->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $programResult;
        }
       
    }
     /**
     * processStudentDataForTabulationRegister
     * @param studentDetails
     * @return studentDetails
     * @author Krishnajith
     */
    public function processStudentDataForTabulationRegister($studentMarkDetails,$request,$examRegistrationDetails = null){
        try{ 
            $response = new \stdClass;
            $displaySubjectArray = [];
            $studentsDetails = [];
            $isCurrentSemester = true;
            foreach($studentMarkDetails as $student){
                $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]->cgpa = $student->cgpa;
                $studentsDetails[$student->id]->grade = $student->grade;
                $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){
                    $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;
                        array_walk($academicTerm->markHistory,function($semMarkHistory) use($studentsDetails,$request,$student,$academicTerm){
                            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->creditGradePoint;
                                $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->markObtained;
                                $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){ 
                            $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]->totalMaxMark = $subject->totalMarks;
                            $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]->excludeSubjectFromTotal = $subject->consolidatedMarkDetails->excludeSubjectFromTotal == '1' ? 1 : 0;
                            $subject->totalMinimum = $subject->consolidatedMarkDetails->aggregatePassPercentage? ($subject->totalMarks *  $subject->consolidatedMarkDetails->aggregatePassPercentage)/100 : 0;
                            $displaySubjectArray[$subject->id] = $subject;
                        }
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = array_sum(array_column($studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects,'creditGradePoint'));
                    }
                }
            }
            $displaySubjectArray = array_values($displaySubjectArray); 
            $response->studentsDetails = $studentsDetails;
            $response->displaySubjects = $displaySubjectArray;
            return $response;
        }
        catch (\Exception $e){
            throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
}