ILIAS  release_7 Revision v7.30-3-g800a261c036
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 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("lpobjstatdlytbl");
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 for ($loop = 0; $loop < 24; $loop += 2) {
41 $this->addColumn(str_pad($loop, 2, "0", STR_PAD_LEFT) . ":00-<br />" .
42 str_pad($loop + 2, 2, "0", STR_PAD_LEFT) . ":00 ", "hour" . $loop);
43 }
44 $this->addColumn($lng->txt("total"), "sum");
45
46 $this->setTitle($this->lng->txt("trac_object_stat_daily"));
47
48 // $this->setSelectAllCheckbox("item_id");
49 $this->addMultiCommand("showDailyGraph", $lng->txt("trac_show_graph"));
50 $this->setResetCommand("resetDailyFilter");
51 $this->setFilterCommand("applyDailyFilter");
52
53 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
54 $this->setRowTemplate("tpl.lp_object_statistics_daily_row.html", "Services/Tracking");
55 $this->setEnableHeader(true);
56 $this->setEnableNumInfo(true);
57 $this->setEnableTitle(true);
58 $this->setDefaultOrderField("title");
59 $this->setDefaultOrderDirection("asc");
60
61 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
62
63 if ($a_load_items) {
64 $this->getItems();
65 }
66 }
67
68 public function numericOrdering($a_field)
69 {
70 if ($a_field != "title") {
71 return true;
72 }
73 return false;
74 }
75
79 public function initFilter()
80 {
81 global $DIC;
82
83 $lng = $DIC['lng'];
84
85 $this->setDisableFilterHiding(true);
86
87 // object type selection
88 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
89 $si = new ilSelectInputGUI($lng->txt("obj_type"), "type");
90 $si->setOptions($this->getPossibleTypes(true, false, true));
91 $this->addFilterItem($si);
92 $si->readFromSession();
93 if (!$si->getValue()) {
94 $si->setValue("crs");
95 }
96 $this->filter["type"] = $si->getValue();
97
98 // title/description
99 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
100 $ti = new ilTextInputGUI($lng->txt("trac_title_description"), "query");
101 $ti->setMaxLength(64);
102 $ti->setSize(20);
103 $this->addFilterItem($ti);
104 $ti->readFromSession();
105 $this->filter["query"] = $ti->getValue();
106
107 // read_count/spent_seconds
108 $si = new ilSelectInputGUI($lng->txt("trac_figure"), "figure");
109 $si->setOptions(array("read_count" => $lng->txt("trac_read_count"),
110 "spent_seconds" => $lng->txt("trac_spent_seconds")));
111 $this->addFilterItem($si);
112 $si->readFromSession();
113 if (!$si->getValue()) {
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 $si->setValue(date("Y-m"));
125 }
126 $this->filter["yearmonth"] = $si->getValue();
127 }
128
129 public function getItems()
130 {
131 $data = array();
132
133 if ($this->filter["type"] != "prtf") {
134 // JF, 2016-06-06
135 $objects = $this->searchObjects($this->getCurrentFilter(true), "", null, false);
136
137 if ($this->filter["type"] == "blog") {
138 foreach (ilTrQuery::getWorkspaceBlogs($this->filter["query"]) as $obj_id) {
139 $objects[$obj_id] = array($obj_id);
140 }
141 }
142 } else {
143 // portfolios are not part of repository
144 foreach (ilTrQuery::getPortfolios($this->filter["query"]) as $obj_id) {
145 $objects[$obj_id] = array($obj_id);
146 }
147 }
148
149 if ($objects) {
150 include_once "Services/Tracking/classes/class.ilTrQuery.php";
151
152 $yearmonth = explode("-", $this->filter["yearmonth"]);
153 if (sizeof($yearmonth) == 1) {
154 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0]);
155 } else {
156 $stat_objects = ilTrQuery::getObjectDailyStatistics($objects, $yearmonth[0], (int) $yearmonth[1]);
157 }
158
159 foreach ($stat_objects as $obj_id => $hours) {
160 $data[$obj_id]["obj_id"] = $obj_id;
161 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
162
163 foreach ($hours as $hour => $values) {
164 // table data
165 $data[$obj_id]["hour" . floor($hour / 2) * 2] += (int) $values[$this->filter["measure"]];
166 $data[$obj_id]["sum"] += (int) $values[$this->filter["measure"]];
167
168 // graph data
169 $data[$obj_id]["graph"]["hour" . $hour] = $values[$this->filter["measure"]];
170 }
171 }
172
173 // add objects with no usage data
174 foreach ($objects as $obj_id => $ref_ids) {
175 if (!isset($data[$obj_id])) {
176 $data[$obj_id]["obj_id"] = $obj_id;
177 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
178 }
179 }
180 }
181
182 $this->setData($data);
183 }
184
188 protected function fillRow($a_set)
189 {
190 global $DIC;
191
192 $ilCtrl = $DIC['ilCtrl'];
193
194 $type = ilObject::_lookupType($a_set["obj_id"]);
195
196 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
197 $this->tpl->setVariable("ICON_SRC", ilObject::_getIcon("", "tiny", $type));
198 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
199 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
200
201 if ($this->preselected && in_array($a_set["obj_id"], $this->preselected)) {
202 $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
203 }
204
205 $this->tpl->setCurrentBlock("hour");
206 for ($loop = 0; $loop < 24; $loop += 2) {
207 $value = (int) $a_set["hour" . $loop];
208 if ($this->filter["measure"] != "spent_seconds") {
209 $value = $this->anonymizeValue($value);
210 } else {
211 $value = $this->formatSeconds($value, true);
212 }
213 $this->tpl->setVariable("HOUR_VALUE", $value);
214 $this->tpl->parseCurrentBlock();
215 }
216
217 if ($this->filter["measure"] == "spent_seconds") {
218 $sum = $this->formatSeconds((int) $a_set["sum"], true);
219 } else {
220 $sum = $this->anonymizeValue((int) $a_set["sum"]);
221 }
222 $this->tpl->setVariable("TOTAL", $sum);
223 }
224
225 public function getGraph(array $a_graph_items)
226 {
227 global $DIC;
228
229 $lng = $DIC['lng'];
230
231 include_once "Services/Chart/classes/class.ilChart.php";
233 $chart->setsize(700, 500);
234
235 $legend = new ilChartLegend();
236 $chart->setLegend($legend);
237
238 $max_value = 0;
239 foreach ($this->getData() as $object) {
240 if (in_array($object["obj_id"], $a_graph_items)) {
241 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
242 $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
243
244 for ($loop = 0; $loop < 24; $loop++) {
245 $value = (int) $object["graph"]["hour" . $loop];
246 $max_value = max($max_value, $value);
247 if ($this->filter["measure"] != "spent_seconds") {
248 $value = $this->anonymizeValue($value, true);
249 }
250 $series->addPoint($loop, $value);
251 }
252
253 $chart->addData($series);
254 }
255 }
256
257 $value_ticks = $this->buildValueScale(
258 $max_value,
259 ($this->filter["measure"] != "spent_seconds"),
260 ($this->filter["measure"] == "spent_seconds")
261 );
262
263 $labels = array();
264 for ($loop = 0; $loop < 24; $loop++) {
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(ilExcel $a_excel, &$a_row)
273 {
274 }
275
276 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
277 {
278 $a_excel->setCell($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
279 $a_excel->setCell($a_row, 1, $a_set["obj_id"]);
280
281 $col = 1;
282 for ($loop = 0; $loop < 24; $loop += 2) {
283 $value = (int) $a_set["hour" . $loop];
284 if ($this->filter["measure"] != "spent_seconds") {
285 $value = $this->anonymizeValue($value);
286 }
287
288 $a_excel->setCell($a_row, ++$col, $value);
289 }
290
291 if ($this->filter["measure"] == "spent_seconds") {
292 // keep seconds
293 // $sum = $this->formatSeconds((int)$a_set["sum"]);
294 $sum = (int) $a_set["sum"];
295 } else {
296 $sum = $this->anonymizeValue((int) $a_set["sum"]);
297 }
298 $a_excel->setCell($a_row, ++$col, $sum);
299 }
300
301 protected function fillMetaCSV($a_csv)
302 {
303 }
304
305 protected function fillRowCSV($a_csv, $a_set)
306 {
307 $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
308 $a_csv->addColumn($a_set["obj_id"]);
309
310 for ($loop = 0; $loop < 24; $loop += 2) {
311 $value = (int) $a_set["hour" . $loop];
312 if ($this->filter["measure"] != "spent_seconds") {
313 $value = $this->anonymizeValue($value);
314 }
315
316 $a_csv->addColumn($value);
317 }
318
319 if ($this->filter["measure"] == "spent_seconds") {
320 // keep seconds
321 // $sum = $this->formatSeconds((int)$a_set["sum"]);
322 $sum = (int) $a_set["sum"];
323 } else {
324 $sum = $this->anonymizeValue((int) $a_set["sum"]);
325 }
326 $a_csv->addColumn($sum);
327
328 $a_csv->addRow();
329 }
330}
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.
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.
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 getObjectDailyStatistics(array $a_ref_ids, $a_year, $a_month=null)
static getWorkspaceBlogs($a_title=null)
static getPortfolios($a_title=null)
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type