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 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 85
UniversityGradeService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
552.00
0.00% covered (danger)
0.00%
0 / 85
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getAllUniversityGradePointTypes
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getGradesByTypeId
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 14
 processGradesToAnArray
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 6
 processGradesToAnArrayByNameAsIndex
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 6
 getMaxGradeByGradeId
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 15
 getGradeById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getMaxGradePointOfAGradeType
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 18
<?php
namespace com\linways\core\ams\professional\service;
use com\linways\core\ams\professional\exception\ProfessionalException;
class UniversityGradeService extends BaseService
{
    // /Condition 1 - Presence of a static member variable
    private static $_instance = null;
    
    // /Condition 2 - Locked down the constructor
    private function __construct()
    {}
    // Prevent any oustide instantiation of this class
    
    // /Condition 3 - Prevent any object or instance of that class to be cloned
    private function __clone()
    {}
    // Prevent any copy of this object
    
    // /Condition 4 - Have a single globally accessible static method
    public static function getInstance()
    {
        if (! is_object(self::$_instance)) // or if( is_null(self::$_instance) ) or if( self::$_instance == null )
            self::$_instance = new self();
            return self::$_instance;
    }
    /**
     * Undocumented function
     *
     * @return void
     */
    public function getAllUniversityGradePointTypes(){
        $sql = "";
        $sql = "SELECT typeID as id, typeName as name, typeDesc as description, noofGrades as noOfGrades, entryType FROM university_coursetypegrading";
        try{
            $gradeTypes = $this->executeQueryForList($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $gradeTypes;
    }
    /**
     * Undocumented function
     *
     * @param [type] $typeId
     * @return void
     */
    public function getGradesByTypeId($typeId){
        $sql = "";
        $typeId = $this->realEscapeString($typeId);
        if(empty($typeId)){
            return null;
        }
        $gradeList = [];
        $sql = "SELECT gradeID as id, typeID as gradeTypeId, letterGrade as grade, percentFrom, percentTo, gradePoint FROM university_gradepoints where typeID = '$typeId'";
        try{
            $gradeList = $this->executeQueryForList($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $gradeList;
    }
    /**
     * Return grade as array
     *
     * @param [type] $typeId
     * @return void
     */
    public function processGradesToAnArray($gradeList){
        $responseList = [];
        foreach($gradeList as $grade){
            $responseList[$grade->id] = $grade;
        }
        return $responseList;
    }
      /**
     * Return grade as array
     *
     * @param [type] $typeId
     * @return void
     */
    public function processGradesToAnArrayByNameAsIndex($gradeList){
        $responseList = [];
        foreach($gradeList as $grade){
            $responseList[$grade->grade] = $grade;
        }
        return $responseList;
    }
    /**
     * get max grade point
     *
     * @param [type] $gradeId
     * @return void
     */
    public function getMaxGradeByGradeId($gradeId){
        $gradeId = $this->realEscapeString($gradeId);
        try{
            $grade = $this->getGradeById($gradeId);
        }catch(\Exception $e){
            $grade = null;
        }
        if(empty($grade)){
            return null;
        }
        try{
            $maxGradePoint = $this->getMaxGradePointOfAGradeType($grade->gradeTypeId);
        }catch(\Exception $e){
        }
        return $maxGradePoint;
    }
  
    /**
     * Undocumented function
     *
     * @param [type] $gradeId
     * @return void
     */
    public function getGradeById($gradeId){
        $gradeId = $this->realEscapeString($gradeId);
        $sql = "";
        $sql = "SELECT gradeID as id, typeID as gradeTypeId, letterGrade as grade, percentFrom, percentTo, gradePoint FROM university_gradepoints WHERE gradeID = '$gradeId'";
        try{
            $grade = $this->executeQueryForObject($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $grade;
    }
    /**
     * Undocumented function
     *
     * @param [type] $typeId
     * @return void
     */
    public function getMaxGradePointOfAGradeType($typeId){
        $sql = "";
        $grade = null;
        $typeId = $this->realEscapeString($typeId);
        if(empty($typeId)){
            return null;
        }
        $gradeList = [];
        $sql = "SELECT MAX(gradePoint) as gradePoint FROM university_gradepoints WHERE typeID = '$typeId'";
        try{
            $grade = $this->executeQueryForObject($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        if(!empty($grade)){
            return $grade->gradePoint;
        }
        return null;
    }
    
  
}