ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLPObjectStatisticsTableGUI.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 public function __construct($a_parent_obj, $a_parent_cmd, array $a_preselect = null, $a_load_items = true)
21 {
22 global $DIC;
23
24 $ilCtrl = $DIC['ilCtrl'];
25 $lng = $DIC['lng'];
26
27 $this->preselected = $a_preselect;
28
29 $this->setId("lpobjstattbl");
30
31 parent::__construct($a_parent_obj, $a_parent_cmd);
32
33 $this->setShowRowsSelector(true);
34 // $this->setLimit(ilSearchSettings::getInstance()->getMaxHits());
35 $this->initFilter();
36
37 $this->addColumn("", "", "1", true);
38 $this->addColumn($lng->txt("trac_title"), "title");
39 $this->addColumn($lng->txt("object_id"), "obj_id");
40 if (strpos($this->filter["yearmonth"], "-") === false) {
41 foreach ($this->getMonthsYear($this->filter["yearmonth"]) as $num => $caption) {
42 $this->addColumn($caption, "month_" . $num);
43 }
44 }
45 $this->addColumn($lng->txt("total"), "total");
46
47 $this->setTitle($this->lng->txt("trac_object_stat_access"));
48
49 // $this->setSelectAllCheckbox("item_id");
50 $this->addMultiCommand("showAccessGraph", $lng->txt("trac_show_graph"));
51 $this->setResetCommand("resetAccessFilter");
52 $this->setFilterCommand("applyAccessFilter");
53
54 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
55 $this->setRowTemplate("tpl.lp_object_statistics_row.html", "Services/Tracking");
56 $this->setEnableHeader(true);
57 $this->setEnableNumInfo(true);
58 $this->setEnableTitle(true);
59 $this->setDefaultOrderField("title");
60 $this->setDefaultOrderDirection("asc");
61
62 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
63
64 if ($a_load_items) {
65 $this->getItems();
66 }
67 }
68
69 public function numericOrdering($a_field)
70 {
71 if ($a_field != "title") {
72 return true;
73 }
74 return false;
75 }
76
80 public function initFilter()
81 {
82 global $DIC;
83
84 $lng = $DIC['lng'];
85
86 $this->setDisableFilterHiding(true);
87
88 // object type selection
89 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
90 $si = new ilSelectInputGUI($lng->txt("obj_type"), "type");
91 $si->setOptions($this->getPossibleTypes(true, false, true));
92 $this->addFilterItem($si);
93 $si->readFromSession();
94 if (!$si->getValue()) {
95 $si->setValue("crs");
96 }
97 $this->filter["type"] = $si->getValue();
98
99 // title/description
100 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
101 $ti = new ilTextInputGUI($lng->txt("trac_title_description"), "query");
102 $ti->setMaxLength(64);
103 $ti->setSize(20);
104 $this->addFilterItem($ti);
105 $ti->readFromSession();
106 $this->filter["query"] = $ti->getValue();
107
108 // read_count/spent_seconds
109 $si = new ilSelectInputGUI($lng->txt("trac_figure"), "figure");
110 $si->setOptions(array("read_count" => $lng->txt("trac_read_count"),
111 "spent_seconds" => $lng->txt("trac_spent_seconds"),
112 "users" => $lng->txt("users")));
113 $this->addFilterItem($si);
114 $si->readFromSession();
115 if (!$si->getValue()) {
116 $si->setValue("read_count");
117 }
118 $this->filter["measure"] = $si->getValue();
119
120 // year/month
121 $si = new ilSelectInputGUI($lng->txt("year") . " / " . $lng->txt("month"), "yearmonth");
122 $si->setOptions($this->getMonthsFilter());
123 $this->addFilterItem($si);
124 $si->readFromSession();
125 if (!$si->getValue()) {
126 $si->setValue(date("Y-m"));
127 }
128 $this->filter["yearmonth"] = $si->getValue();
129 }
130
131 public function getItems()
132 {
133 $data = array();
134
135 if ($this->filter["type"] != "prtf") {
136 // JF, 2016-06-06
137 $objects = $this->searchObjects($this->getCurrentFilter(true), "", null, false);
138
139 if ($this->filter["type"] == "blog") {
140 include_once './Services/Tracking/classes/class.ilTrQuery.php';
141 foreach (ilTrQuery::getWorkspaceBlogs($this->filter["query"]) as $obj_id) {
142 $objects[$obj_id] = array($obj_id);
143 }
144 }
145 } else {
146 // portfolios are not part of repository
147 include_once './Services/Tracking/classes/class.ilTrQuery.php';
148 foreach (ilTrQuery::getPortfolios($this->filter["query"]) as $obj_id) {
149 $objects[$obj_id] = array($obj_id);
150 }
151 }
152
153 if ($objects) {
154 $yearmonth = explode("-", $this->filter["yearmonth"]);
155 if (sizeof($yearmonth) == 1) {
156 include_once './Services/Tracking/classes/class.ilTrQuery.php';
157 foreach (ilTrQuery::getObjectAccessStatistics($objects, $yearmonth[0]) as $obj_id => $months) {
158 $data[$obj_id]["obj_id"] = $obj_id;
159 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
160
161 foreach ($months as $month => $values) {
162 $idx = $yearmonth[0] . "-" . str_pad($month, 2, "0", STR_PAD_LEFT);
163 $data[$obj_id]["month_" . $idx] = (int) $values[$this->filter["measure"]];
164 $data[$obj_id]["total"] += (int) $values[$this->filter["measure"]];
165 }
166 }
167 } else {
168 include_once './Services/Tracking/classes/class.ilTrQuery.php';
169 foreach (ilTrQuery::getObjectAccessStatistics($objects, $yearmonth[0], (int) $yearmonth[1]) as $obj_id => $days) {
170 $data[$obj_id]["obj_id"] = $obj_id;
171 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
172
173 foreach ($days as $day => $values) {
174 $data[$obj_id]["day_" . $day] = (int) $values[$this->filter["measure"]];
175 $data[$obj_id]["total"] += (int) $values[$this->filter["measure"]];
176 }
177 }
178 }
179
180 // add objects with no usage data
181 foreach (array_keys($objects) as $obj_id) {
182 if (!isset($data[$obj_id])) {
183 $data[$obj_id]["obj_id"] = $obj_id;
184 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
185 }
186 }
187 }
188
189 $this->setData($data);
190 }
191
195 protected function fillRow($a_set)
196 {
197 global $DIC;
198
199 $ilCtrl = $DIC['ilCtrl'];
200
201 $type = ilObject::_lookupType($a_set["obj_id"]);
202
203 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
204 $this->tpl->setVariable("ICON_SRC", ilObject::_getIcon("", "tiny", $type));
205 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
206 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
207
208 if ($this->preselected && in_array($a_set["obj_id"], $this->preselected)) {
209 $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
210 }
211
212 $sum = 0;
213 if (strpos($this->filter["yearmonth"], "-") === false) {
214 $this->tpl->setCurrentBlock("month");
215 foreach (array_keys($this->getMonthsYear($this->filter["yearmonth"])) as $num) {
216 $value = (int) $a_set["month_" . $num];
217 if ($this->filter["measure"] != "spent_seconds") {
218 $value = $this->anonymizeValue($value);
219 } else {
220 $value = $this->formatSeconds($value, true);
221 }
222 $this->tpl->setVariable("MONTH_VALUE", $value);
223 $this->tpl->parseCurrentBlock();
224 }
225 }
226
227 if ($this->filter["measure"] == "spent_seconds") {
228 $sum = $this->formatSeconds((int) $a_set["total"], true);
229 } else {
230 $sum = $this->anonymizeValue((int) $a_set["total"]);
231 }
232 $this->tpl->setVariable("TOTAL", $sum);
233 }
234
235 public function getGraph(array $a_graph_items)
236 {
237 global $DIC;
238
239 $lng = $DIC['lng'];
240
241 include_once "Services/Chart/classes/class.ilChart.php";
243 $chart->setSize(700, 500);
244
245 $legend = new ilChartLegend();
246 $chart->setLegend($legend);
247
248 $max_value = 0;
249 foreach ($this->getData() as $object) {
250 if (in_array($object["obj_id"], $a_graph_items)) {
251 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
252 $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
253
254 if (strpos($this->filter["yearmonth"], "-") === false) {
255 foreach (array_keys($this->getMonthsYear($this->filter["yearmonth"])) as $idx => $num) {
256 $value = (int) $object["month_" . $num];
257 $max_value = max($max_value, $value);
258 if ($this->filter["measure"] != "spent_seconds") {
259 $value = $this->anonymizeValue($value, true);
260 }
261 $series->addPoint($idx, $value);
262 }
263 } else {
264 for ($loop = 1; $loop < 32; $loop++) {
265 $value = (int) $object["day_" . $loop];
266 $max_value = max($max_value, $value);
267 if ($this->filter["measure"] != "spent_seconds") {
268 $value = $this->anonymizeValue($value, true);
269 }
270 $series->addPoint($loop, $value);
271 }
272 }
273
274 $chart->addData($series);
275 }
276 }
277
278 $value_ticks = $this->buildValueScale(
279 $max_value,
280 ($this->filter["measure"] != "spent_seconds"),
281 ($this->filter["measure"] == "spent_seconds")
282 );
283
284 $labels = array();
285 if (strpos($this->filter["yearmonth"], "-") === false) {
286 foreach (array_values($this->getMonthsYear($this->filter["yearmonth"], true)) as $idx => $caption) {
287 $labels[$idx] = $caption;
288 }
289 } else {
290 for ($loop = 1; $loop < 32; $loop++) {
291 $labels[$loop] = $loop . ".";
292 }
293 }
294 $chart->setTicks($labels, $value_ticks, true);
295
296 return $chart->getHTML();
297 }
298
299 protected function fillMetaExcel(ilExcel $a_excel, &$a_row)
300 {
301 }
302
303 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
304 {
305 $a_excel->setCell($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
306 $a_excel->setCell($a_row, 1, $a_set["obj_id"]);
307
308 $col = 1;
309 if (strpos($this->filter["yearmonth"], "-") === false) {
310 foreach (array_keys($this->getMonthsYear($this->filter["yearmonth"])) as $num) {
311 $value = (int) $a_set["month_" . $num];
312 if ($this->filter["measure"] != "spent_seconds") {
313 $value = $this->anonymizeValue($value);
314 }
315
316 $a_excel->setCell($a_row, ++$col, $value);
317 }
318 }
319
320 if ($this->filter["measure"] == "spent_seconds") {
321 // keep seconds
322 // $sum = $this->formatSeconds((int)$a_set["total"]);
323 $sum = (int) $a_set["total"];
324 } else {
325 $sum = $this->anonymizeValue((int) $a_set["total"]);
326 }
327 $a_excel->setCell($a_row, ++$col, $sum);
328 }
329
330 protected function fillMetaCSV($a_csv)
331 {
332 }
333
334 protected function fillRowCSV($a_csv, $a_set)
335 {
336 $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
337 $a_csv->addColumn($a_set["obj_id"]);
338
339 if (strpos($this->filter["yearmonth"], "-") === false) {
340 foreach (array_keys($this->getMonthsYear($this->filter["yearmonth"])) as $num) {
341 $value = (int) $a_set["month_" . $num];
342 if ($this->filter["measure"] != "spent_seconds") {
343 $value = $this->anonymizeValue($value);
344 }
345
346 $a_csv->addColumn($value);
347 }
348 }
349
350 if ($this->filter["measure"] == "spent_seconds") {
351 // keep seconds
352 // $sum = $this->formatSeconds((int)$a_set["total"]);
353 $sum = (int) $a_set["total"];
354 } else {
355 $sum = $this->anonymizeValue((int) $a_set["total"]);
356 }
357 $a_csv->addColumn($sum);
358
359 $a_csv->addRow();
360 }
361}
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, $a_datatype=null)
Set cell value.
TableGUI class for learning progress.
fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
Excel 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.
fillRowCSV($a_csv, $a_set)
CSV Version of Fill Row.
fillMetaCSV($a_csv)
Add meta information to csv export.
numericOrdering($a_field)
Should this field be sorted numeric?
TableGUI class for learning progress.
formatSeconds($seconds, $a_shorten_zero=false)
getCurrentFilter($as_query=false)
getMonthsYear($a_year=null, $a_short=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 _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.
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.
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.
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 getObjectAccessStatistics(array $a_ref_ids, $a_year, $a_month=null)
static getWorkspaceBlogs($a_title=null)
static getPortfolios($a_title=null)
$legend
global $ilCtrl
Definition: ilias.php:18
$type
global $DIC
Definition: saml.php:7
$values