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 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 310
Template6PC
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
6320.00
0.00% covered (danger)
0.00%
0 / 310
 __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 / 21
 processData
0.00% covered (danger)
0.00%
0 / 1
4556.00
0.00% covered (danger)
0.00%
0 / 225
 renderTemplate
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 30
 getCustomFieldObjectList
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 18
 getDataType
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 16
<?php
// SAINTGITS
namespace com\linways\ec\core\service\ProvisionalMarksCardGenerator;
use com\linways\base\util\TwigRenderer;
use com\linways\ec\core\service\MarksCardService;
use com\linways\ec\core\service\CommonExamService;
use com\linways\core\ams\professional\util\PdfUtil;
use com\linways\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\exception\ExamControllerException;
use com\linways\ec\core\service\FinalConsolidatedReportService;
use com\linways\ec\core\service\ProvisionalMarksCardGenerator\PCGenerator;
use com\linways\core\ams\professional\service\StudentService;
use com\linways\core\ams\professional\constant\examcontroller\CourseTypeConstants;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\ec\core\service\ExamRegistrationService;
class Template6PC extends PCGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $query = "SELECT
            ct.course_Type AS courseType,
            g.properties->>'$.startYear' AS batchStartYear
        FROM
            `groups` g
        INNER JOIN program p ON 
            p.id = CAST(g.properties->>'$.programId' AS CHAR)
        INNER JOIN course_type ct ON
            ct.courseTypeID = p.course_type_id
        WHERE g.id IN ('$request->groupId')";
        $courseDetails = $this->executeQueryForObject($query);
        $courseType = $courseDetails->courseType;
        $batchStartYear = $courseDetails->batchStartYear;
        if ($courseType == "UG") {
            $templateName = "Template6PC_BTECH";
        }
        else{
            $templateName = 'Template6PC';
        }
        return $templateName;
    }
     /**
     * Process Student data college base
     * @param $request
     */
    protected function processData($request){
        $response = new \stdClass;
        $additionalInfo = new \stdClass();
        $studentMinorSyllabusDetails = [];
        $requestForSpecialExam = new \stdClass;
        $requestForSpecialExam->isSpecialExamRegistration = true;
        $requestForSpecialExam->groupId = $request->groupId;
        $allSupplementaryExamRegistrations = (array) ExamRegistrationService::getInstance()->searchExamRegistrationByOtherDetails($requestForSpecialExam);
        $allSupplementaryExamRegistrationIds = array_column($allSupplementaryExamRegistrations,'id');
        // get all students credit points
        // $requestForActivityPoints = new \stdClass;
        // $requestForActivityPoints->groupId = $request->groupId;
        // $requestForActivityPoints->studentId = $request->studentId;
        // $studentActivityPoints = CommonExamService::getInstance()->getStudentsActivityPoints($requestForActivityPoints);
        $response = new \stdClass;
        $searchRequest = new \stdClass;
        $request->excludeMinorHonor = 1;
        $response->studentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        uasort($response->studentData, function ($a, $b) {
            return $a->regNo > $b->regNo;
        });
        // to fetch Mionor Subject Details
        $request->excludeMinorHonor = false;
        $request->consoiderHonoursSubjects = false;
        $request->consoiderMinorSubjects = 1;
        $response->minorStudentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        // to fetch Honour Subject Details
        $request->excludeMinorHonor = false;
        $request->consoiderMinorSubjects = false;
        $request->consoiderHonoursSubjects = 1;
        $response->honoursStudentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        $additionalInfo->showHonoursMarksCard = $request->filterSettings['showHonoursMarksCard'] ? true : false;
        $additionalInfo->showMinorMarksCard = $request->filterSettings['showMinorMarksCard'] ? true : false;
        foreach ($response->studentData as $studentId => $student){
            if($student->failedStatus == 'FAILED'){
                unset($response->studentData[$studentId]);
            }
            $student->minorSubjects = [];
            $student->honoursSubjects = [];
            $student->isPassAllMinorSubjects = true;
            $student->studentMinorCredits = 0;
            $student->studentHonoursCredits = 0;
            $minorDetails = $response->minorStudentData[$studentId];
            $student->isPassAllHonourSubjects = true;
            $honoursDetails = $response->honoursStudentData[$studentId];
            $student->minorHonoursAcademicPaperSubjectIds = [];
            $student->syllabusName = "";
            $student->syllabusDescription = "";
            // check conditions for eligible minor certificate and eligible minor subjects
            // if the certificate is verified then that subject become passed (Grade P )in case of MOOC subject 
            foreach ($minorDetails->academicTerms as $minorTermId) {
                foreach ($minorTermId->subjects as $minorSubject) {
                    if($minorSubject->isMoocSubject == '1'){
                        if($minorSubject->moocVerificationStatus == 'APPROVED'){
                            $minorSubject->examMonthYearFormat2 = date('M Y',strtotime($minorSubject->markDetails->latestExamYear."-".$minorSubject->markDetails->latestExamMonth."-01"));
                            $minorSubject->credit = $minorSubject->markDetails->credit;
                            $student->studentMinorCredits =  $student->studentMinorCredits + (float)$minorSubject->credit;
                            $minorSubject->isMooc = $minorSubject->isMoocSubject == '1' ? 1 : 0; 
                            $minorSubject->grade = "P";
                            $minorSubject->failedStatus = "PASSED";
                            $student->minorSubjects[] = $minorSubject;
                        }
                        else{
                            $student->isPassAllMinorSubjects = false;
                        }
                    }
                    else{
                        if($minorSubject->failedStatus == 'FAILED'){
                            $student->isPassAllMinorSubjects = false;
                        }
                        else{
                            $student->minorHonoursAcademicPaperSubjectIds[] = $minorSubject->paperSubjetId;
                            $minorSubject->examMonthYearFormat2 = date('M Y',strtotime($minorSubject->markDetails->latestExamYear."-".$minorSubject->markDetails->latestExamMonth."-01"));
                            $minorSubject->credit = $minorSubject->markDetails->credit;
                            $student->studentMinorCredits =  $student->studentMinorCredits + (float)$minorSubject->credit;
                            $student->minorSubjects[] = $minorSubject;
                        }
                    }
                    // fetch minor syllabus name by cluster
                    if(empty($student->syllabusName)){
                        $student->syllabusName = $minorSubject->academicSyllabusName;
                        $student->syllabusDescription = !empty($minorSubject->syllabusDescription) ? $minorSubject->syllabusDescription : $minorSubject->academicSyllabusName;
                    }
                }
            }
            if(!empty($student->minorHonoursAcademicPaperSubjectIds)){
                $studentMinorSyllabusDetailsReq = new \stdClass();
                $studentMinorSyllabusDetailsReq->studentId = $student->studentId;
                $studentMinorSyllabusDetailsReq->academicPaperSubjectId = $student->minorHonoursAcademicPaperSubjectIds;
                $studentMinorSyllabusDetails[$student->studentId] = MarksCardService::getInstance()->getMinorSyllabusDetailsByStudent($studentMinorSyllabusDetailsReq);
            }
            // check conditions for eligible honours certificate and eligible honours subjects
            // check all subject having gradepont greate than or egual to 6.5 then will be pass otherwise failed 
            // if the certificate is verified then that subject become passed (Grade P ) in case of MOOC subject 
            // 6.5 -> grade pont of C grade (as per college rule) 
            foreach ($honoursDetails->academicTerms as $honoursTermId) {
                foreach ($honoursTermId->subjects as $honoursSubject) {
                    if($honoursSubject->isMoocSubject == '1'){
                        if($honoursSubject->moocVerificationStatus == 'APPROVED'){
                            $honoursSubject->examMonthYearFormat2 = date('M Y',strtotime($honoursSubject->markDetails->latestExamYear."-".$honoursSubject->markDetails->latestExamMonth."-01"));
                            $honoursSubject->credit = $honoursSubject->markDetails->credit;
                            $student->studentHonoursCredits =  $student->studentHonoursCredits + (float)$honoursSubject->credit;
                            $honoursSubject->isMooc = $honoursSubject->isMoocSubject == '1' ? 1 : 0; 
                            $honoursSubject->grade = "P";
                            $honoursSubject->failedStatus = "PASSED";
                            $student->honoursSubjects[] = $honoursSubject;
                        }
                        else{
                            $student->isPassAllHonourSubjects = false;
                        }
                    }
                    else{
                        if((float)$honoursSubject->markDetails->gradePoint >= 6.5){
                            $honoursSubject->examMonthYearFormat2 = date('M Y',strtotime($honoursSubject->markDetails->latestExamYear."-".$honoursSubject->markDetails->latestExamMonth."-01"));
                            $honoursSubject->credit = $honoursSubject->markDetails->credit;
                            $student->studentHonoursCredits =  $student->studentHonoursCredits + (float)$honoursSubject->credit;
                            $honoursSubject->isMooc = $honoursSubject->isMoocSubject == '1' ? 1 : 0; 
                            $student->honoursSubjects[] = $honoursSubject;
                        }
                        else{
                            $student->isPassAllHonourSubjects = false;
                        }
                    }
                }
            }
            if( $student->isPassAllMinorSubjects){
                if(empty($student->minorSubjects)){
                    $student->isPassAllMinorSubjects = false;
                }
                elseif($student->studentMinorCredits < 20){
                    $student->isPassAllMinorSubjects = false;
                }
            }
        }
        $courseType = reset($response->studentData)->courseType;
        $batchStartYear = reset($response->studentData)->admissionYear;
        foreach ($response->studentData as $studentId => $student){
            // if student register by sem term then update the minor syllabus name
            if(!empty($studentMinorSyllabusDetails[$student->studentId])){
                $student->syllabusName = $studentMinorSyllabusDetails[$student->studentId]->syllabusName;
                $student->syllabusDescription = !empty($studentMinorSyllabusDetails[$student->studentId]->syllabusDescription) ? $studentMinorSyllabusDetails[$student->studentId]->syllabusDescription : $student->syllabusName;
            }
            $student->showDegreeClassification = true;
            $batchDetails = json_decode($student->properties);
            $student->finalSem = $batchDetails->finalTermId;
            $finalSem = $batchDetails->finalTermId;
            // this case to check if student attempt supply after last semester regular exam then not eligible minor
            $student->lastAcademicTerm = reset(array_filter( $student->academicTerms ,function($value)use($finalSem){
                return $value->termId == $finalSem;
            }));
            $student->finalTermRegularExamHistory = reset(array_filter($student->lastAcademicTerm->markHistory,function($value){
                return $value->historyType == 'REGULAR';
            }));
            $student->finalTermRegularExamMonthYear = !empty($student->finalTermRegularExamHistory ) ? date('Y-m',strtotime($student->finalTermRegularExamHistory->examYear."-". $student->finalTermRegularExamHistory->examMonth."-01")) : NULL;
            $student->latestExamMonthYear = $student->markDetails->latestExamMonth ?  date("Y-m", strtotime($student->markDetails->latestExamYear."-".$student->markDetails->latestExamMonth."-01")) : NULL;
            $latestExamMonth = $student->markDetails->latestExamMonth;
            $latestExamYear = $student->markDetails->latestExamYear;
            $student->lastMonthYear = strtoupper(date("F - Y",strtotime("$latestExamYear-$latestExamMonth-1")));
            $student->roundOff = 2;
            $student->percentageValue = $student->admissionYear >= 2019 ?  20 : 25;
            $student->cgpa = sprintf('%0.2f',round($student->markDetails->rawCgpa, $student->roundOff));
            $student->class = $student->markDetails->class;
            $student->cgpaInWords = CommonUtil::convertNumberToWords($student->cgpa);
            $student->creditInWords = CommonUtil::convertNumberToWords($student->markDetails->credit);
            $student->genderTag = (strtoupper($student->gender) == "MALE") ? "Mr" : "Ms";
            $customFields = AmsCustomFieldsService::getInstance()->getAmsCustomFieldValue(AmsCustomFieldsEntities::STUDENT, $studentId, []);
            if( $customFields ){
                $student->ktuCode = $this->getCustomFieldObjectList($customFields)->studentData->KTU_CODE;
            }
            $student->qrData = $student->regNo ." | ".$student->name . " | CGPA - " .$student->cgpa;
            if($student->cgpa < 6.50){
                $student->showDegreeClassification = false;
            }
            if( $student->isPassAllMinorSubjects){
                // ---------------- Check Minor Passing Criteria --------------------
                // 1. if student attempt supply after last semester regular exam then not eligible minor
                if(!empty($student->finalTermRegularExamMonthYear) && !empty($student->latestExamMonthYear)){
                    if($student->finalTermRegularExamMonthYear < $student->latestExamMonthYear){
                        $student->isPassAllMinorSubjects = false;
                    }
                }
            }
            if( $student->isPassAllHonourSubjects){
                // ---------------- Check Honour Passing Criteria --------------------
                // 1.Currently Pass OverAll Subject And get cgpa >= 8.5
                // 2.Pass All Subjects in honurs with credit atleast 20
                // 3.No backlogs (Supply) not consider backlog as special and revaluation
                if(empty($student->honoursSubjects)){
                    $student->isPassAllHonourSubjects = false;
                }
                elseif($student->studentHonoursCredits < 20){
                    $student->isPassAllHonourSubjects = false;
                }
                else if($student->failedStatus == 'FAILED' || ($student->cgpa < 8.5)){
                    $student->isPassAllHonourSubjects = false;
                }
                else{
                    foreach ($student->academicTerms as $term) {
                        foreach ($term->subjects as $subject) {
                            if(count($subject->markHistory) >= 2 && !empty($allSupplementaryExamRegistrationIds)){
                                $specialExamSubject = reset(array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                    return in_array($value->examRegistrationId, $allSupplementaryExamRegistrationIds);
                                }));
                                $revaluationExamHistory = reset(array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                    return $value->examMarkType == 'REVALUATION';
                                }));
                                if(!empty($specialExamSubject)){
                                    $subject->markHistory = array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                        return $value->examMarkType != 'REGULAR';
                                    });
                                }
                                if(!empty($revaluationExamHistory)){
                                    $subject->markHistory = array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                        return $value->examMarkType != 'REGULAR';
                                    });
                                }
                                if (count($subject->markHistory) >= 2) {
                                    $student->isPassAllHonourSubjects = false;
                                    break;
                                } 
                            }
                        }
                    }
                }
            }
            if ( $request->filterSettings['showMinorMarksCard'] && $request->filterSettings['showHonoursMarksCard']){
                if(empty($student->minorSubjects) || empty($student->honoursSubjects) || !$student->isPassAllHonourSubjects || !$student->isPassAllMinorSubjects){
                    unset($response->studentData[$studentId]);
                }
            }
            else if ( $request->filterSettings['showMinorMarksCard'] ){
                if( empty($student->minorSubjects)  || !$student->isPassAllMinorSubjects || !empty($student->honoursSubjects)){
                    unset($response->studentData[$studentId]);
                }
            }
            else if ( $request->filterSettings['showHonoursMarksCard'] ){
                if( empty($student->honoursSubjects) || !$student->isPassAllHonourSubjects || !empty($student->minorSubjects)){
                    unset($response->studentData[$studentId]);
                }
            }
        }
        if( empty( $response->studentData ) ){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        uasort($response->studentData, function ($a, $b) {
            return $a->regNo > $b->regNo;
        });
        $additionalInfo->currentDate = date("d.m.Y");
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails();
        $additionalInfo->currentDate = $request->filterSettings['markListDate']? date("d<\s\up>S</\s\up> F Y",strtotime($request->filterSettings['markListDate'])) : date("d<\s\up>S</\s\up> F Y");
        // $additionalInfo->currentDate = str_replace('th', '<sup>th</sup>',  $additionalInfo->currentDate);
        if($courseType == CourseTypeConstants::MTECH || $courseType == CourseTypeConstants::UG){
            $additionalInfo->showSpecialization = true;
        }
        $response->additionalInfo = $additionalInfo;
        return $response;
    }
     /**
     * Render Program Result
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderTemplate($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/ProvisionalMarksCard/Template6/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "<style>
                
                </style>";
            $prtContent .= '</head><title>Consolidated Marks Card</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            $totalWidth = 210;
            $totalHeight = 297;
            $options = array(
                'page-width'     => $totalWidth."mm",
                'page-height'    => $totalHeight."mm",
                'dpi'            => 96,
                'margin-top' => "7.5mm",
                'margin-left' => "7.5mm",
                'margin-right' => "7.5mm",
                'margin-bottom' => "7.5mm",
                // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac
                'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css")
            );
            $finalCMC = new \stdClass;
            $finalCMC->htmlData = $responseHtml;
            $finalCMC->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $finalCMC;
        }
       
    }
    protected function getCustomFieldObjectList($customFields)
    {
        $fieldList = [];
        $response = new \stdClass();
        $studentData = new \stdClass();
        $orderNo = 1;
        foreach ($customFields as $customField) {
            $field = json_decode('{"columnName":"","displayName":"","fieldType":"","format":"","orderNo":0,"validation":"text","editable":true,"required":false,"relatedFieldList":[],"relatedFieldSeperator":"","foreignkeyTableDetails":{},"tableType":"CUSTOM"}');
            $field->columnName = $customField->code;
            $field->displayName = $customField->label;
            $field->fieldType = getDataType($customField->dataType);
            $field->orderNo = $orderNo++;
            $studentData->{$customField->code} = $customField->value;
            $fieldList[] = $field;
        }
        $response->fieldList = $fieldList;
        $response->studentData = $studentData;
        return $response;
    }
    protected function getDataType($dataType)
    {
        switch($dataType)
        {
            case "longtext":
                return "textarea";
                break;
            case "varchar":
                return "text";
            break;
            case "integer":
                return "text";
            case "textarea":
                return "text";
            break;
            // default:
            //     return "select";
    
        }
    }
}