/** * Analyse completed test * * This function is used to analyse completed test. Scores are calculated for * each unit and subunit, based on the corresponding questions performance. * <br/>Example: * <code> * list($parentScores, $analysisCode) = $completedTest -> analyseTest(); * </code> * The function returns an array with 2 separate elements: The first element is the array * of scores per unit, which is needed in order to display the chart. The second element * is the content tree, where the scores per unit are depicted. * * @return array A results array. * @since 3.5.2 * @access public */ public function analyseTest() { $parentScores = array(); foreach ($this->questions as $question) { $questionIds[$question->question['content_ID']]['score'] += $question->score; $questionIds[$question->question['content_ID']]['total']++; $question->score > 0 ? $questionIds[$question->question['content_ID']]['correct'] += $question->score / 100 : null; } $questionsStats = EfrontStats::getQuestionsUnitStatistics($this->questions); //Get unit names and ids $content = new EfrontContentTree(key($this->getLesson())); if (isset($_GET['entity']) && $_GET['entity']) { $temp = $content->seekNode($_GET['entity']); $tree[0] = new EfrontUnit(array('id' => 0, 'name' => _NOUNIT, 'active' => 1, $temp['id'] => $temp)); //Add a bogus unit to hold questions which do not belong to a unit $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($tree), RecursiveIteratorIterator::SELF_FIRST)); } else { $tree = $content->tree; $tree[0] = new EfrontUnit(array('id' => 0, 'name' => _NOUNIT, 'active' => 1)); //Add a bogus unit to hold questions which do not belong to a unit $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST)); } foreach ($iterator as $key => $value) { if ($key != 0) { foreach ($content->getNodeAncestors($key) as $id => $foo) { $parentScores[$foo['id']]['score'] += $questionIds[$key]['score']; $parentScores[$foo['id']]['total'] += $questionIds[$key]['total']; $parentScores[$foo['id']]['correct'] += $questionIds[$key]['correct']; } $parentScores[$key]['this_score'] += $questionIds[$key]['score']; $parentScores[$key]['this_total'] += $questionIds[$key]['total']; $parentScores[$key]['this_correct'] += $questionIds[$key]['correct']; $parentScores[$key]['name'] = $value['name']; // Check if this chapter is a parent one. if (isset($content->tree[$key])) { $parentScores[$key]['top_level'] = 1; } else { $parentScores[$key]['top_level'] = 0; } } } foreach ($parentScores as $id => $value) { if ($value['total']) { $parentScores[$id]['percentage'] = round($value['score'] / $value['total'], 2); } if ($value['this_total']) { $parentScores[$id]['this_percentage'] = round($value['this_score'] / $value['this_total'], 2); } if ($value['total']) { $options['custom'][$id] = ' <span style = "margin-left:20px;color:gray">' . $parentScores[$id]['percentage'] . '% [' . $value['correct'] . '/' . $value['total'] . ']</span> <img src = "images/16x16/information.png" style = "vertical-align:middle" alt = "" title = "' . _THISLEVEL . ': ' . $parentScores[$id]['this_percentage'] . '% [' . $value['this_correct'] . '/' . $value['this_total'] . ']'; if ($value['total'] - $value['this_total'] > 0) { $options['custom'][$id] .= '/ ' . _BELOWLEVELS . ': ' . round(($value['score'] - $value['this_score']) / ($value['total'] - $value['this_total']), 2) . '% [' . ($value['correct'] - $value['this_correct']) . '/' . ($value['total'] - $value['this_total']) . '] '; } $options['custom'][$id] .= '">'; } else { unset($parentScores[$id]); } } $iterator = new analyseTestFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST)), array_keys($parentScores)); $options['show_hide'] = false; $options['noclick'] = true; //$options['tree_root'] = array('name' => _BACKTOTOP, 'class' => 'examples', 'onclick' => "$('analysis_frame').src = $('analysis_frame').src.replace(/selected_unit=(\d*)/, 'selected_unit='+Element.extend(this).up().id.replace(/node/, ''));"); //$options['onclick'] = "re = new RegExp(this.up().id.replace(/node/, ''), 'g');if(treeObj.getNodeOrders().match(re).length > 1) $('analysis_frame').src = $('analysis_frame').src.replace(/selected_unit=(\d*)/, 'selected_unit='+Element.extend(this).up().id.replace(/node/, ''));"; $options['onclick'] = "showGraph(\$('proto_chart'), 'graph_test_analysis', Element.extend(this).up().id.replace(/node/, ''));"; return array($parentScores, $content->toHTML($iterator, false, $options)); }