1<?php 2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4require_once 'Services/Table/classes/class.ilTable2GUI.php'; 5require_once 'Services/Tree/classes/class.ilPathGUI.php'; 6require_once 'Services/Link/classes/class.ilLink.php'; 7 8/** 9 * Class ilQuestionUsagesTableGUI 10 * @author Michael Jansen <mjansen@databay.de> 11 */ 12class ilQuestionCumulatedStatisticsTableGUI extends ilTable2GUI 13{ 14 /** 15 * @var assQuestion 16 */ 17 protected $question; 18 19 /** 20 * @param ilUnitConfigurationGUI $controller 21 * @param string $cmd 22 * @param string $template_context 23 * @param assQuestion $question 24 */ 25 public function __construct($controller, $cmd, $template_context, assQuestion $question) 26 { 27 $this->question = $question; 28 $this->setId('qst_usage_' . $question->getId()); 29 parent::__construct($controller, $cmd); 30 31 $this->setRowTemplate('tpl.il_as_qpl_question_cumulated_stats_table_row.html', 'Modules/TestQuestionPool'); 32 $this->setLimit(PHP_INT_MAX); 33 34 $this->setDefaultOrderField('result'); 35 $this->setDefaultOrderDirection('ASC'); 36 37 $this->setTitle($this->lng->txt('question_cumulated_statistics')); 38 $this->setNoEntriesText($this->lng->txt('qpl_assessment_no_assessment_of_questions')); 39 40 $this->disable('sort'); 41 $this->disable('hits'); 42 $this->disable('numinfo'); 43 44 $this->initColumns(); 45 $this->initData(); 46 } 47 48 /** 49 * 50 */ 51 protected function initColumns() 52 { 53 $this->addColumn($this->lng->txt('result'), 'result'); 54 $this->addColumn($this->lng->txt('value'), 'value'); 55 } 56 57 /** 58 * 59 */ 60 protected function initData() 61 { 62 $rows = array(); 63 64 $total_of_answers = $this->question->getTotalAnswers(); 65 66 if ($total_of_answers) { 67 $rows[] = array( 68 'result' => $this->lng->txt('qpl_assessment_total_of_answers'), 69 'value' => $total_of_answers, 70 'is_percent' => false 71 ); 72 73 $rows[] = array( 74 'result' => $this->lng->txt('qpl_assessment_total_of_right_answers'), 75 'value' => assQuestion::_getTotalRightAnswers($this->question->getId()) * 100.0, 76 'is_percent' => true 77 ); 78 } else { 79 $this->disable('header'); 80 } 81 82 $this->setData($rows); 83 } 84 85 /** 86 * @param string $a_field 87 * @return bool 88 */ 89 public function numericOrdering($a_field) 90 { 91 if ('value' == $a_field) { 92 return true; 93 } 94 95 return false; 96 } 97 98 /** 99 * @param array $row 100 */ 101 public function fillRow($row) 102 { 103 $this->tpl->setVariable('VAL_RESULT', $row['result']); 104 $this->tpl->setVariable('VAL_VALUE', $row['is_percent'] ? sprintf("%2.2f", $row['value']) 105 . ' %' : $row['value']); 106 } 107} 108