ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4include_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($this->getCurrentFilter(true), "read");
135 if($objects)
136 {
137 include_once "Services/Tracking/classes/class.ilTrQuery.php";
138
139 $yearmonth = explode("-", $this->filter["yearmonth"]);
140 if(sizeof($yearmonth) == 1)
141 {
142 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0]);
143 }
144 else
145 {
146 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0], (int)$yearmonth[1]);
147 }
148
149 foreach($stat_objects as $obj_id => $hours)
150 {
151 $data[$obj_id]["obj_id"] = $obj_id;
152 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
153
154 foreach($hours as $hour => $values)
155 {
156 // table data
157 $data[$obj_id]["hour".floor($hour/2)*2] += (int)$values[$this->filter["measure"]];
158 $data[$obj_id]["sum"] += (int)$values[$this->filter["measure"]];
159
160 // graph data
161 $data[$obj_id]["graph"]["hour".$hour] = $values[$this->filter["measure"]];
162 }
163 }
164
165 // add objects with no usage data
166 foreach($objects as $obj_id => $ref_ids)
167 {
168 if(!isset($data[$obj_id]))
169 {
170 $data[$obj_id]["obj_id"] = $obj_id;
171 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
172 }
173 }
174 }
175
176 $this->setData($data);
177 }
178
182 protected function fillRow($a_set)
183 {
184 global $ilCtrl;
185
186 $type = ilObject::_lookupType($a_set["obj_id"]);
187
188 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
189 $this->tpl->setVariable("ICON_SRC", ilObject::_getIcon("", "tiny", $type));
190 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
191 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
192
193 if($this->preselected && in_array($a_set["obj_id"], $this->preselected))
194 {
195 $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
196 }
197
198 $this->tpl->setCurrentBlock("hour");
199 for($loop = 0; $loop<24; $loop+=2)
200 {
201 $value = (int)$a_set["hour".$loop];
202 if($this->filter["measure"] != "spent_seconds")
203 {
204 $value = $this->anonymizeValue($value);
205 }
206 else
207 {
208 $value = $this->formatSeconds($value, true);
209 }
210 $this->tpl->setVariable("HOUR_VALUE", $value);
211 $this->tpl->parseCurrentBlock();
212 }
213
214 if($this->filter["measure"] == "spent_seconds")
215 {
216 $sum = $this->formatSeconds((int)$a_set["sum"], true);
217 }
218 else
219 {
220 $sum = $this->anonymizeValue((int)$a_set["sum"]);
221 }
222 $this->tpl->setVariable("TOTAL", $sum);
223 }
224
225 function getGraph(array $a_graph_items)
226 {
227 global $lng;
228
229 include_once "Services/Chart/classes/class.ilChart.php";
231 $chart->setsize(700, 500);
232
233 $legend = new ilChartLegend();
234 $chart->setLegend($legend);
235
236 $max_value = 0;
237 foreach($this->getData() as $object)
238 {
239 if(in_array($object["obj_id"], $a_graph_items))
240 {
241 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
242 $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
243
244 for($loop = 0; $loop<24; $loop++)
245 {
246 $value = (int)$object["graph"]["hour".$loop];
247 $max_value = max($max_value, $value);
248 if($this->filter["measure"] != "spent_seconds")
249 {
250 $value = $this->anonymizeValue($value, true);
251 }
252 $series->addPoint($loop, $value);
253 }
254
255 $chart->addData($series);
256 }
257 }
258
259 $value_ticks = $this->buildValueScale($max_value, ($this->filter["measure"] != "spent_seconds"),
260 ($this->filter["measure"] == "spent_seconds"));
261
262 $labels = array();
263 for($loop = 0; $loop<24; $loop++)
264 {
265 $labels[$loop] = str_pad($loop, 2, "0", STR_PAD_LEFT);
266 }
267 $chart->setTicks($labels, $value_ticks, true);
268
269 return $chart->getHTML();
270 }
271
272 protected function fillMetaExcel()
273 {
274
275 }
276
277 protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
278 {
279 $a_worksheet->write($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
280 $a_worksheet->write($a_row, 0, $a_set["obj_id"]);
281
282 $col = 1;
283 for($loop = 0; $loop<24; $loop+=2)
284 {
285 $value = (int)$a_set["hour".$loop];
286 if($this->filter["measure"] != "spent_seconds")
287 {
288 $value = $this->anonymizeValue($value);
289 }
290
291 $col++;
292 $a_worksheet->write($a_row, $col, $value);
293 }
294
295 if($this->filter["measure"] == "spent_seconds")
296 {
297 // keep seconds
298 // $sum = $this->formatSeconds((int)$a_set["sum"]);
299 $sum = (int)$a_set["sum"];
300 }
301 else
302 {
303 $sum = $this->anonymizeValue((int)$a_set["sum"]);
304 }
305 $col++;
306 $a_worksheet->write($a_row, $col, $sum);
307 }
308
309 protected function fillMetaCSV()
310 {
311
312 }
313
314 protected function fillRowCSV($a_csv, $a_set)
315 {
316 $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
317 $a_csv->addColumn($a_set["obj_id"]);
318
319 for($loop = 0; $loop<24; $loop+=2)
320 {
321 $value = (int)$a_set["hour".$loop];
322 if($this->filter["measure"] != "spent_seconds")
323 {
324 $value = $this->anonymizeValue($value);
325 }
326
327 $a_csv->addColumn($value);
328 }
329
330 if($this->filter["measure"] == "spent_seconds")
331 {
332 // keep seconds
333 // $sum = $this->formatSeconds((int)$a_set["sum"]);
334 $sum = (int)$a_set["sum"];
335 }
336 else
337 {
338 $sum = $this->anonymizeValue((int)$a_set["sum"]);
339 }
340 $a_csv->addColumn($sum);
341
342 $a_csv->addRow();
343 }
344}
345
346?>
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
fillRowExcel($a_worksheet, &$a_row, $a_set)
Excel Version of Fill Row.
numericOrdering($a_field)
Should this field be sorted numeric?
fillRowCSV($a_csv, $a_set)
CSV Version of Fill Row.
__construct($a_parent_obj, $a_parent_cmd, array $a_preselect=null, $a_load_items=true)
Constructor.
TableGUI class for learning progress.
searchObjects(array $filter, $permission, array $preset_obj_ids=null)
Search objects that match current filters.
formatSeconds($seconds, $a_shorten_zero=false)
getCurrentFilter($as_query=false)
buildValueScale($a_max_value, $a_anonymize=false, $a_format_seconds=false)
anonymizeValue($a_value, $a_force_number=false)
getMonthsFilter($a_short=false)
getPossibleTypes($a_split_learning_resources=false, $a_include_digilib=false, $a_allow_undefined_lp=false)
Get possible subtypes.
static _lookupTitle($a_id)
lookup object title
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a selection list property in a property form.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="")
Add a column to the header.
setEnableHeader($a_enableheader)
Set Enable Header.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setExportFormats(array $formats)
Set available export formats.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setEnableTitle($a_enabletitle)
Set Enable Title.
setEnableNumInfo($a_val)
Set enable num info.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
This class represents a text property in a property form.
static getObjectDailyStatistics(array $a_ref_ids, $a_year, $a_month=null)
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40