ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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);
41 }
42 $this->addColumn($lng->txt("total"), "sum");
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 if($this->filter["type"] != "prtf")
135 {
136 // JF, 2016-06-06
137 $objects = $this->searchObjects($this->getCurrentFilter(true), "", null, false);
138
139 if($this->filter["type"] == "blog")
140 {
141 foreach(ilTrQuery::getWorkspaceBlogs($this->filter["query"]) as $obj_id)
142 {
143 $objects[$obj_id] = array($obj_id);
144 }
145 }
146 }
147 else
148 {
149 // portfolios are not part of repository
150 foreach(ilTrQuery::getPortfolios($this->filter["query"]) as $obj_id)
151 {
152 $objects[$obj_id] = array($obj_id);
153 }
154 }
155
156 if($objects)
157 {
158 include_once "Services/Tracking/classes/class.ilTrQuery.php";
159
160 $yearmonth = explode("-", $this->filter["yearmonth"]);
161 if(sizeof($yearmonth) == 1)
162 {
163 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0]);
164 }
165 else
166 {
167 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0], (int)$yearmonth[1]);
168 }
169
170 foreach($stat_objects as $obj_id => $hours)
171 {
172 $data[$obj_id]["obj_id"] = $obj_id;
173 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
174
175 foreach($hours as $hour => $values)
176 {
177 // table data
178 $data[$obj_id]["hour".floor($hour/2)*2] += (int)$values[$this->filter["measure"]];
179 $data[$obj_id]["sum"] += (int)$values[$this->filter["measure"]];
180
181 // graph data
182 $data[$obj_id]["graph"]["hour".$hour] = $values[$this->filter["measure"]];
183 }
184 }
185
186 // add objects with no usage data
187 foreach($objects as $obj_id => $ref_ids)
188 {
189 if(!isset($data[$obj_id]))
190 {
191 $data[$obj_id]["obj_id"] = $obj_id;
192 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
193 }
194 }
195 }
196
197 $this->setData($data);
198 }
199
203 protected function fillRow($a_set)
204 {
205 global $ilCtrl;
206
207 $type = ilObject::_lookupType($a_set["obj_id"]);
208
209 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
210 $this->tpl->setVariable("ICON_SRC", ilObject::_getIcon("", "tiny", $type));
211 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
212 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
213
214 if($this->preselected && in_array($a_set["obj_id"], $this->preselected))
215 {
216 $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
217 }
218
219 $this->tpl->setCurrentBlock("hour");
220 for($loop = 0; $loop<24; $loop+=2)
221 {
222 $value = (int)$a_set["hour".$loop];
223 if($this->filter["measure"] != "spent_seconds")
224 {
225 $value = $this->anonymizeValue($value);
226 }
227 else
228 {
229 $value = $this->formatSeconds($value, true);
230 }
231 $this->tpl->setVariable("HOUR_VALUE", $value);
232 $this->tpl->parseCurrentBlock();
233 }
234
235 if($this->filter["measure"] == "spent_seconds")
236 {
237 $sum = $this->formatSeconds((int)$a_set["sum"], true);
238 }
239 else
240 {
241 $sum = $this->anonymizeValue((int)$a_set["sum"]);
242 }
243 $this->tpl->setVariable("TOTAL", $sum);
244 }
245
246 function getGraph(array $a_graph_items)
247 {
248 global $lng;
249
250 include_once "Services/Chart/classes/class.ilChart.php";
252 $chart->setsize(700, 500);
253
254 $legend = new ilChartLegend();
255 $chart->setLegend($legend);
256
257 $max_value = 0;
258 foreach($this->getData() as $object)
259 {
260 if(in_array($object["obj_id"], $a_graph_items))
261 {
262 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
263 $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
264
265 for($loop = 0; $loop<24; $loop++)
266 {
267 $value = (int)$object["graph"]["hour".$loop];
268 $max_value = max($max_value, $value);
269 if($this->filter["measure"] != "spent_seconds")
270 {
271 $value = $this->anonymizeValue($value, true);
272 }
273 $series->addPoint($loop, $value);
274 }
275
276 $chart->addData($series);
277 }
278 }
279
280 $value_ticks = $this->buildValueScale($max_value, ($this->filter["measure"] != "spent_seconds"),
281 ($this->filter["measure"] == "spent_seconds"));
282
283 $labels = array();
284 for($loop = 0; $loop<24; $loop++)
285 {
286 $labels[$loop] = str_pad($loop, 2, "0", STR_PAD_LEFT);
287 }
288 $chart->setTicks($labels, $value_ticks, true);
289
290 return $chart->getHTML();
291 }
292
293 protected function fillMetaExcel(ilExcel $a_excel, &$a_row)
294 {
295
296 }
297
298 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
299 {
300 $a_excel->setCell($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
301 $a_excel->setCell($a_row, 1, $a_set["obj_id"]);
302
303 $col = 1;
304 for($loop = 0; $loop<24; $loop+=2)
305 {
306 $value = (int)$a_set["hour".$loop];
307 if($this->filter["measure"] != "spent_seconds")
308 {
309 $value = $this->anonymizeValue($value);
310 }
311
312 $a_excel->setCell($a_row, ++$col, $value);
313 }
314
315 if($this->filter["measure"] == "spent_seconds")
316 {
317 // keep seconds
318 // $sum = $this->formatSeconds((int)$a_set["sum"]);
319 $sum = (int)$a_set["sum"];
320 }
321 else
322 {
323 $sum = $this->anonymizeValue((int)$a_set["sum"]);
324 }
325 $a_excel->setCell($a_row, ++$col, $sum);
326 }
327
328 protected function fillMetaCSV($a_csv)
329 {
330
331 }
332
333 protected function fillRowCSV($a_csv, $a_set)
334 {
335 $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
336 $a_csv->addColumn($a_set["obj_id"]);
337
338 for($loop = 0; $loop<24; $loop+=2)
339 {
340 $value = (int)$a_set["hour".$loop];
341 if($this->filter["measure"] != "spent_seconds")
342 {
343 $value = $this->anonymizeValue($value);
344 }
345
346 $a_csv->addColumn($value);
347 }
348
349 if($this->filter["measure"] == "spent_seconds")
350 {
351 // keep seconds
352 // $sum = $this->formatSeconds((int)$a_set["sum"]);
353 $sum = (int)$a_set["sum"];
354 }
355 else
356 {
357 $sum = $this->anonymizeValue((int)$a_set["sum"]);
358 }
359 $a_csv->addColumn($sum);
360
361 $a_csv->addRow();
362 }
363}
364
365?>
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
setCell($a_row, $a_col, $a_value)
Set cell value.
fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
Excel Version of Fill Row.
fillMetaCSV($a_csv)
Add meta information to csv export.
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.
fillMetaExcel(ilExcel $a_excel, &$a_row)
Add meta information to excel export.
TableGUI class for learning progress.
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.
searchObjects(array $filter, $permission, array $preset_obj_ids=null, $a_check_lp_activation=true)
Search objects that match current filters.
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.
setEnableHeader($a_enableheader)
Set Enable Header.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
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.
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)
static getWorkspaceBlogs($a_title=null)
static getPortfolios($a_title=null)
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17