ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLPObjectStatisticsDailyTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Tracking/classes/class.ilLPTableBaseGUI.php");
5 
16 {
20  function __construct($a_parent_obj, $a_parent_cmd, array $a_preselect = null, $a_load_items = true)
21  {
22  global $ilCtrl, $lng;
23 
24  $this->preselected = $a_preselect;
25 
26  $this->setId("lpobjstatdlytbl");
27 
28  parent::__construct($a_parent_obj, $a_parent_cmd);
29 
30  $this->setShowRowsSelector(true);
31  // $this->setLimit(ilSearchSettings::getInstance()->getMaxHits());
32  $this->initFilter();
33 
34  $this->addColumn("", "", "1", true);
35  $this->addColumn($lng->txt("trac_title"), "title");
36  $this->addColumn($lng->txt("object_id"), "obj_id");
37  for($loop = 0; $loop<24; $loop+=2)
38  {
39  $this->addColumn(str_pad($loop, 2, "0", STR_PAD_LEFT).":00-<br />".
40  str_pad($loop+2, 2, "0", STR_PAD_LEFT).":00 ", "hour".$loop, "", false, "ilRight");
41  }
42  $this->addColumn($lng->txt("total"), "sum", "", false, "ilRight");
43 
44  $this->setTitle($this->lng->txt("trac_object_stat_daily"));
45 
46  // $this->setSelectAllCheckbox("item_id");
47  $this->addMultiCommand("showDailyGraph", $lng->txt("trac_show_graph"));
48  $this->setResetCommand("resetDailyFilter");
49  $this->setFilterCommand("applyDailyFilter");
50 
51  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
52  $this->setRowTemplate("tpl.lp_object_statistics_daily_row.html", "Services/Tracking");
53  $this->setEnableHeader(true);
54  $this->setEnableNumInfo(true);
55  $this->setEnableTitle(true);
56  $this->setDefaultOrderField("title");
57  $this->setDefaultOrderDirection("asc");
58 
59  $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
60 
61  if($a_load_items)
62  {
63  $this->getItems();
64  }
65  }
66 
67  public function numericOrdering($a_field)
68  {
69  if($a_field != "title")
70  {
71  return true;
72  }
73  return false;
74  }
75 
79  public function initFilter()
80  {
81  global $lng;
82 
83  $this->setDisableFilterHiding(true);
84 
85  // object type selection
86  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
87  $si = new ilSelectInputGUI($lng->txt("obj_type"), "type");
88  $si->setOptions($this->getPossibleTypes(true, false, true));
89  $this->addFilterItem($si);
90  $si->readFromSession();
91  if(!$si->getValue())
92  {
93  $si->setValue("crs");
94  }
95  $this->filter["type"] = $si->getValue();
96 
97  // title/description
98  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
99  $ti = new ilTextInputGUI($lng->txt("trac_title_description"), "query");
100  $ti->setMaxLength(64);
101  $ti->setSize(20);
102  $this->addFilterItem($ti);
103  $ti->readFromSession();
104  $this->filter["query"] = $ti->getValue();
105 
106  // read_count/spent_seconds
107  $si = new ilSelectInputGUI($lng->txt("trac_figure"), "figure");
108  $si->setOptions(array("read_count"=>$lng->txt("trac_read_count"),
109  "spent_seconds"=>$lng->txt("trac_spent_seconds")));
110  $this->addFilterItem($si);
111  $si->readFromSession();
112  if(!$si->getValue())
113  {
114  $si->setValue("read_count");
115  }
116  $this->filter["measure"] = $si->getValue();
117 
118  // year/month
119  $si = new ilSelectInputGUI($lng->txt("year")." / ".$lng->txt("month"), "yearmonth");
120  $si->setOptions($this->getMonthsFilter());
121  $this->addFilterItem($si);
122  $si->readFromSession();
123  if(!$si->getValue())
124  {
125  $si->setValue(date("Y-m"));
126  }
127  $this->filter["yearmonth"] = $si->getValue();
128  }
129 
130  function getItems()
131  {
132  $data = array();
133 
134  $objects = $this->searchObjects(
135  $this->getCurrentFilter(true),
136  "read",
137  null,
138  false
139  );
140  if($objects)
141  {
142  include_once "Services/Tracking/classes/class.ilTrQuery.php";
143 
144  $yearmonth = explode("-", $this->filter["yearmonth"]);
145  if(sizeof($yearmonth) == 1)
146  {
147  $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0]);
148  }
149  else
150  {
151  $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0], (int)$yearmonth[1]);
152  }
153 
154  foreach($stat_objects as $obj_id => $hours)
155  {
156  $data[$obj_id]["obj_id"] = $obj_id;
157  $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
158 
159  foreach($hours as $hour => $values)
160  {
161  // table data
162  $data[$obj_id]["hour".floor($hour/2)*2] += (int)$values[$this->filter["measure"]];
163  $data[$obj_id]["sum"] += (int)$values[$this->filter["measure"]];
164 
165  // graph data
166  $data[$obj_id]["graph"]["hour".$hour] = $values[$this->filter["measure"]];
167  }
168  }
169 
170  // add objects with no usage data
171  foreach($objects as $obj_id => $ref_ids)
172  {
173  if(!isset($data[$obj_id]))
174  {
175  $data[$obj_id]["obj_id"] = $obj_id;
176  $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
177  }
178  }
179  }
180 
181  $this->setData($data);
182  }
183 
187  protected function fillRow($a_set)
188  {
189  global $ilCtrl;
190 
191  $type = ilObject::_lookupType($a_set["obj_id"]);
192 
193  $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
194  $this->tpl->setVariable("ICON_SRC", ilObject::_getIcon("", "tiny", $type));
195  $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
196  $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
197 
198  if($this->preselected && in_array($a_set["obj_id"], $this->preselected))
199  {
200  $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
201  }
202 
203  $this->tpl->setCurrentBlock("hour");
204  for($loop = 0; $loop<24; $loop+=2)
205  {
206  $value = (int)$a_set["hour".$loop];
207  if($this->filter["measure"] != "spent_seconds")
208  {
209  $value = $this->anonymizeValue($value);
210  }
211  else
212  {
213  $value = $this->formatSeconds($value, true);
214  }
215  $this->tpl->setVariable("HOUR_VALUE", $value);
216  $this->tpl->parseCurrentBlock();
217  }
218 
219  if($this->filter["measure"] == "spent_seconds")
220  {
221  $sum = $this->formatSeconds((int)$a_set["sum"], true);
222  }
223  else
224  {
225  $sum = $this->anonymizeValue((int)$a_set["sum"]);
226  }
227  $this->tpl->setVariable("TOTAL", $sum);
228  }
229 
230  function getGraph(array $a_graph_items)
231  {
232  global $lng;
233 
234  include_once "Services/Chart/classes/class.ilChart.php";
235  $chart = ilChart::getInstanceByType(ilChart::TYPE_GRID, "objstdly");
236  $chart->setsize(700, 500);
237 
238  $legend = new ilChartLegend();
239  $chart->setLegend($legend);
240 
241  $max_value = 0;
242  foreach($this->getData() as $object)
243  {
244  if(in_array($object["obj_id"], $a_graph_items))
245  {
246  $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
247  $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
248 
249  for($loop = 0; $loop<24; $loop++)
250  {
251  $value = (int)$object["graph"]["hour".$loop];
252  $max_value = max($max_value, $value);
253  if($this->filter["measure"] != "spent_seconds")
254  {
255  $value = $this->anonymizeValue($value, true);
256  }
257  $series->addPoint($loop, $value);
258  }
259 
260  $chart->addData($series);
261  }
262  }
263 
264  $value_ticks = $this->buildValueScale($max_value, ($this->filter["measure"] != "spent_seconds"),
265  ($this->filter["measure"] == "spent_seconds"));
266 
267  $labels = array();
268  for($loop = 0; $loop<24; $loop++)
269  {
270  $labels[$loop] = str_pad($loop, 2, "0", STR_PAD_LEFT);
271  }
272  $chart->setTicks($labels, $value_ticks, true);
273 
274  return $chart->getHTML();
275  }
276 
277  protected function fillMetaExcel()
278  {
279 
280  }
281 
282  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
283  {
284  $a_worksheet->write($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
285  $a_worksheet->write($a_row, 0, $a_set["obj_id"]);
286 
287  $col = 1;
288  for($loop = 0; $loop<24; $loop+=2)
289  {
290  $value = (int)$a_set["hour".$loop];
291  if($this->filter["measure"] != "spent_seconds")
292  {
293  $value = $this->anonymizeValue($value);
294  }
295 
296  $col++;
297  $a_worksheet->write($a_row, $col, $value);
298  }
299 
300  if($this->filter["measure"] == "spent_seconds")
301  {
302  // keep seconds
303  // $sum = $this->formatSeconds((int)$a_set["sum"]);
304  $sum = (int)$a_set["sum"];
305  }
306  else
307  {
308  $sum = $this->anonymizeValue((int)$a_set["sum"]);
309  }
310  $col++;
311  $a_worksheet->write($a_row, $col, $sum);
312  }
313 
314  protected function fillMetaCSV()
315  {
316 
317  }
318 
319  protected function fillRowCSV($a_csv, $a_set)
320  {
321  $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
322  $a_csv->addColumn($a_set["obj_id"]);
323 
324  for($loop = 0; $loop<24; $loop+=2)
325  {
326  $value = (int)$a_set["hour".$loop];
327  if($this->filter["measure"] != "spent_seconds")
328  {
329  $value = $this->anonymizeValue($value);
330  }
331 
332  $a_csv->addColumn($value);
333  }
334 
335  if($this->filter["measure"] == "spent_seconds")
336  {
337  // keep seconds
338  // $sum = $this->formatSeconds((int)$a_set["sum"]);
339  $sum = (int)$a_set["sum"];
340  }
341  else
342  {
343  $sum = $this->anonymizeValue((int)$a_set["sum"]);
344  }
345  $a_csv->addColumn($sum);
346 
347  $a_csv->addRow();
348  }
349 }
350 
351 ?>
anonymizeValue($a_value, $a_force_number=false)
__construct($a_parent_obj, $a_parent_cmd, array $a_preselect=null, $a_load_items=true)
Constructor.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
This class represents a selection list property in a property form.
Chart legend.
$legend
setEnableNumInfo($a_val)
Set enable num info.
searchObjects(array $filter, $permission, array $preset_obj_ids=null, $a_check_lp_activation=true)
Search objects that match current filters.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
static _lookupTitle($a_id)
lookup object title
getPossibleTypes($a_split_learning_resources=false, $a_include_digilib=false, $a_allow_undefined_lp=false)
Get possible subtypes.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static getObjectDailyStatistics(array $a_ref_ids, $a_year, $a_month=null)
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
TableGUI class for learning progress.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
buildValueScale($a_max_value, $a_anonymize=false, $a_format_seconds=false)
addMultiCommand($a_cmd, $a_text)
Add Command button.
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _lookupType($a_id, $a_reference=false)
lookup object type
const TYPE_GRID
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
getMonthsFilter($a_short=false)
formatSeconds($seconds, $a_shorten_zero=false)
global $lng
Definition: privfeed.php:40
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setEnableHeader($a_enableheader)
Set Enable Header.
getCurrentFilter($as_query=false)
setEnableTitle($a_enabletitle)
Set Enable Title.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
static getInstanceByType($a_type, $a_id)
Get type instance.
setFilterCommand($a_val, $a_caption=null)
Set filter command.