ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSessionStatisticsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "Services/Authentication/classes/class.ilSessionStatistics.php";
6 
16 {
17  const MODE_TODAY = 1;
18  const MODE_LAST_DAY = 2;
19  const MODE_LAST_WEEK = 3;
20  const MODE_LAST_MONTH = 4;
21  const MODE_DAY = 5;
22  const MODE_WEEK = 6;
23  const MODE_MONTH = 7;
24  const MODE_YEAR = 8;
25 
26  const SCALE_DAY = 1;
27  const SCALE_WEEK = 2;
28  const SCALE_MONTH = 3;
29  const SCALE_YEAR = 4;
31 
32  function executeCommand()
33  {
34  global $ilCtrl;
35 
36  $this->setSubTabs();
37 
38  switch($ilCtrl->getNextClass())
39  {
40  default:
41  $cmd = $ilCtrl->getCmd("current");
42  $this->$cmd();
43  }
44 
45  return true;
46  }
47 
48  protected function setSubTabs()
49  {
50  global $ilTabs, $ilCtrl, $lng;
51 
52  $ilTabs->addSubTab("current", $lng->txt("trac_current_system_load"),
53  $ilCtrl->getLinkTarget($this, "current"));
54  $ilTabs->addSubTab("short", $lng->txt("trac_short_system_load"),
55  $ilCtrl->getLinkTarget($this, "short"));
56  $ilTabs->addSubTab("long", $lng->txt("trac_long_system_load"),
57  $ilCtrl->getLinkTarget($this, "long"));
58  $ilTabs->addSubTab("periodic", $lng->txt("trac_periodic_system_load"),
59  $ilCtrl->getLinkTarget($this, "periodic"));
60  }
61 
62  protected function current($a_export = false)
63  {
64  global $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
65 
66  $ilTabs->activateSubTab("current");
67 
68  // current mode
69  if(!$_REQUEST["smd"])
70  {
71  $_REQUEST["smd"] = self::MODE_TODAY;
72  }
73  $mode = (int)$_REQUEST["smd"];
74 
75  // current measure
76  if(!$_REQUEST["smm"])
77  {
78  $_REQUEST["smm"] = "avg";
79  }
80  $measure = (string)$_REQUEST["smm"];
81 
82 
83  switch($mode)
84  {
85  case self::MODE_TODAY:
86  $time_from = strtotime("today");
87  $time_to = strtotime("tomorrow")-1;
88  $scale = self::SCALE_DAY;
89  break;
90 
91  case self::MODE_LAST_DAY:
92  $time_to = time();
93  $time_from = $time_to-60*60*24;
94  $scale = self::SCALE_DAY;
95  break;
96 
97  case self::MODE_LAST_WEEK:
98  $time_to = time();
99  $time_from = $time_to-60*60*24*7;
100  $scale = self::SCALE_WEEK;
101  break;
102 
103  case self::MODE_LAST_MONTH:
104  $time_to = time();
105  $time_from = $time_to-60*60*24*30;
106  $scale = self::SCALE_MONTH;
107  break;
108  }
109 
110  $mode_options = array(
111  self::MODE_TODAY => $lng->txt("trac_session_statistics_mode_today"),
112  self::MODE_LAST_DAY => $lng->txt("trac_session_statistics_mode_last_day"),
113  self::MODE_LAST_WEEK => $lng->txt("trac_session_statistics_mode_last_week"),
114  self::MODE_LAST_MONTH => $lng->txt("trac_session_statistics_mode_last_month"));
115 
116  $title = $lng->txt("trac_current_system_load")." - ".$mode_options[$mode];
117  $data = $this->buildData($time_from, $time_to, $title);
118 
119  if(!$a_export)
120  {
121  // toolbar
122  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
123  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "current"));
124 
125  $mode_selector = new ilSelectInputGUI("&nbsp;".$lng->txt("trac_scale"), "smd");
126  $mode_selector->setOptions($mode_options);
127  $mode_selector->setValue($mode);
128  $ilToolbar->addInputItem($mode_selector, true);
129 
130  $measure_options = array(
131  "avg" => $lng->txt("trac_session_active_avg"),
132  "min" => $lng->txt("trac_session_active_min"),
133  "max" => $lng->txt("trac_session_active_max"));
134 
135  $measure_selector = new ilSelectInputGUI("&nbsp;".$lng->txt("trac_measure"), "smm");
136  $measure_selector->setOptions($measure_options);
137  $measure_selector->setValue($measure);
138  $ilToolbar->addInputItem($measure_selector, true);
139 
140  $ilToolbar->addFormButton($lng->txt("ok"), "current");
141 
142  if(sizeof($data["active"]))
143  {
144  $ilToolbar->addSeparator();
145  $ilToolbar->addFormButton($lng->txt("export"), "currentExport");
146  }
147 
148  $tpl->setContent($this->render($data, $scale, $measure));
149 
150  $tpl->setLeftContent($this->renderCurrentBasics());
151  }
152  else
153  {
154  $this->exportCSV($data, $scale);
155  }
156  }
157 
158  protected function currentExport()
159  {
160  $this->current(true);
161  }
162 
163  protected function importDate($a_incoming, $a_default = null)
164  {
165  if(!$a_default)
166  {
167  $a_default = time();
168  }
169 
170  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
171  $parsed = ilCalendarUtil::parseIncomingDate($a_incoming);
172  return $parsed
173  ? $parsed->get(IL_CAL_UNIX)
174  : $a_default;
175  }
176 
177  protected function short($a_export = false)
178  {
179  global $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
180 
181  $ilTabs->activateSubTab("short");
182 
183  // current start
184  $time_to = $this->importDate($_REQUEST["sst"]);
185 
186  // current mode
187  if(!$_REQUEST["smd"])
188  {
189  $_REQUEST["smd"] = self::MODE_DAY;
190  }
191  $mode = (int)$_REQUEST["smd"];
192 
193  // current measure
194  if(!$_REQUEST["smm"])
195  {
196  $_REQUEST["smm"] = "avg";
197  }
198  $measure = (string)$_REQUEST["smm"];
199 
200  switch($mode)
201  {
202  case self::MODE_DAY:
203  $time_from = $time_to-60*60*24;
204  $scale = self::SCALE_DAY;
205  break;
206 
207  case self::MODE_WEEK:
208  $time_from = $time_to-60*60*24*7;
209  $scale = self::SCALE_WEEK;
210  break;
211  }
212 
213  $mode_options = array(
214  self::MODE_DAY => $lng->txt("trac_session_statistics_mode_day"),
215  self::MODE_WEEK => $lng->txt("trac_session_statistics_mode_week")
216  );
217 
218  $title = $lng->txt("trac_short_system_load")." - ".$mode_options[$mode];
219  $data = $this->buildData($time_from, $time_to, $title);
220 
221  if(!$a_export)
222  {
223  // toolbar
224  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
225  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "short"));
226 
227  $start_selector = new ilDateTimeInputGUI($lng->txt("trac_end_at"), "sst");
228  $start_selector->setDate(new ilDate($time_to, IL_CAL_UNIX));
229  $ilToolbar->addInputItem($start_selector, true);
230 
231  $mode_selector = new ilSelectInputGUI("&nbsp;".$lng->txt("trac_scale"), "smd");
232  $mode_selector->setOptions($mode_options);
233  $mode_selector->setValue($mode);
234  $ilToolbar->addInputItem($mode_selector, true);
235 
236  $measure_options = array(
237  "avg" => $lng->txt("trac_session_active_avg"),
238  "min" => $lng->txt("trac_session_active_min"),
239  "max" => $lng->txt("trac_session_active_max"));
240 
241  $measure_selector = new ilSelectInputGUI("&nbsp;".$lng->txt("trac_measure"), "smm");
242  $measure_selector->setOptions($measure_options);
243  $measure_selector->setValue($measure);
244  $ilToolbar->addInputItem($measure_selector, true);
245 
246  $ilToolbar->addFormButton($lng->txt("ok"), "short");
247 
248  if(sizeof($data["active"]))
249  {
250  $ilToolbar->addSeparator();
251  $ilToolbar->addFormButton($lng->txt("export"), "shortExport");
252  }
253 
254  $tpl->setContent($this->render($data, $scale, $measure));
255  }
256  else
257  {
258  $this->exportCSV($data, $scale);
259  }
260  }
261 
262  protected function shortExport()
263  {
264  $this->short(true);
265  }
266 
267  protected function long($a_export = false)
268  {
269  global $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
270 
271  $ilTabs->activateSubTab("long");
272 
273  // current start
274  $time_to = $this->importDate($_REQUEST["sst"]);
275 
276  // current mode
277  if(!$_REQUEST["smd"])
278  {
279  $_REQUEST["smd"] = self::MODE_WEEK;
280  }
281  $mode = (int)$_REQUEST["smd"];
282 
283  switch($mode)
284  {
285  case self::MODE_WEEK:
286  $time_from = $time_to-60*60*24*7;
287  $scale = self::SCALE_WEEK;
288  break;
289 
290  case self::MODE_MONTH:
291  $time_from = $time_to-60*60*24*30;
292  $scale = self::SCALE_MONTH;
293  break;
294 
295  case self::MODE_YEAR:
296  $time_from = $time_to-60*60*24*365;
297  $scale = self::SCALE_YEAR;
298  break;
299  }
300 
301  $mode_options = array(
302  self::MODE_WEEK => $lng->txt("trac_session_statistics_mode_week"),
303  self::MODE_MONTH => $lng->txt("trac_session_statistics_mode_month"),
304  self::MODE_YEAR => $lng->txt("trac_session_statistics_mode_year")
305  );
306 
307  $title = $lng->txt("trac_long_system_load")." - ".$mode_options[$mode];
308  $data = $this->buildData($time_from, $time_to, $title);
309 
310  if(!$a_export)
311  {
312  // toolbar
313  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
314  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "long"));
315 
316  $start_selector = new ilDateTimeInputGUI($lng->txt("trac_end_at"), "sst");
317  $start_selector->setDate(new ilDate($time_to, IL_CAL_UNIX));
318  $ilToolbar->addInputItem($start_selector, true);
319 
320  $mode_selector = new ilSelectInputGUI("&nbsp;".$lng->txt("trac_scale"), "smd");
321  $mode_selector->setOptions($mode_options);
322  $mode_selector->setValue($mode);
323  $ilToolbar->addInputItem($mode_selector, true);
324 
325  $ilToolbar->addFormButton($lng->txt("ok"), "long");
326 
327  if(sizeof($data["active"]))
328  {
329  $ilToolbar->addSeparator();
330  $ilToolbar->addFormButton($lng->txt("export"), "longExport");
331  }
332 
333  $tpl->setContent($this->render($data, $scale));
334  }
335  else
336  {
337  $this->exportCSV($data, $scale);
338  }
339  }
340 
341  protected function longExport()
342  {
343  $this->long(true);
344  }
345 
346  protected function periodic($a_export = false)
347  {
348  global $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
349 
350  $ilTabs->activateSubTab("periodic");
351 
352  // current start
353  $time_to = $this->importDate($_REQUEST["sst"]);
354 
355  // current end
356  $time_from = $this->importDate($_REQUEST["sto"], strtotime("-7 days"));
357 
358  // mixed up dates?
359  if($time_to < $time_from)
360  {
361  $tmp = $time_to;
362  $time_to = $time_from;
363  $time_from = $tmp;
364  }
365 
366  $title = $lng->txt("trac_periodic_system_load");
367  $data = $this->buildData($time_from, $time_to, $title);
368 
369  if(!$a_export)
370  {
371  // toolbar
372  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
373  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "periodic"));
374 
375  $end_selector = new ilDateTimeInputGUI($lng->txt("trac_begin_at"), "sto");
376  $end_selector->setDate(new ilDate($time_from, IL_CAL_UNIX));
377  $ilToolbar->addInputItem($end_selector, true);
378 
379  $start_selector = new ilDateTimeInputGUI($lng->txt("trac_end_at"), "sst");
380  $start_selector->setDate(new ilDate($time_to, IL_CAL_UNIX));
381  $ilToolbar->addInputItem($start_selector, true);
382 
383  $ilToolbar->addFormButton($lng->txt("ok"), "periodic");
384 
385  if(sizeof($data["active"]))
386  {
387  $ilToolbar->addSeparator();
388  $ilToolbar->addFormButton($lng->txt("export"), "periodicExport");
389  }
390 
391  $tpl->setContent($this->render($data, self::SCALE_PERIODIC_WEEK));
392  }
393  else
394  {
395  $this->exportCSV($data, self::SCALE_PERIODIC_WEEK);
396  }
397  }
398 
399  protected function periodicExport()
400  {
401  $this->periodic(true);
402  }
403 
404  protected function renderCurrentBasics()
405  {
406  global $ilSetting, $lng, $ilCtrl, $ilAccess;
407 
408  // basic data - not time related
409 
410  include_once "Services/Authentication/classes/class.ilSessionControl.php";
412 
413  $control_active = ($ilSetting->get('session_handling_type', 0) == 1);
414  if($control_active)
415  {
416  $control_max_sessions = (int)$ilSetting->get('session_max_count', ilSessionControl::DEFAULT_MAX_COUNT);
417  $control_min_idle = (int)$ilSetting->get('session_min_idle', ilSessionControl::DEFAULT_MIN_IDLE);
418  $control_max_idle = (int)$ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE);
419  $control_max_idle_first = (int)$ilSetting->get('session_max_idle_after_first_request', ilSessionControl::DEFAULT_MAX_IDLE_AFTER_FIRST_REQUEST);
420  }
421 
424 
425 
426  // build left column
427 
428  $left = new ilTemplate("tpl.session_statistics_left.html", true, true, "Services/Authentication");
429 
430  $left->setVariable("CAPTION_CURRENT", $lng->txt("users_online"));
431  $left->setVariable("VALUE_CURRENT", $active);
432 
433  $left->setVariable("CAPTION_LAST_AGGR", $lng->txt("trac_last_aggregation"));
434  $left->setVariable("VALUE_LAST_AGGR", ilDatePresentation::formatDate($last_aggr));
435 
436  $left->setVariable("CAPTION_LAST_MAX", $lng->txt("trac_last_maxed_out_sessions"));
437  $left->setVariable("VALUE_LAST_MAX", ilDatePresentation::formatDate($last_maxed_out));
438 
439  $left->setVariable("CAPTION_SESSION_CONTROL", $lng->txt("sess_load_dependent_session_handling"));
440  if(!$control_active)
441  {
442  $left->setVariable("VALUE_SESSION_CONTROL", $lng->txt("no"));
443  }
444  else
445  {
446  $left->setVariable("VALUE_SESSION_CONTROL", $lng->txt("yes"));
447 
448  $left->setCurrentBlock("control_details");
449 
450  $left->setVariable("CAPTION_SESSION_CONTROL_LIMIT", $lng->txt("session_max_count"));
451  $left->setVariable("VALUE_SESSION_CONTROL_LIMIT", $control_max_sessions);
452 
453  $left->setVariable("CAPTION_SESSION_CONTROL_IDLE_MIN", $lng->txt("session_min_idle"));
454  $left->setVariable("VALUE_SESSION_CONTROL_IDLE_MIN", $control_min_idle);
455 
456  $left->setVariable("CAPTION_SESSION_CONTROL_IDLE_MAX", $lng->txt("session_max_idle"));
457  $left->setVariable("VALUE_SESSION_CONTROL_IDLE_MAX", $control_max_idle);
458 
459  $left->setVariable("CAPTION_SESSION_CONTROL_IDLE_FIRST", $lng->txt("session_max_idle_after_first_request"));
460  $left->setVariable("VALUE_SESSION_CONTROL_IDLE_FIRST", $control_max_idle_first);
461 
462  $left->parseCurrentBlock();
463  }
464 
465  // sync button
466  if($ilAccess->checkAccess("write", "", (int)$_REQUEST["ref_id"]))
467  {
468  $left->setVariable("URL_SYNC", $ilCtrl->getFormAction($this, "adminSync"));
469  $left->setVariable("CMD_SYNC", "adminSync");
470  $left->setVariable("TXT_SYNC", $lng->txt("trac_sync_session_stats"));
471  }
472 
473  return $left->get();
474  }
475 
476  protected function buildData($a_time_from, $a_time_to, $a_title)
477  {
478  global $lng;
479 
480  // basic data - time related
481 
482  $maxed_out_duration = round(ilSessionStatistics::getMaxedOutDuration($a_time_from, $a_time_to)/60);
483  $counters = ilSessionStatistics::getNumberOfSessionsByType($a_time_from, $a_time_to);
484  $opened = (int)$counters["opened"];
485  $closed_limit = (int)$counters["closed_limit"];
486  unset($counters["opened"]);
487  unset($counters["closed_limit"]);
488 
489 
490  // build center column
491 
492  $data = array();
493 
495  $data["title"] = $a_title." (".
497  new ilDateTime($a_time_to, IL_CAL_UNIX)).")";
498 
499  $data["maxed_out_time"] = array($lng->txt("trac_maxed_out_time"), $maxed_out_duration);
500  $data["maxed_out_counter"] = array($lng->txt("trac_maxed_out_counter"), $closed_limit);
501  $data["opened"] = array($lng->txt("trac_sessions_opened"), $opened);
502  $data["closed"] = array($lng->txt("trac_sessions_closed"), array_sum($counters));
503  foreach($counters as $type => $counter)
504  {
505  $data["closed_details"][] = array($lng->txt("trac_".$type), (int)$counter);
506  }
507 
508  $data["active"] = ilSessionStatistics::getActiveSessions($a_time_from, $a_time_to);
509 
510  return $data;
511  }
512 
513  protected function render($a_data, $a_scale, $a_measure = null)
514  {
515  global $lng;
516 
517  $center = new ilTemplate("tpl.session_statistics_center.html", true, true, "Services/Authentication");
518 
519  foreach($a_data as $idx => $item)
520  {
521  switch($idx)
522  {
523  case "active":
524  case "title":
525  // nothing to do
526  break;
527 
528  case "closed_details":
529  $center->setCurrentBlock("closed_details");
530  foreach($item as $detail)
531  {
532  $center->setVariable("CAPTION_CLOSED_DETAILS", $detail[0]);
533  $center->setVariable("VALUE_CLOSED_DETAILS", $detail[1]);
534  $center->parseCurrentBlock();
535  }
536  break;
537 
538  default:
539  $tpl_var = strtoupper($idx);
540  $center->setVariable("CAPTION_".$tpl_var, $item[0]);
541  $center->setVariable("VALUE_".$tpl_var, $item[1]);
542  break;
543  }
544  }
545 
546  if($a_data["active"])
547  {
548  $center->setVariable("CHART", $this->getChart($a_data["active"], $a_data["title"], $a_scale, $a_measure));
549  }
550  else
551  {
552  ilUtil::sendInfo($lng->txt("trac_session_statistics_no_data"));
553  }
554 
555  return $center->get();
556  }
557 
567  protected function getChart($a_data, $a_title, $a_scale = self::SCALE_DAY, $a_measure = null)
568  {
569  global $lng;
570 
571  include_once "Services/Chart/classes/class.ilChart.php";
573  $chart->setsize(700, 500);
574  $chart->setYAxisToInteger(true);
575 
576  $legend = new ilChartLegend();
577  $chart->setLegend($legend);
578 
579  if(!$a_measure)
580  {
581  $a_measure = array("min", "avg", "max");
582  }
583  else if(!is_array($a_measure))
584  {
585  $a_measure = array($a_measure);
586  }
587 
588  $colors_map = array("min" => "#00cc00",
589  "avg" => "#0000cc",
590  "max" => "#cc00cc");
591 
592  $colors = $act_line = array();
593  foreach($a_measure as $measure)
594  {
595  $act_line[$measure] = $chart->getDataInstance(ilChartGrid::DATA_LINES);
596  $act_line[$measure]->setLineSteps(true);
597  $act_line[$measure]->setLabel($lng->txt("trac_session_active_".$measure));
598  $colors[] = $colors_map[$measure];
599  }
600 
601  if($a_scale != self::SCALE_PERIODIC_WEEK)
602  {
603  $max_line = $chart->getDataInstance(ilChartGrid::DATA_LINES);
604  $max_line->setLabel($lng->txt("session_max_count"));
605  $colors[] = "#cc0000";
606  }
607 
608  $chart->setColors($colors);
609 
610  $chart_data = $this->adaptDataToScale($a_scale, $a_data, 700);
611  unset($a_data);
612 
613  $scale = ceil(sizeof($chart_data)/5);
614  $labels = array();
615  foreach($chart_data as $idx => $item)
616  {
617  $date = $item["slot_begin"];
618 
619  if($a_scale == self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale)))
620  {
621  switch($a_scale)
622  {
623  case self::SCALE_DAY:
624  $labels[$date] = date("H:i", $date);
625  break;
626 
627  case self::SCALE_WEEK:
628  $labels[$date] = date("d.m. H", $date)."h";
629  break;
630 
631  case self::SCALE_MONTH:
632  $labels[$date] = date("d.m.", $date);
633  break;
634 
635  case self::SCALE_YEAR:
636  $labels[$date] = date("Y-m", $date);
637  break;
638 
639  case self::SCALE_PERIODIC_WEEK:
640  $day = substr($date, 0, 1);
641  $hour = substr($date, 1, 2);
642  $min = substr($date, 3, 2);
643 
644  // build ascending scale from day values
645  $day_value = ($day-1)*60*60*24;
646  $date = $day_value+$hour*60*60+$min*60;
647 
648  // 6-hour interval labels
649  if($hour != $old_hour && $hour && $hour%6 == 0)
650  {
651  $labels[$date] = $hour;
652  $old_hour = $hour;
653  }
654  // day label
655  if($day != $old_day)
656  {
657  $labels[$date] = ilCalendarUtil::_numericDayToString($day, false);
658  $old_day = $day;
659  }
660  break;
661  }
662  }
663 
664  foreach($a_measure as $measure)
665  {
666  $value = (int)$item["active_".$measure];
667  $act_line[$measure]->addPoint($date, $value);
668  }
669 
670  if($a_scale != self::SCALE_PERIODIC_WEEK)
671  {
672  $max_line->addPoint($date, (int)$item["max_sessions"]);
673  }
674  }
675 
676  foreach($act_line as $line)
677  {
678  $chart->addData($line);
679  }
680  if($a_scale != self::SCALE_PERIODIC_WEEK)
681  {
682  $chart->addData($max_line);
683  }
684 
685  $chart->setTicks($labels, null, true);
686 
687  return $chart->getHTML();
688  }
689 
690  protected function adaptDataToScale($a_scale, array $a_data)
691  {
692  // can we use original data?
693  switch($a_scale)
694  {
695  case self::SCALE_DAY:
696  // 96 values => ok
697  // fallthrough
698 
699  case self::SCALE_WEEK:
700  // 672 values => ok
701  return $a_data;
702  }
703 
704  $tmp = array();
705  foreach($a_data as $item)
706  {
707  $date_parts = getdate($item["slot_begin"]);
708 
709  // aggregate slots for scale
710  switch($a_scale)
711  {
712  case self::SCALE_MONTH:
713  // aggregate to hours => 720 values
714  $slot = mktime($date_parts["hours"], 0, 0, $date_parts["mon"], $date_parts["mday"], $date_parts["year"]);
715  break;
716 
717  case self::SCALE_YEAR:
718  // aggregate to days => 365 values
719  $slot = mktime(0, 0, 1, $date_parts["mon"], $date_parts["mday"], $date_parts["year"]);
720  break;
721 
722  case self::SCALE_PERIODIC_WEEK:
723  // aggregate to weekdays => 672 values
724  $day = $date_parts["wday"];
725  if(!$day)
726  {
727  $day = 7;
728  }
729  $slot = $day.date("His", $item["slot_begin"]);
730  break;
731  }
732 
733  // process minx/max, prepare avg
734  foreach($item as $id => $value)
735  {
736  switch(substr($id, -3))
737  {
738  case "min":
739  if(!$tmp[$slot][$id] || $value < $tmp[$slot][$id])
740  {
741  $tmp[$slot][$id] = $value;
742  }
743  break;
744 
745  case "max":
746  if(!$tmp[$slot][$id] || $value > $tmp[$slot][$id])
747  {
748  $tmp[$slot][$id] = $value;
749  }
750  break;
751 
752  case "avg":
753  $tmp[$slot][$id][] = $value;
754  break;
755  }
756  }
757  }
758 
759  foreach($tmp as $slot => $attr)
760  {
761  $tmp[$slot]["active_avg"] = (int)round(array_sum($attr["active_avg"])/sizeof($attr["active_avg"]));
762  $tmp[$slot]["slot_begin"] = $slot;
763  }
764  ksort($tmp);
765  return array_values($tmp);
766  }
767 
768  protected function adminSync()
769  {
770  global $ilCtrl, $lng;
771 
772  // see ilSession::_writeData()
773  $now = time();
776 
777  ilUtil::sendSuccess($lng->txt("trac_sync_session_stats_success"), true);
778  $ilCtrl->redirect($this);
779  }
780 
781  protected function exportCSV(array $a_data, $a_scale)
782  {
783  global $lng, $ilClientIniFile, $ilUser;
784 
786  include_once './Services/Link/classes/class.ilLink.php';
787 
788  include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
789  $csv = new ilCSVWriter();
790  $csv->setSeparator(";");
791 
792  $now = time();
793 
794  // meta
795  $meta = array(
796  $lng->txt("trac_name_of_installation") => $ilClientIniFile->readVariable('client', 'name'),
797  $lng->txt("trac_report_date") =>
799  $lng->txt("trac_report_owner") => $ilUser->getFullName(),
800  );
801  foreach($a_data as $idx => $item)
802  {
803  switch($idx)
804  {
805  case "title":
806  $meta[$lng->txt("title")] = $item;
807  break;
808 
809  case "active":
810  // nothing to do
811  break;
812 
813  case "closed_details":
814  foreach($item as $detail)
815  {
816  $meta[$a_data["closed"][0]." - ".$detail[0]] = $detail[1];
817  }
818  break;
819 
820  default:
821  $meta[$item[0]] = $item[1];
822  break;
823  }
824  }
825  foreach($meta as $caption => $value)
826  {
827  $csv->addColumn(strip_tags($caption));
828  $csv->addColumn(strip_tags($value));
829  $csv->addRow();
830  }
831  $csv->addRow();
832 
833  // aggregate data
834  $aggr_data = $this->adaptDataToScale($a_scale, $a_data["active"], 700);
835  unset($a_data);
836 
837  // header
838  $first = $aggr_data;
839  $first = array_keys(array_shift($first));
840  foreach ($first as $column)
841  {
842  // split weekday and time slot again
843  if($a_scale == self::SCALE_PERIODIC_WEEK && $column == "slot_begin")
844  {
845  $csv->addColumn("weekday");
846  $csv->addColumn("time");
847  }
848  else
849  {
850  $csv->addColumn(strip_tags($column));
851  }
852  }
853  $csv->addRow();
854 
855  // data
856  foreach($aggr_data as $row)
857  {
858  foreach ($row as $column => $value)
859  {
860  if(is_array($value))
861  {
862  $value = implode(', ', $value);
863  }
864  switch($column)
865  {
866  case "slot_begin":
867  // split weekday and time slot again
868  if($a_scale == self::SCALE_PERIODIC_WEEK)
869  {
870  $csv->addColumn(ilCalendarUtil::_numericDayToString(substr($value, 0, 1)));
871  $value = substr($value, 1, 2).":".substr($value, 3, 2);
872  break;
873  }
874  // fallthrough
875 
876  case "slot_end":
877  $value = date("d.m.Y H:i", $value);
878  break;
879  }
880  $csv->addColumn(strip_tags($value));
881  }
882  $csv->addRow();
883  }
884 
885  // send
886  $filename .= "session_statistics_".date("Ymd", $now).".csv";
887  header("Content-type: text/comma-separated-values");
888  header("Content-Disposition: attachment; filename=\"".$filename."\"");
889  header("Expires: 0");
890  header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
891  header("Pragma: public");
892  echo $csv->getCSVString();
893  exit();
894  }
895 }
896 
897 ?>
Class ilSessionStatisticsGUI.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
exportCSV(array $a_data, $a_scale)
static getMaxedOutDuration($a_from, $a_to)
Get maxed out duration in given timeframe.
const IL_CAL_DATETIME
Helper class to generate CSV files.
This class represents a selection list property in a property form.
static _numericDayToString($a_day, $a_long=true)
get
Chart legend.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
$cmd
Definition: sahs_server.php:35
static setUseRelativeDates($a_status)
set use relative dates
Add rich text string
The name of the decorator.
static getNumberOfSessionsByType($a_from, $a_to)
Get session counters by type (opened, closed)
const IL_CAL_UNIX
setDate(ilDateTime $a_date=NULL)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
static _destroyExpiredSessions()
Destroy expired sessions.
importDate($a_incoming, $a_default=null)
This class represents a date/time property in a property form.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
render($a_data, $a_scale, $a_measure=null)
static getLastAggregation()
Get timestamp of last aggregation.
$column
Definition: 39dropdown.php:62
Class for single dates.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
special template class to simplify handling of ITX/PEAR
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
$ilUser
Definition: imgupload.php:18
Add a drawing to the header
Definition: 04printing.php:69
setOptions($a_options)
Set Options.
Create styles array
The data for the language used.
const TYPE_GRID
static getExistingSessionCount(array $a_types)
returns number of valid sessions relating to given session types
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
adaptDataToScale($a_scale, array $a_data)
getChart($a_data, $a_title, $a_scale=self::SCALE_DAY, $a_measure=null)
Build chart for active sessions.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getLastMaxedOut()
Get latest slot during which sessions were maxed out.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
buildData($a_time_from, $a_time_to, $a_title)
static getInstanceByType($a_type, $a_id)
Get type instance.
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static getActiveSessions($a_from, $a_to)
Get active sessions aggregated data.