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