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 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 222
Template3ConsolidatedResultGenerator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
1482.00
0.00% covered (danger)
0.00%
0 / 222
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getTemplateName
0.00% covered (danger)
0.00%
0 / 1
272.00
0.00% covered (danger)
0.00%
0 / 42
 processData
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 renderConsolidatedMarkListResult
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 32
 processStudentData
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 61
 getExamRegistrationDetailsData
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 75
 processStudentSubjectDataForCourseFileTemplate
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
<?php
// Template Consilidated Generator For  SB College
namespace com\linways\ec\core\service\RegularConsolidatedMarkListGenerator;
use com\linways\ec\core\service\StudentMarkListService;
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\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\dto\ExamRegistrationSubject;
use com\linways\ec\core\service\CommonExamService;
use com\linways\ec\core\service\ExamRegistrationBatchService;
use com\linways\ec\core\service\ExamRegistrationSubjectService;
use com\linways\ec\core\service\RegularConsolidatedMarkListGenerator\RegularConsolidatedMarkListResultDataGenerator;
class Template3ConsolidatedResultGenerator extends RegularConsolidatedMarkListResultDataGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $templateName = "template_3_ug";
        $examRegistrationDetails = new \stdClass;
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $examRegistrationDetails->name = $examRegistrationDetailsArray[0]->name;
        $examRegistrationDetails->type = $examRegistrationDetailsArray[0]->type;
        $examRegistrationDetails->groupId = $examRegistrationDetailsArray[0]->groups[0]->groupId;
        $examRegistrationDetails->groupName = $examRegistrationDetailsArray[0]->groups[0]->groupName;
        $examRegistrationDetails->courseTypeID = $examRegistrationDetailsArray[0]->groups[0]->courseTypeID;
        $examRegistrationDetails->courseTypeName = $examRegistrationDetailsArray[0]->groups[0]->courseTypeName;
        $examRegistrationDetails->batchStartYear = $examRegistrationDetailsArray[0]->groups[0]->batchStartYear;
        $examRegistrationDetails->deptID = $examRegistrationDetailsArray[0]->groups[0]->deptID;
        $examRegistrationDetails->deptName = $examRegistrationDetailsArray[0]->groups[0]->deptName;
        $examRegistrationDetails->degreeName = $examRegistrationDetailsArray[0]->groups[0]->degreeName;
        if($examRegistrationDetails->degreeName == "MBA" && $examRegistrationDetails->batchStartYear >= 2019){
            $templateName = "template_3_mba_2019";
        }
        else if($examRegistrationDetails->degreeName == "MBA"){
            $templateName = "template_3_mba";
        }
        else if($examRegistrationDetails->courseTypeName == "PG" && $examRegistrationDetails->batchStartYear >= 2019 || $examRegistrationDetails->degreeName == "LIB" || $examRegistrationDetails->degreeName == "MSW"){
            $templateName = "template_3_pg_2019";
        }
        else if($examRegistrationDetails->degreeName == "LIB" ){
            $templateName = "template_3_mba";
        }
        else if($examRegistrationDetails->courseTypeName == "PG" && $examRegistrationDetails->batchStartYear == 2014){
            $templateName = "template_3_pg_2014";
        }
        else if($examRegistrationDetails->courseTypeName == "PG" ){
            $templateName = "template_3_pg";
        }
        else if($examRegistrationDetails->courseTypeName == "UG" && ($examRegistrationDetails->batchStartYear < 2019 || $examRegistrationDetails->batchStartYear == 2018)){
            $templateName = "template_3_ug_2018";
        }
        else{
            $templateName = "template_3_ug";
        }
        return $templateName;
    }
     /**
     * Process Student data college base
     *
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $studentsMarkDetails = [];
        $studentsMarkDetails = StudentMarkListService::getInstance()->getAllRegistredStudentMarkDetailsDummyData($request);
        if(empty($studentsMarkDetails)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $response->studentData = $this->processStudentData($studentsMarkDetails,$request);
        $response->examRegistrationData = $this->getExamRegistrationDetailsData($request);
        $response->collegeAndOtherData = CommonExamService::getInstance()->getCollegeDetails($request);
        return $response;
       
    }
     /**
     * Render Program Result
     *
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderConsolidatedMarkListResult($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/RegularConsolidatedMarkList/Template3/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "<style>
                h6 {font-size: 26px;} .text-center { text-align: center;} .alignMiddle {vertical-align: middle}; tr.noBorder td {border: 0;  border-collapse:collapse;}
                table, th, td {border: 1px solid black;border-collapse: collapse; vertical-align: middle;} th {font-weight: normal;} .bold {font-weight: bold;}
                </style>";
            $prtContent .= '</head><title>Consolidated MarkList</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $totalWidth = 297;
            $totalHeight = 210;
            $options = array(
                'page-width'     => $totalWidth."mm",
                'page-height'    => $totalHeight."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;
        }
       
    }
    protected function processStudentData($studentsMarkDetails,$request){
        $studentsDetails = [];
        foreach($studentsMarkDetails as $student){
            $studentsDetails[$student->id]->id = $student->id;
            $studentsDetails[$student->id]->name = $student->studentDetails->name;
            $studentsDetails[$student->id]->failedStatus = $student->academicTerms[0]->isFailed;
            $studentsDetails[$student->id]->registerNo = $student->studentDetails->registerNo;
            $studentsDetails[$student->id]->rollNo = $student->studentDetails->rollNo;
            foreach($student->academicTerms[0]->markHistory as $semMarkHistory){
                if($semMarkHistory->examRegistrationId == $request->examRegistrationId){
                    $studentsDetails[$student->id]->examRegistrationWiseFailedStatus = $semMarkHistory->failedStatus;
                    $studentsDetails[$student->id]->failedStatus = $semMarkHistory->failedStatus;
                    $studentsDetails[$student->id]->semesterGrade = $semMarkHistory->grade;
                    $studentsDetails[$student->id]->semesterCreditGradePoint = $semMarkHistory->creditGradePoint;
                    $studentsDetails[$student->id]->roundOff = $student->studentDetails->academicYear < 2019 ?  2 : 3;
                    $studentsDetails[$student->id]->semesterSgpa = round($semMarkHistory->sgpa, $studentsDetails[$student->id]->roundOff);
                    $studentsDetails[$student->id]->semesterMarkObtained = $semMarkHistory->markObtained;
                    $studentsDetails[$student->id]->semesterPercentage = round($semMarkHistory->percentage,2);
                    $studentsDetails[$student->id]->semesterClass = $semMarkHistory->class;
                    $studentsDetails[$student->id]->overallClass =  $semMarkHistory->class;
                    $studentsDetails[$student->id]->overallGrade= $semMarkHistory->grade;
                    if ($semMarkHistory->failedStatus != 'PASSED') {
                        $studentsDetails[$student->id]->semesterSgpa = "-";
                    }
                }
            }
            $studentsDetails[$student->id]->semesterCredit = $student->academicTerms[0]->credit;
            $studentsDetails[$student->id]->semesterTotalMarks = $student->academicTerms[0]->totalMarks;
            foreach($student->academicTerms[0]->subjects as $subject){
                $studentsDetails[$student->id]->subjects[$subject->id]->id = $subject->id;
                $studentsDetails[$student->id]->subjects[$subject->id]->name = $subject->name;
                $studentsDetails[$student->id]->subjects[$subject->id]->code = $subject->code;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMaxMark = $subject->externalMaxMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMaxMark = $subject->internalMaxMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->class = $subject->class;
                $studentsDetails[$student->id]->subjects[$subject->id]->grade = $subject->grade;
                $studentsDetails[$student->id]->subjects[$subject->id]->percentage = round($subject->percentage,2);
                $studentsDetails[$student->id]->subjects[$subject->id]->internalMark = $subject->internalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalMark = $subject->externalMark;
                $studentsDetails[$student->id]->subjects[$subject->id]->totalMarks = $subject->totalMarks;
                $studentsDetails[$student->id]->subjects[$subject->id]->markObtained = $subject->markObtained;
                $studentsDetails[$student->id]->subjects[$subject->id]->failedStatus = $subject->isFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->credit = $subject->credit;
                $studentsDetails[$student->id]->subjects[$subject->id]->wgpa = $subject->wgpa;
                $studentsDetails[$student->id]->subjects[$subject->id]->internalPassPercentage = $subject->internalPassPercentage;
                $studentsDetails[$student->id]->subjects[$subject->id]->externalPassPercentage = $subject->externalPassPercentage;
                $studentsDetails[$student->id]->subjects[$subject->id]->percentageObtainedExternal = $subject->percentageObtainedExternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->percentageObtainedInternal = $subject->percentageObtainedInternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->isExternalFailed = $subject->isExternalFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->isInternalFailed = $subject->isInternalFailed;
                $studentsDetails[$student->id]->subjects[$subject->id]->isInternal = $subject->isInternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->isExternal = $subject->isExternal;
                $studentsDetails[$student->id]->subjects[$subject->id]->categoryId = $subject->categoryId;
                $studentsDetails[$student->id]->subjects[$subject->id]->categoryName = $subject->categoryName;
            }
            
        }
        $studentsDetails = array_values($studentsDetails); 
        foreach($studentsDetails as $student){
            $student->subjects = array_values($student->subjects); 
        }
        return $studentsDetails;
    }
    protected function getExamRegistrationDetailsData($request){
        $examRegistrationDetails = new \stdClass;
        $examRegistrationDetailsArray = ExamRegistrationService::getInstance()->searchDetailedExamRegistrationDetails($request);
        if(empty($examRegistrationDetailsArray)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $examRegistrationDetails->name = $examRegistrationDetailsArray[0]->name;
        $examRegistrationDetails->examYear = $examRegistrationDetailsArray[0]->examYear;
        $examRegistrationDetails->examMonth = $examRegistrationDetailsArray[0]->examMonth;
        $examRegistrationDetails->examMonthName = $examRegistrationDetailsArray[0]->examMonthName;
        $examRegistrationDetails->type = $examRegistrationDetailsArray[0]->type;
        $examRegistrationDetails->groupId = $examRegistrationDetailsArray[0]->groups[0]->groupId;
        $examRegistrationDetails->groupName = $examRegistrationDetailsArray[0]->groups[0]->groupName;
        $examRegistrationDetails->courseTypeID = $examRegistrationDetailsArray[0]->groups[0]->courseTypeID;
        $examRegistrationDetails->courseTypeName = $examRegistrationDetailsArray[0]->groups[0]->courseTypeName;
        $examRegistrationDetails->academicTermName = $examRegistrationDetailsArray[0]->groups[0]->academicTermName;
        $examRegistrationDetails->academicTermYear = $examRegistrationDetailsArray[0]->groups[0]->academicTermYear;
        $examRegistrationDetails->academicTermYearRoman = strtoupper(CommonUtil::convertNumberToRoman($examRegistrationDetails->academicTermYear));
        $examRegistrationDetails->academicTermId = $examRegistrationDetailsArray[0]->groups[0]->academicTermId;
        $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($examRegistrationDetails->academicTermName);
        $examRegistrationDetails->semInRomanLetter = $semesterNames->romanLetter;
        $examRegistrationDetails->semInFullName = $semesterNames->fullName;
        $examRegistrationDetails->semInSemNumber = $semesterNames->semNumber;
        $examRegistrationDetails->batchStartYear = $examRegistrationDetailsArray[0]->groups[0]->batchStartYear;
        $examRegistrationDetails->deptID = $examRegistrationDetailsArray[0]->groups[0]->deptID;
        $examRegistrationDetails->deptName = $examRegistrationDetailsArray[0]->groups[0]->deptName;
        $examRegistrationDetails->degreeName = $examRegistrationDetailsArray[0]->groups[0]->degreeName;
        $subjectGroups = ExamRegistrationSubjectService::getInstance()->getBatchAssignedSubjectGroupsByRequest($request);
        $i = 0;
        $headingArray = [];
        $groupSubsIds = [];
        $groupSubjectCount = "";
        foreach ($examRegistrationDetailsArray[0]->groups[0]->subjects as $subjectId => $subject) {
            $found = 0;
            $subjectId = $subject->id;
            $alreadyGrouped = 0;
            $groupId = "";
            foreach ($subjectGroups as $key => $group) {
                $groupId = $group->id;
                $selectedSubject = reset(array_filter( $group->subjects,function($value)use($subjectId){
                    return $value->id == $subjectId;
                }));
                if ( $selectedSubject->id ) {
                    if (in_array($groupId, $groupSubsIds)) {
                        $alreadyGrouped = 1;
                        break;
                    }
                    $groupSubjectCount++;
                    $headingArray[$i]->isGroup = 1;
                    $headingArray[$i]->id = $group->id;
                    $headingArray[$i]->code = "";
                    $headingArray[$i]->name = $group->subjectGroupName;
                    $headingArray[$i]->groupSubjects = $group->subjects;
                    //unset($subjectGroups[$key]);
                    $found = 1;
                    $groupSubsIds[] = $groupId;
                    break;
                }
            }
            if ($alreadyGrouped == 0) {
                if ($found == 0
                ) {
                    $headingArray[$i]->isGroup = 0;
                    $headingArray[$i]->id = $subject->id;
                    $headingArray[$i]->code = $subject->code;
                    $headingArray[$i]->name = $subject->name;
                    $headingArray[$i]->subjectId = $subjectId;
                }
                $headingArray[$i]->internalMaxMark = $subject->internalMaxMark;
                $headingArray[$i]->externalMaxMark = $subject->externalMaxMark;
                $headingArray[$i]->totalSubjectMark = $subject->totalSubjectMark;
                $headingArray[$i]->credit = $subject->credit;
                $i++;
            }
        }
        // foreach($examRegistrationDetailsArray[0]->groups[0]->subjects as $subject){
        //     $examRegistrationDetails->subjects[$subject->id]->id = $subject->id;
        //     $examRegistrationDetails->subjects[$subject->id]->code = $subject->code;
        //     $examRegistrationDetails->subjects[$subject->id]->name = $subject->name;
        //     $examRegistrationDetails->subjects[$subject->id]->credit = $subject->credit;
        //     $examRegistrationDetails->subjects[$subject->id]->id = $subject->id;
        //     $examRegistrationDetails->subjects[$subject->id]->externalMaxMark = $subject->externalMaxMark;
        //     $examRegistrationDetails->subjects[$subject->id]->internalMaxMark = $subject->internalMaxMark;
        //     $examRegistrationDetails->subjects[$subject->id]->totalSubjectMark = $subject->totalSubjectMark;
        // }
        $examRegistrationDetails->subjects = array_values($headingArray); 
        return $examRegistrationDetails;
    }
    protected function processStudentSubjectDataForCourseFileTemplate($studentsList){
    }
  
   
}