ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.SurveyMetricQuestionEvaluation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Modules/SurveyQuestionPool/classes/class.SurveyQuestionEvaluation.php";
5 
13 {
14  //
15  // RESULTS
16  //
17 
18  protected function parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories = null)
19  {
20  parent::parseResults($a_results, $a_answers);
21 
22  // add arithmetic mean
23  $total = $sum = 0;
24  foreach($a_answers as $answers)
25  {
26  foreach($answers as $answer)
27  {
28  $total++;
29  $sum += $answer["value"];
30  }
31  }
32  if($total > 0)
33  {
34  $a_results->setMean($sum/$total);
35  }
36  }
37 
38 
39  //
40  // DETAILS
41  //
42 
43  public function getGrid($a_results, $a_abs = true, $a_perc = true)
44  {
45  global $lng;
46 
47  if((bool)$a_abs && (bool)$a_perc)
48  {
49  $cols = array(
50  $lng->txt("category_nr_selected"),
51  $lng->txt("svy_fraction_of_selections")
52  );
53  }
54  else if((bool)$a_abs)
55  {
56  $cols = array(
57  $lng->txt("category_nr_selected")
58  );
59  }
60  else
61  {
62  $cols = array(
63  $lng->txt("svy_fraction_of_selections")
64  );
65  }
66 
67  $res = array(
68  "cols" => $cols,
69  "rows" => array()
70  );
71 
72  // as we have no variables build rows from answers directly
73  $total = sizeof($a_results->getAnswers());
74  if($total > 0)
75  {
76  $cumulated = array();
77  foreach($a_results->getAnswers() as $answer)
78  {
79  $cumulated[$answer->value]++;
80  }
81  foreach($cumulated as $value => $count)
82  {
83  $perc = sprintf("%.2f", $count/$total*100)."%";
84  if((bool)$a_abs && (bool)$a_perc)
85  {
86  $res["rows"][] = array(
87  $value,
88  $count,
89  $perc
90  );
91  }
92  else if((bool)$a_abs)
93  {
94  $res["rows"][] = array(
95  $value,
96  $count
97  );
98  }
99  else
100  {
101  $res["rows"][] = array(
102  $value,
103  $perc
104  );
105  }
106  }
107  }
108 
109  return $res;
110  }
111 
112  public function getChart($a_results)
113  {
114  global $lng;
115 
116  include_once "Services/Chart/classes/class.ilChart.php";
117  $chart = ilChart::getInstanceByType(ilChart::TYPE_GRID, $a_results->getQuestion()->getId());
118  $chart->setYAxisToInteger(true);
119 
120  $colors = $this->getChartColors();
121  $chart->setColors($colors);
122 
123  // :TODO:
124  $chart->setsize($this->chart_width, $this->chart_height);
125 
126  $data = $chart->getDataInstance(ilChartGrid::DATA_BARS);
127  $data->setLabel($lng->txt("category_nr_selected"));
128  $data->setBarOptions(0.5, "center");
129  $data->setFill(1);
130 
131  $total = sizeof($a_results->getAnswers());
132  if($total > 0)
133  {
134  $cumulated = array();
135  foreach($a_results->getAnswers() as $answer)
136  {
137  $cumulated[$answer->value]++;
138  }
139 
140  $labels = array();
141  foreach($cumulated as $value => $count)
142  {
143  $data->addPoint($value, $count);
144  $labels[$value] = $value;
145  }
146  $chart->addData($data);
147 
148  $chart->setTicks($labels, false, true);
149 
150  return $chart->getHTML();
151  }
152  }
153 
154 
155  //
156  // EXPORT
157  //
158 
165  public function getExportGrid($a_results)
166  {
167  global $lng;
168 
169  $res = array(
170  "cols" => array(
171  $lng->txt("value"),
172  $lng->txt("category_nr_selected"),
173  $lng->txt("svy_fraction_of_selections")
174  ),
175  "rows" => array()
176  );
177 
178  // as we have no variables build rows from answers directly
179  $total = sizeof($a_results->getAnswers());
180  if($total > 0)
181  {
182  $cumulated = array();
183  foreach($a_results->getAnswers() as $answer)
184  {
185  $cumulated[$answer->value]++;
186  }
187  foreach($cumulated as $value => $count)
188  {
189  $res["rows"][] = array(
190  $value,
191  $count,
192  sprintf("%.2f", $count/$total*100)."%"
193  );
194  }
195  }
196 
197  return $res;
198  }
199 
200  public function addUserSpecificResults(array &$a_row, $a_user_id, $a_results)
201  {
202  $answer = $a_results->getUserResults($a_user_id);
203  if($answer === null)
204  {
205  $a_row[] = $this->getSkippedValue();
206  }
207  else
208  {
209  $a_row[] = $answer[0][0];
210  }
211  }
212 }
$total
Definition: Utf8Test.php:87
Class SurveyCategories.
addUserSpecificResults(array &$a_row, $a_user_id, $a_results)
Create styles array
The data for the language used.
const TYPE_GRID
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories=null)
getSkippedValue()
Get caption for skipped value.
global $lng
Definition: privfeed.php:17
getGrid($a_results, $a_abs=true, $a_perc=true)
static getInstanceByType($a_type, $a_id)
Get type instance.