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 / 46
SpecialGradesAwardedService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
156.00
0.00% covered (danger)
0.00%
0 / 46
 __construct
n/a
0 / 0
1
n/a
0 / 0
 __clone
n/a
0 / 0
1
n/a
0 / 0
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getSpecialGradeAwardedActivities
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 assignSpecialGradesAwardedToStudents
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 23
 getSpecialGradesAwardedToStudents
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
<?php
    namespace com\linways\core\ams\professional\service;
    use com\linways\core\ams\professional\exception\ProfessionalException;
    class SpecialGradesAwardedService extends BaseService
    {
        // /Condition 1 - Presence of a static member variable
        private static $_instance = null;
        private $mapper = [];
        // /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;
        }
        public function getSpecialGradeAwardedActivities ( ) {
            $activities = [];
            $sql = "SELECT id, activity FROM special_grades_awarded_activities";
            try {
                $activities = $this->executeQueryForList($sql);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $activities;
        }
        
        public function assignSpecialGradesAwardedToStudents ( $specialGradesAwards ) {
            $values = [];
            $specialGradesAwards = $this->realEscapeArray($specialGradesAwards);
            if ( !empty ( $specialGradesAwards ) ) {
                $batchId = $specialGradesAwards["batchId"];
                $semId = $specialGradesAwards["semId"];
                $createdBy = $specialGradesAwards["createdBy"];
                $sql = "INSERT INTO special_grades_awarded_students ( studentId, batchId, semId, activityId, gradeAwarded, createdBy) VALUES ";
                foreach ($specialGradesAwards["activityGrades"] as $specialGrade ) {
                    $specialGrade = (object) $specialGrade;
                    $values[] = "$specialGrade->studentId$batchId$semId$specialGrade->activityId, '$specialGrade->gradeAwarded', $createdBy )";
                }
                $sql .= implode ( ", ", $values ) . " ON DUPLICATE KEY UPDATE gradeAwarded = VALUES(gradeAwarded), updatedBy = VALUES(createdBy) ";
                try {
                    $this->executeQuery($sql);
                } catch (\Exception $e) {
                    throw new ProfessionalException($e->getCode(), $e->getMessage());
                }
                return true;
            }
            else {
                throw new ProfessionalException(ProfessionalException::INSUFFICIENT_PARAMETERS, "Please assign special grades to students");
            }
        }
        public function getSpecialGradesAwardedToStudents ( $studentId ) {
            $gradeAwarded = [];
            $sql = "SELECT sgas.studentId, sgas.activityId, sgaa.activity, sgas.gradeAwarded FROM special_grades_awarded_students sgas INNER JOIN special_grades_awarded_activities sgaa ON (sgas.activityId = sgaa.id) WHERE studentId = '$studentId";
            try {
                $gradeAwarded = $this->executeQueryForList($sql);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $gradeAwarded;
        }
    }
?>