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 / 113
Template9ConsolidatedTabulationRegisterGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
182.00
0.00% covered (danger)
0.00%
0 / 113
 __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
6.00
0.00% covered (danger)
0.00%
0 / 12
 renderConsolidatedTabulationRegisterResult
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 30
 processStudentDataForConsolidatedTabulationRegister
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 68
<?php
// Template Consolidated TR For SJC College
namespace com\linways\ec\core\service\ConsolidatedTabulationRegisterGenerator;
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\ConsolidatedTabulationRegisterGenerator\ConsolidatedTabulationRegisterResultDataGenerator;
use com\linways\core\ams\professional\util\CommonUtil;
class Template9ConsolidatedTabulationRegisterGenerator extends ConsolidatedTabulationRegisterResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_9";
        // $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;
        // if($examRegistrationDetails->courseTypeName == "UG"){
        //     $templateName = "template_9";
        // }
        // else if($examRegistrationDetails->courseTypeName == "PG"){
        //     $templateName = "template_9";
        // }
        // else{
        //     $templateName = "template_9";
        // }
        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->processStudentDataForConsolidatedTabulationRegister($studentsMarkDetails,$request);
        $response->studentData = $studentsMarkDetails->studentsDetails;
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails();
        $response->displayContentOptions = $request->displayContentOptions;
        return $response;
       
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderConsolidatedTabulationRegisterResult($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/ConsolidatedTR/Template9/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $totalWidth = 210;
            $totalHeight = 297;
            $options = array(
                'page-width'     => $totalHeight."mm",
                'page-height'    => $totalWidth."mm",
                'dpi'            => 96,
                'margin-top' => "9mm",
                'margin-left' => "1mm",
                'margin-right' => "1mm",
                '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 = $responseHtml;
            $programResult->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $programResult;
        }
       
    }
     /**
     * processStudentDataForConsolidatedTabulationRegister
     * @param studentDetails
     * @return studentDetails
     * @author Krishnajith
     */
    public function processStudentDataForConsolidatedTabulationRegister($studentMarkDetails,$request){
        try{ 
            $response = new \stdClass;
            $displaySubjectArray = [];
            $displayOtherAcademicTermArray = [];
            $studentsDetails = [];
            foreach($studentMarkDetails as $student){
                $studentsDetails[$student->id]->id = $student->id;
                $studentsDetails[$student->id]->name = $student->studentDetails->name;
                $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
                $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
                $studentsDetails[$student->id]->failedStatus = $student->isFailed;
                $studentsDetails[$student->id]->grade = $student->grade;
                $studentsDetails[$student->id]->roundOff = 2;
                foreach($student->academicTerms as $academicTerm){
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->id = $academicTerm->id;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->orderNo = $academicTerm->academicTermOrderNo;
                    $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;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->failedStatus = $academicTerm->isFailed;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterGrade = $academicTerm->grade;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCredit = $academicTerm->credit;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterCreditGradePoint = $academicTerm->gradePoint;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterSgpa = round($academicTerm->sgpa, $studentsDetails[$student->id]->roundOff);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterTotalMarks = $academicTerm->totalMarks;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtained = $academicTerm->totalMark;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterMarkObtainedInWord = strtoupper(CommonUtil::convertNumberToWords($semMarkHistory->totalMark))." ONLY";
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterPercentage = round($academicTerm->percentage,2);
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->semesterClass = $academicTerm->class;
                    $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->examType = $academicTerm->historyType;
                    foreach( $academicTerm->subjects as $subject){
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->id = $subject->id;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->name = $subject->name;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->code = $subject->code;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMaxMark = $subject->externalMaxMark;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->internalMaxMark = $subject->internalMaxMark;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isInternalFailed = $subject->isInternalFailed;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isInternal = $subject->isInternal;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->isExternal = $subject->isExternal;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->attendanceStatus =  $subject->attendanceStatus;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->externalMark = $subject->externalMark;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->totalMaxMark = $subject->totalMaxMark;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->markObtained = $subject->markObtained;
                        $studentsDetails[$student->id]->academicTerms[$academicTerm->id]->subjects[$subject->id]->gradePoint = $subject->gradePoint;
                    }
                }
            }
            uasort($studentsDetails, function ($a, $b) {
                return $a->regNo > $b->regNo;
            });
            $studentsDetails = array_values($studentsDetails); 
            foreach($studentsDetails as $student){
                uasort($student->academicTerms, function ($a, $b) {
                    return $a->orderNo > $b->orderNo;
                });
                $student->academicTerms = array_values($student->academicTerms); 
                foreach($student->academicTerms as $academicTerm){
                    $academicTerm->subjects = array_values($academicTerm->subjects); 
                }
            }
            $response->studentsDetails = $studentsDetails;
            $response->displaySubjects = $displaySubjectArray;
            $response->displaySemesters = $displayOtherAcademicTermArray;
            return $response;
        }
        catch (\Exception $e){
            throw new ExamControllerException($e->getCode(),$e->getMessage());
        }
    }
}