Skip to content

Commit

Permalink
Validate Rubric and Mixeval form data
Browse files Browse the repository at this point in the history
Added backend value checking for:
- Rubric lom value selection
- Mixeval likert lom value selection and grade value
  • Loading branch information
andrew-gardener committed Nov 9, 2016
1 parent 1fc3c5f commit f61c986
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions app/controllers/components/evaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,24 @@ function saveRubricEvaluation($targetEvaluatee, $viewMode, $params=null, $target
$this->Rubric->id = $event['Event']['template_id'];
$rubric = $this->Rubric->read();

// validate
$valid_lom_nums = SET::extract($rubric['RubricsLom'], '/lom_num');
if ($viewMode == 0) {
for ($i=1; $i <= $rubric['Rubric']['criteria']; $i++) {
$selectedLom = $params['form']['selected_lom_'.$targetEvaluatee.'_'.$i];
if (!in_array($selectedLom, $valid_lom_nums)) {
return false;
}
}
} elseif ($viewMode == 1) {
$selectedLom = $params['form']['selected_lom_'.$targetEvaluatee.'_'.$targetCriteria];
if (!in_array($selectedLom, $valid_lom_nums)) {
return false;
}
} else {
return false;
}

// Save evaluation data
// total grade for evaluatee from evaluator
$evalRubric = $this->EvaluationRubric->getEvalRubricByGrpEventIdEvaluatorEvaluatee($groupEventId, $evaluator, $targetEvaluatee);
Expand Down Expand Up @@ -951,6 +969,7 @@ function saveMixevalEvaluation($params)
$this->Event = ClassRegistry::init('Event');
$this->Mixeval = ClassRegistry::init('Mixeval');
$this->EvaluationMixeval = ClassRegistry::init('EvaluationMixeval');
$this->MixevalQuestion = ClassRegistry::init('MixevalQuestion');

// assuming all are in the same order and same size
$evaluator = $params['Evaluation']['evaluator_id'];
Expand All @@ -967,6 +986,39 @@ function saveMixevalEvaluation($params)
$this->Mixeval->id = $event['Event']['template_id'];
$mixeval = $this->Mixeval->read();

// validate
$data = $params['EvaluationMixeval'];
$questions = $this->MixevalQuestion->findAllByMixevalId($event['Event']['template_id']);
foreach($questions as $ques) {
$num = $ques['MixevalQuestion']['question_num'];
$multiplier = $ques['MixevalQuestion']['multiplier'];
$zero_mark = $mixeval['Mixeval']['zero_mark'];

if ($ques['MixevalQuestion']['mixeval_question_type_id'] == '1') {
$scale = count($ques['MixevalQuestionDesc']);
if (empty($data[$num]['selected_lom'])) {
continue;
}
$valid_loms = array();
$valid_grades = array();
foreach ($ques['MixevalQuestionDesc'] as $key => $desc) {
$lom = $desc['scale_level'];
if ($lom == 0) {
// upgraded from pre 3.1, scale_levels are set to 0. So use $key as level, scale_level starts from 1
$lom = $key + 1;
}
$valid_loms[]=$lom;
$valid_grades[]=$multiplier * (($lom - $zero_mark) / ($scale - $zero_mark));
}
if (!in_array($data[$num]['selected_lom'], $valid_loms)) {
return false;
}
if (!in_array($data[$num]['grade'], $valid_grades)) {
return false;
}
}
}

$evalMixeval = $this->EvaluationMixeval->getEvalMixevalByGrpEventIdEvaluatorEvaluatee(
$groupEventId, $evaluator, $evaluatee);
if (empty($evalMixeval)) {
Expand Down
2 changes: 1 addition & 1 deletion app/libs/toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static function getRubricEvalDemoData($data)
),
'allDone' => 0,
'comReq' => 0,
'userIds' => array(1,2,3),
'userIds' => "1,2,3",
);
}

Expand Down

0 comments on commit f61c986

Please sign in to comment.