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 / 156
Template9SupplementaryTabulationRegisterGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
552.00
0.00% covered (danger)
0.00%
0 / 156
 __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
42.00
0.00% covered (danger)
0.00%
0 / 36
 renderSupplementaryTabulationRegisterResult
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 45
 processStudentDataForTabulationRegister
0.00% covered (danger)
0.00%
0 / 1
182.00
0.00% covered (danger)
0.00%
0 / 72
<?php
// Template Supply TR Generator For SJC 
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 Template9SupplementaryTabulationRegisterGenerator extends SupplementaryTabulationRegisterResultDataGenerator{
    public function __construct(){}
    protected function getTemplateName($request){
        $templateName = "template_9";
        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;
        $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;
        
        $response->examRegistrationData = $examRegistrationData ;
        $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/Template9/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $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;padding-top:10px!important;text-transform: uppercase;' data-f-bold='true' data-a-h='center' >
                                <b style='font-size: 18px;'>CONSOLIDATED REPORT - TR " .$data->examRegistrationData->examMonthName . $data->examRegistrationData->examYear." - " .$data->examRegistrationData->groupName ."(SEMESTER " .$data->examRegistrationData->semInSemNumber .") </b>
                            </td>
                        </tr>
                    </thead>
                </table>
                </body>
            </html>";
            
            $totalWidth = 420;
            $totalHeight=297;
            $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-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->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;
                $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]->degree = $student->studentDetails->degree;
                $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->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){ 
                            $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]->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(count($student->academicTerms) > 1){
                    $studentsDetails[$student->id]->overallClass = $student->class;
                    $studentsDetails[$student->id]->overallGrade= $student->grade;
                    $studentsDetails[$student->id]->failedStatus = $student->isFailed;
                }
            }
            $displaySubjectArray = array_values($displaySubjectArray);
            $response->studentsDetails = $studentsDetails;
            return $response;
        }
        catch (\Exception $e){
            throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
}