Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 221 |
RubricsService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
1640.00 | |
0.00% |
0 / 221 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
saveRubrics | |
0.00% |
0 / 1 |
90.00 | |
0.00% |
0 / 55 |
|||
updateRubrics | |
0.00% |
0 / 1 |
90.00 | |
0.00% |
0 / 48 |
|||
deleteRubric | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 39 |
|||
getAllRubricsOfAStaff | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 30 |
|||
getRubricDetailsById | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 39 |
<?php | |
namespace com\linways\core\ams\professional\service\nba; | |
use com\linways\core\ams\professional\dto\nba\Rubrics; | |
use com\linways\core\ams\professional\service\BaseService; | |
use com\linways\core\ams\professional\dto\nba\RubricsPoints; | |
use com\linways\core\ams\professional\dto\nba\RubricsCriterion; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\mapper\nba\RubricsServiceMapper; | |
use com\linways\core\ams\professional\dto\nba\RubricsToAssessmentMapping; | |
use com\linways\core\ams\professional\dto\nba\RubricsPointCriterionDefinition; | |
use com\linways\core\ams\professional\request\nba\GetAllRubricsOfAStaffRequest; | |
class RubricsService 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() | |
{ | |
$this->mapper = RubricsServiceMapper::getInstance()->getMapper(); | |
} | |
// 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; | |
} | |
/** | |
* Service to save a rubric | |
* | |
* @param Rubrics $rubrics | |
* @param RubricsCriterion[] $rubricsCriterionList | |
* @param RubricsPoints[] $rubricsPointsList | |
* @param RubricsPointCriterionDefinition[] $rubricsPointCriterionDefinitionList | |
* @param RubricsToAssessmentMapping $rubricsToAssessmentMapping | |
* @return void | |
*/ | |
public function saveRubrics($rubrics, $rubricsCriterionList, $rubricsPointsList, $rubricsPointCriterionDefinitionList, $rubricsToAssessmentMapping, $createdBy) | |
{ | |
$rubrics = $this->realEscapeObject($rubrics); | |
$rubricsCriterionList = $this->realEscapeArray($rubricsCriterionList); | |
$rubricsPointsList = $this->realEscapeArray($rubricsPointsList); | |
$rubricsPointCriterionDefinitionList = $this->realEscapeArray($rubricsPointCriterionDefinitionList); | |
$rubricsToAssessmentMapping = $this->realEscapeObject($rubricsToAssessmentMapping); | |
$createdBy = $this->realEscapeString($createdBy); | |
$sql = "INSERT INTO `nba_rubrics` (`name`, `description`, `rubric_type`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$rubrics->name', '$rubrics->description', '$rubrics->rubricType', '$createdBy', UTC_TIMESTAMP(), '$createdBy', UTC_TIMESTAMP())"; | |
$rubricsId = null; | |
try { | |
$rubricsId = $this->executeQueryForObject($sql, true); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$criterionOrderToId = []; | |
foreach ($rubricsCriterionList as $criterion) { | |
$sql = ""; | |
$sql = "INSERT INTO `nba_rubrics_criterion` (`name`, `display_order`, `nba_rubrics_id`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$criterion->name', '$criterion->displayOrder', '$rubricsId', '$createdBy', UTC_TIMESTAMP(), '$createdBy', UTC_TIMESTAMP())"; | |
try { | |
$criterionOrderToId[$criterion->displayOrder] = $this->executeQueryForObject($sql, true); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
$pointsOrderToId = []; | |
foreach ($rubricsPointsList as $point) { | |
$sql = ""; | |
$sql = "INSERT INTO `nba_rubrics_points` (`value`, `display_order`, `nba_rubrics_id`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$point->value', '$point->displayOrder', '$rubricsId', '$createdBy', UTC_TIMESTAMP(), '$createdBy', UTC_TIMESTAMP())"; | |
try { | |
$pointsOrderToId[$point->displayOrder] = $this->executeQueryForObject($sql, true); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
$sql = ""; | |
$sql = "INSERT INTO `nba_rubrics_points_criterion_definition` (`description`, `nba_rubrics_id`, `nba_rubrics_criterion_id`, `nba_rubrics_points_id`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES "; | |
$values = []; | |
foreach ($rubricsPointCriterionDefinitionList as $pointCriterion) { | |
$values[] = "('$pointCriterion->description', '$rubricsId', '" . $criterionOrderToId[$pointCriterion->criterionOrder] . "', '" . $pointsOrderToId[$pointCriterion->pointOrder] . "', '$createdBy', UTC_TIMESTAMP(), '$createdBy', UTC_TIMESTAMP())"; | |
} | |
$sql .= implode(',', $values); | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "INSERT INTO `nba_rubrics_to_assessment_mapping` (`nba_rubrics_id`, `subject_id`, `batch_id`, `sem_id`, `staff_id`, `quiz_id`, `assignment_id`, `exam_id`, `universityExams_id`, `labExperiment_id`, `extra_activity_id`) VALUES ('$rubricsId', '$rubricsToAssessmentMapping->subjectId', '$rubricsToAssessmentMapping->batchId', '$rubricsToAssessmentMapping->semId', '$rubricsToAssessmentMapping->staffId', '$rubricsToAssessmentMapping->quizId', '$rubricsToAssessmentMapping->assignmentId', '$rubricsToAssessmentMapping->examId', '$rubricsToAssessmentMapping->universityExamsId', '$rubricsToAssessmentMapping->labExperimentId', '$rubricsToAssessmentMapping->extraActivityId')"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $rubricsId; | |
} | |
public function updateRubrics($rubrics, $rubricsCriterionList, $rubricsPointsList, $rubricsPointCriterionDefinitionList, $rubricsToAssessmentMapping, $updatedBy) | |
{ | |
$rubrics = $this->realEscapeObject($rubrics); | |
$rubricsCriterionList = $this->realEscapeArray($rubricsCriterionList); | |
$rubricsPointsList = $this->realEscapeArray($rubricsPointsList); | |
$rubricsPointCriterionDefinitionList = $this->realEscapeArray($rubricsPointCriterionDefinitionList); | |
$rubricsToAssessmentMapping = $this->realEscapeObject($rubricsToAssessmentMapping); | |
$updatedBy = $this->realEscapeString($updatedBy); | |
$sql = "UPDATE `nba_rubrics` SET `name`='$rubrics->name', `description`='$rubrics->description', `rubric_type`='$rubrics->rubricType', `updated_by`='$updatedBy', `updated_date`= UTC_TIMESTAMP() WHERE `id`='$rubrics->id'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
foreach ($rubricsCriterionList as $criterion) { | |
$sql = ""; | |
$sql = "UPDATE `nba_rubrics_criterion` SET `name`='$criterion->name', `updated_by`='$updatedBy', `updated_date`=UTC_TIMESTAMP() WHERE `id`='$criterion->id'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
foreach ($rubricsPointsList as $point) { | |
$sql = ""; | |
$sql = "UPDATE `nba_rubrics_points` SET `value`='$point->value', `updated_by`='$updatedBy', `updated_date`=UTC_TIMESTAMP() WHERE `id`='$point->id'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
foreach ($rubricsPointCriterionDefinitionList as $pointCriterion) { | |
$sql = ""; | |
$sql = "UPDATE `nba_rubrics_points_criterion_definition` SET `description`='$pointCriterion->description', `updated_by`='$updatedBy', `updated_date`=UTC_TIMESTAMP() WHERE `id`='$pointCriterion->id'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
$sql = ""; | |
$sql = "UPDATE `nba_rubrics_to_assessment_mapping` SET `subject_id`='$rubricsToAssessmentMapping->subjectId', `batch_id`='$rubricsToAssessmentMapping->batchId', `sem_id`='$rubricsToAssessmentMapping->semId', `staff_id`='$rubricsToAssessmentMapping->staffId', `quiz_id`='$rubricsToAssessmentMapping->quizId', `assignment_id`='$rubricsToAssessmentMapping->assignmentId', `exam_id`='$rubricsToAssessmentMapping->examId', `universityExams_id`='$rubricsToAssessmentMapping->universityExamsId', `labExperiment_id`='$rubricsToAssessmentMapping->labExperimentId', `extra_activity_id`='$rubricsToAssessmentMapping->extraActivityId' WHERE `id`='$rubricsToAssessmentMapping->id'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* | |
* | |
* @param [int] $rubricId | |
* @return void | |
*/ | |
public function deleteRubric($rubricId) | |
{ | |
$rubricId = $this->realEscapeString($rubricId); | |
$sql = ""; | |
$sql = "DELETE FROM nba_rubrics_to_assessment_mapping WHERE nba_rubrics_id = '$rubricId'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "DELETE FROM nba_rubrics_points_criterion_definition WHERE nba_rubrics_id = '$rubricId'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "DELETE FROM nba_rubrics_points WHERE nba_rubrics_id = '$rubricId'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "DELETE FROM nba_rubrics_criterion WHERE nba_rubrics_id = '$rubricId'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "DELETE FROM nba_rubrics WHERE id = '$rubricId'"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return true; | |
} | |
/** | |
* | |
* @param GetAllRubricsOfAStaffRequest $request | |
* @return void | |
*/ | |
public function getAllRubricsOfAStaff($request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$responseList = []; | |
$sql = "SELECT | |
r.id, r.name, r.description, r.rubric_type | |
FROM | |
nba_rubrics r | |
INNER JOIN | |
nba_rubrics_to_assessment_mapping rtam ON rtam.nba_rubrics_id = r.id | |
WHERE | |
1 = 1 "; | |
if ($request->subjectId) { | |
$sql .= "AND rtam.subject_id = '$request->subjectId'"; | |
} | |
if ($request->batchId) { | |
$sql .= "AND rtam.batch_id = '$request->batchId'"; | |
} | |
if ($request->semId) { | |
$sql .= "AND rtam.sem_id = '$request->semId'"; | |
} | |
if ($request->staffId) { | |
$sql .= "AND rtam.staff_id = '$request->staffId'"; | |
} | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $responseList; | |
} | |
/** | |
* | |
* | |
* @param [type] $id | |
* @return void | |
*/ | |
public function getRubricDetailsById($id) | |
{ | |
$sql = ""; | |
$sql = "SELECT id, name, description, rubric_type as rubricType FROM nba_rubrics WHERE id ='$id'"; | |
$response = new \stdClass(); | |
try { | |
$response->rubrics = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "SELECT id, name, display_order as displayOrder FROM nba_rubrics_criterion WHERE nba_rubrics_id = '$id'"; | |
try { | |
$response->rubricsCriterionList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "SELECT id, ROUND(value,2) as value, display_order as displayOrder FROM nba_rubrics_points WHERE nba_rubrics_id = '$id'"; | |
try { | |
$response->rubricsPointsList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "SELECT rpcd.id, rpcd.description, rc.display_order as criterionOrder, rp.display_order as pointOrder FROM nba_rubrics_points_criterion_definition rpcd INNER JOIN nba_rubrics_criterion rc ON rpcd.nba_rubrics_criterion_id = rc.id INNER JOIN nba_rubrics_points rp ON rpcd.nba_rubrics_points_id = rp.id WHERE rpcd.nba_rubrics_id = '$id'"; | |
try { | |
$response->rubricsPointCriterionDefinitionList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
$sql = ""; | |
$sql = "SELECT id, subject_id as subjectId, batch_id as batchId, sem_id as semId, staff_id as staffId FROM nba_rubrics_to_assessment_mapping WHERE nba_rubrics_id = '$id'"; | |
try { | |
$response->rubricsToAssessmentMapping = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $response; | |
} | |
} |