19 declare(strict_types=1);
    60     private ?
string $smm = null;
    61     private ?
string $sst = null;
    62     private ?
string $sto = null;
    68         $this->
ilCtrl = $DIC->ctrl();
    69         $this->ilTabs = $DIC->tabs();
    70         $this->
lng = $DIC->language();
    71         $this->tpl = $DIC->ui()->mainTemplate();
    72         $this->
toolbar = $DIC->toolbar();
    74         $this->
access = $DIC->access();
    75         $this->clientIniFile = $DIC->clientIni();
    76         $this->
user = $DIC->user();
    77         $this->
logger = $DIC->logger()->auth();
    80         $kindlyTo = $DIC->refinery()->kindlyTo();
    81         if (
$http->request()->getMethod() === 
"POST") {
    82             if (
$http->wrapper()->post()->has(self::REQUEST_SMD)) {
    83                 $this->smd = 
$http->wrapper()->post()->retrieve(self::REQUEST_SMD, $kindlyTo->int());
    85             if (
$http->wrapper()->post()->has(self::REQUEST_SMM)) {
    86                 $this->smm = 
$http->wrapper()->post()->retrieve(self::REQUEST_SMM, $kindlyTo->string());
    88             if (
$http->wrapper()->post()->has(self::REQUEST_STO)) {
    89                 $this->sto = 
$http->wrapper()->post()->retrieve(self::REQUEST_STO, $kindlyTo->string());
    91             if (
$http->wrapper()->post()->has(self::REQUEST_SST)) {
    92                 $this->sst = 
$http->wrapper()->post()->retrieve(self::REQUEST_SST, $kindlyTo->string());
    95             if (
$http->wrapper()->query()->has(self::REQUEST_SMD)) {
    96                 $this->smd = 
$http->wrapper()->query()->retrieve(self::REQUEST_SMD, $kindlyTo->int());
    98             if (
$http->wrapper()->query()->has(self::REQUEST_SMM)) {
    99                 $this->smm = 
$http->wrapper()->query()->retrieve(self::REQUEST_SMM, $kindlyTo->string());
   101             if (
$http->wrapper()->query()->has(self::REQUEST_STO)) {
   102                 $this->sto = 
$http->wrapper()->query()->retrieve(self::REQUEST_STO, $kindlyTo->string());
   104             if (
$http->wrapper()->query()->has(self::REQUEST_SST)) {
   105                 $this->sst = 
$http->wrapper()->query()->retrieve(self::REQUEST_SST, $kindlyTo->string());
   108         if (
$http->wrapper()->query()->has(self::REQUEST_REF)) {
   109             $this->ref_id = 
$http->wrapper()->query()->retrieve(self::REQUEST_REF, $kindlyTo->int());
   117         switch ($this->
ilCtrl->getNextClass()) {
   119                 $cmd = $this->
ilCtrl->getCmd(
"current");
   128         $this->ilTabs->addSubTab(
   130             $this->
lng->txt(
"trac_current_system_load"),
   131             $this->
ilCtrl->getLinkTarget($this, 
"current")
   133         $this->ilTabs->addSubTab(
   135             $this->
lng->txt(
"trac_short_system_load"),
   136             $this->
ilCtrl->getLinkTarget($this, 
"short")
   138         $this->ilTabs->addSubTab(
   140             $this->
lng->txt(
"trac_long_system_load"),
   141             $this->
ilCtrl->getLinkTarget($this, 
"long")
   143         $this->ilTabs->addSubTab(
   145             $this->
lng->txt(
"trac_periodic_system_load"),
   146             $this->
ilCtrl->getLinkTarget($this, 
"periodic")
   150     protected function current(
bool $a_export = 
false): void
   152         $this->ilTabs->activateSubTab(
"current");
   156             $mode = self::MODE_TODAY;
   170             case self::MODE_TODAY:
   171                 $time_from = strtotime(
"today");
   172                 $time_to = strtotime(
"tomorrow") - 1;
   173                 $scale = self::SCALE_DAY;
   176             case self::MODE_LAST_DAY:
   178                 $time_from = $time_to - 60 * 60 * 24;
   179                 $scale = self::SCALE_DAY;
   182             case self::MODE_LAST_WEEK:
   184                 $time_from = $time_to - 60 * 60 * 24 * 7;
   185                 $scale = self::SCALE_WEEK;
   188             case self::MODE_LAST_MONTH:
   190                 $time_from = $time_to - 60 * 60 * 24 * 30;
   191                 $scale = self::SCALE_MONTH;
   195         $mode_options = array(
   196             self::MODE_TODAY => $this->
lng->txt(
"trac_session_statistics_mode_today"),
   197             self::MODE_LAST_DAY => $this->
lng->txt(
"trac_session_statistics_mode_last_day"),
   198             self::MODE_LAST_WEEK => $this->
lng->txt(
"trac_session_statistics_mode_last_week"),
   199             self::MODE_LAST_MONTH => $this->
lng->txt(
"trac_session_statistics_mode_last_month"));
   201         $title = $this->
lng->txt(
"trac_current_system_load") . 
" - " . $mode_options[$mode];
   206             $this->
toolbar->setFormAction($this->
ilCtrl->getFormAction($this, 
"current"));
   210             $mode_selector->setValue($mode);
   211             $this->
toolbar->addInputItem($mode_selector, 
true);
   213             $measure_options = array(
   214                 "avg" => $this->
lng->txt(
"trac_session_active_avg"),
   215                 "min" => $this->
lng->txt(
"trac_session_active_min"),
   216                 "max" => $this->
lng->txt(
"trac_session_active_max"));
   218             $measure_selector = 
new ilSelectInputGUI(
" " . $this->
lng->txt(
"trac_measure"), 
"smm");
   219             $measure_selector->
setOptions($measure_options);
   220             $measure_selector->setValue($measure);
   221             $this->
toolbar->addInputItem($measure_selector, 
true);
   223             $this->
toolbar->addFormButton($this->
lng->txt(
"ok"), 
"current");
   225             if (count(
$data[
"active"])) {
   226                 $this->
toolbar->addSeparator();
   227                 $this->
toolbar->addFormButton($this->
lng->txt(
"export"), 
"currentExport");
   230             $this->tpl->setContent($this->
render(
$data, $scale, $measure));
   246     protected function importDate(
string $a_incoming, 
int $a_default = null)
   258     protected function short(
bool $a_export = 
false): void
   260         $this->ilTabs->activateSubTab(
"short");
   264         $time_to = $this->
importDate((
string) $this->sst);
   268             $mode = self::MODE_DAY;
   283                 $time_from = $time_to - 60 * 60 * 24;
   284                 $scale = self::SCALE_DAY;
   287             case self::MODE_WEEK:
   288                 $time_from = $time_to - 60 * 60 * 24 * 7;
   289                 $scale = self::SCALE_WEEK;
   293         $mode_options = array(
   294                 self::MODE_DAY => $this->
lng->txt(
"trac_session_statistics_mode_day"),
   295                 self::MODE_WEEK => $this->
lng->txt(
"trac_session_statistics_mode_week")
   298         $title = $this->
lng->txt(
"trac_short_system_load") . 
" - " . $mode_options[$mode];
   303             $this->
toolbar->setFormAction($this->
ilCtrl->getFormAction($this, 
"short"));
   307             $this->
toolbar->addInputItem($start_selector, 
true);
   311             $mode_selector->setValue($mode);
   312             $this->
toolbar->addInputItem($mode_selector, 
true);
   314             $measure_options = array(
   315                 "avg" => $this->
lng->txt(
"trac_session_active_avg"),
   316                 "min" => $this->
lng->txt(
"trac_session_active_min"),
   317                 "max" => $this->
lng->txt(
"trac_session_active_max"));
   319             $measure_selector = 
new ilSelectInputGUI(
" " . $this->
lng->txt(
"trac_measure"), 
"smm");
   320             $measure_selector->
setOptions($measure_options);
   321             $measure_selector->setValue($measure);
   322             $this->
toolbar->addInputItem($measure_selector, 
true);
   324             $this->
toolbar->addFormButton($this->
lng->txt(
"ok"), 
"short");
   326             if (count(
$data[
"active"])) {
   327                 $this->
toolbar->addSeparator();
   328                 $this->
toolbar->addFormButton($this->
lng->txt(
"export"), 
"shortExport");
   331             $this->tpl->setContent($this->
render(
$data, $scale, $measure));
   342     protected function long($a_export = 
false): void
   344         $this->ilTabs->activateSubTab(
"long");
   348         $time_to = $this->
importDate((
string) $this->sst);
   352             $mode = self::MODE_WEEK;
   359             case self::MODE_WEEK:
   360                 $time_from = $time_to - 60 * 60 * 24 * 7;
   361                 $scale = self::SCALE_WEEK;
   364             case self::MODE_MONTH:
   365                 $time_from = $time_to - 60 * 60 * 24 * 30;
   366                 $scale = self::SCALE_MONTH;
   369             case self::MODE_YEAR:
   370                 $time_from = $time_to - 60 * 60 * 24 * 365;
   371                 $scale = self::SCALE_YEAR;
   375         $mode_options = array(
   376                 self::MODE_WEEK => $this->
lng->txt(
"trac_session_statistics_mode_week"),
   377                 self::MODE_MONTH => $this->
lng->txt(
"trac_session_statistics_mode_month"),
   378                 self::MODE_YEAR => $this->
lng->txt(
"trac_session_statistics_mode_year")
   381         $title = $this->
lng->txt(
"trac_long_system_load") . 
" - " . $mode_options[$mode];
   386             $this->
toolbar->setFormAction($this->
ilCtrl->getFormAction($this, 
"long"));
   390             $this->
toolbar->addInputItem($start_selector, 
true);
   394             $mode_selector->setValue($mode);
   395             $this->
toolbar->addInputItem($mode_selector, 
true);
   397             $this->
toolbar->addFormButton($this->
lng->txt(
"ok"), 
"long");
   399             if (count(
$data[
"active"])) {
   400                 $this->
toolbar->addSeparator();
   401                 $this->
toolbar->addFormButton($this->
lng->txt(
"export"), 
"longExport");
   404             $this->tpl->setContent($this->
render(
$data, $scale));
   415     protected function periodic($a_export = 
false): void
   417         $this->ilTabs->activateSubTab(
"periodic");
   421         $time_to = $this->
importDate((
string) $this->sst);
   424         $time_from = $this->
importDate((
string) $this->sto, strtotime(
"-7 days"));
   427         if ($time_to < $time_from) {
   429             $time_to = $time_from;
   433         $title = $this->
lng->txt(
"trac_periodic_system_load");
   438             $this->
toolbar->setFormAction($this->
ilCtrl->getFormAction($this, 
"periodic"));
   442             $this->
toolbar->addInputItem($end_selector, 
true);
   446             $this->
toolbar->addInputItem($start_selector, 
true);
   448             $this->
toolbar->addFormButton($this->
lng->txt(
"ok"), 
"periodic");
   450             if (count(
$data[
"active"])) {
   451                 $this->
toolbar->addSeparator();
   452                 $this->
toolbar->addFormButton($this->
lng->txt(
"export"), 
"periodicExport");
   455             $this->tpl->setContent($this->
render(
$data, self::SCALE_PERIODIC_WEEK));
   477         $left = 
new ilTemplate(
"tpl.session_statistics_left.html", 
true, 
true, 
"components/ILIAS/Authentication");
   479         $left->setVariable(
"CAPTION_CURRENT", $this->
lng->txt(
"users_online"));
   480         $left->setVariable(
"VALUE_CURRENT", $active);
   482         $left->setVariable(
"CAPTION_LAST_AGGR", $this->
lng->txt(
"trac_last_aggregation"));
   486         if ($this->
access->checkAccess(
"write", 
"", $this->ref_id)) {
   487             $left->setVariable(
"URL_SYNC", $this->
ilCtrl->getFormAction($this, 
"adminSync"));
   488             $left->setVariable(
"CMD_SYNC", 
"adminSync");
   489             $left->setVariable(
"TXT_SYNC", $this->
lng->txt(
"trac_sync_session_stats"));
   495     protected function buildData(
int $a_time_from, 
int $a_time_to, 
string $a_title): array
   500         $opened = (
int) $counters[
"opened"];
   501         unset($counters[
"opened"]);
   509         $data[
"title"] = $a_title . 
" (" .
   515         $data[
"opened"] = array($this->
lng->txt(
"trac_sessions_opened"), $opened);
   516         $data[
"closed"] = array($this->
lng->txt(
"trac_sessions_closed"), array_sum($counters));
   517         foreach ($counters as $type => $counter) {
   518             $data[
"closed_details"][] = array($this->
lng->txt(
"trac_" . $type), (
int) $counter);
   521         $data[
"active"] = ilSessionStatistics::getActiveSessions($a_time_from, $a_time_to);
   522         $this->
logger->debug(
"Data to plot: " . var_export($data, 
true));
   526     protected function render(array $a_data, 
int $a_scale, 
string $a_measure = null): string
   528         $center = 
new ilTemplate(
"tpl.session_statistics_center.html", 
true, 
true, 
"components/ILIAS/Authentication");
   530         foreach ($a_data as $idx => $item) {
   537                 case "closed_details":
   538                     $center->setCurrentBlock(
"closed_details");
   539                     foreach ($item as $detail) {
   540                         $center->setVariable(
"CAPTION_CLOSED_DETAILS", $detail[0]);
   541                         $center->setVariable(
"VALUE_CLOSED_DETAILS", $detail[1]);
   542                         $center->parseCurrentBlock();
   547                     $tpl_var = strtoupper($idx);
   548                     $center->setVariable(
"CAPTION_" . $tpl_var, $item[0]);
   549                     $center->setVariable(
"VALUE_" . $tpl_var, $item[1]);
   554         if ($a_data[
"active"]) {
   555             $center->setVariable(
"CHART", $this->
getChart($a_data[
"active"], $a_data[
"title"], $a_scale, $a_measure));
   557             $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"trac_session_statistics_no_data"));
   560         return $center->get();
   566     protected function getChart(array $a_data, 
string $a_title, 
int $a_scale = self::SCALE_DAY, 
string $a_measure = null): string
   569         $chart->setSize(
"700", 
"500");
   570         $chart->setYAxisToInteger(
true);
   573         $chart->setLegend($legend);
   576             $measures = [
"min", 
"avg", 
"max"];
   578             $measures = [$a_measure];
   581         $colors_map = array(
"min" => 
"#00cc00",
   585         $colors = $act_line = array();
   586         foreach ($measures as $measure) {
   588             $act_line[$measure]->setLineSteps(
true);
   589             $act_line[$measure]->setLabel($this->
lng->txt(
"trac_session_active_" . $measure));
   590             $colors[] = $colors_map[$measure];
   593         $chart->setColors($colors);
   597         $scale = ceil(count($chart_data) / 5);
   599         foreach ($chart_data as $idx => $item) {
   600             $date = $item[
"slot_begin"];
   602             if ($a_scale === self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale))) {
   604                     case self::SCALE_DAY:
   605                         $labels[$date] = date(
"H:i", $date);
   608                     case self::SCALE_WEEK:
   609                         $labels[$date] = date(
"d.m. H", $date) . 
"h";
   612                     case self::SCALE_MONTH:
   613                         $labels[$date] = date(
"d.m.", $date);
   616                     case self::SCALE_YEAR:
   617                         $labels[$date] = date(
"Y-m", $date);
   620                     case self::SCALE_PERIODIC_WEEK:
   621                         $day = substr((
string) $date, 0, 1);
   622                         $hour = substr((
string) $date, 1, 2);
   623                         $min = substr((
string) $date, 3, 2);
   626                         $day_value = ($day - 1) * 60 * 60 * 24;
   627                         $date = $day_value + $hour * 60 * 60 + $min * 60;
   630                         if ((!isset($old_hour) || $hour != $old_hour) && $hour && $hour % 6 == 0) {
   631                             $labels[$date] = $hour;
   635                         if (!isset($old_day) || $day != $old_day) {
   643             foreach ($measures as $measure) {
   644                 $value = (
int) $item[
"active_" . $measure];
   645                 $act_line[$measure]->addPoint($date, $value);
   649         foreach ($act_line as $line) {
   650             $chart->addData($line);
   653         $chart->setTicks($labels, null, 
true);
   655         return $chart->getHTML();
   662             case self::SCALE_DAY:
   666             case self::SCALE_WEEK:
   672         foreach ($a_data as $item) {
   673             $date_parts = getdate($item[
"slot_begin"]);
   678                 case self::SCALE_MONTH:
   680                     $slot = mktime($date_parts[
"hours"], 0, 0, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
   683                 case self::SCALE_YEAR:
   685                     $slot = mktime(0, 0, 1, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
   688                 case self::SCALE_PERIODIC_WEEK:
   690                     $day = $date_parts[
"wday"];
   694                     $slot = $day . date(
"His", $item[
"slot_begin"]);
   699             foreach ($item as 
$id => $value) {
   700                 switch (substr((
string) 
$id, -3)) {
   702                         if (!isset($tmp[$slot][$id]) || $value < $tmp[$slot][$id]) {
   703                             $tmp[$slot][
$id] = $value;
   708                         if (!isset($tmp[$slot][$id]) || $value > $tmp[$slot][$id]) {
   709                             $tmp[$slot][
$id] = $value;
   714                         $tmp[$slot][
$id][] = $value;
   720         foreach ($tmp as $slot => $attr) {
   721             $tmp[$slot][
"active_avg"] = (
int) round(array_sum($attr[
"active_avg"]) / count($attr[
"active_avg"]));
   722             $tmp[$slot][
"slot_begin"] = $slot;
   725         return array_values($tmp);
   735         $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"trac_sync_session_stats_success"), 
true);
   736         $this->
ilCtrl->redirect($this);
   739     protected function exportCSV(array $a_data, $a_scale): void
   744         $csv->setSeparator(
";");
   750             $this->
lng->txt(
"trac_name_of_installation") => $this->clientIniFile->readVariable(
'client', 
'name'),
   752             $this->
lng->txt(
"trac_report_owner") => $this->
user->getFullName(),
   754         foreach ($a_data as $idx => $item) {
   757                     $meta[$this->
lng->txt(
"title")] = $item;
   764                 case "closed_details":
   765                     foreach ($item as $detail) {
   766                         $meta[$a_data[
"closed"][0] . 
" - " . $detail[0]] = $detail[1];
   771                     $meta[$item[0]] = $item[1];
   775         foreach ($meta as $caption => $value) {
   776             $csv->addColumn(strip_tags((
string) $caption));
   777             $csv->addColumn(strip_tags((
string) $value));
   787         $first = array_keys(array_shift($first));
   788         foreach ($first as $column) {
   790             if ($a_scale === self::SCALE_PERIODIC_WEEK && $column === 
"slot_begin") {
   791                 $csv->addColumn(
"weekday");
   792                 $csv->addColumn(
"time");
   794                 $csv->addColumn(strip_tags((
string) $column));
   800         foreach ($aggr_data as $row) {
   801             foreach ($row as $column => $value) {
   802                 if (is_array($value)) {
   803                     $value = implode(
', ', $value);
   808                         if ($a_scale === self::SCALE_PERIODIC_WEEK) {
   810                             $value = substr((
string) $value, 1, 2) . 
":" . substr((
string) $value, 3, 2);
   817                         $value = date(
"d.m.Y H:i", $value);
   820                 $csv->addColumn(strip_tags((
string) $value));
   826         $filename = 
"session_statistics_" . date(
"Ymd", $now) . 
".csv";
   827         header(
"Content-type: text/comma-separated-values");
   828         header(
"Content-Disposition: attachment; filename=\"" . 
$filename . 
"\"");
   830         header(
"Cache-Control: must-revalidate, post-check=0,pre-check=0");
   832         echo $csv->getCSVString();
 
static array static setUseRelativeDates(bool $a_status)
set use relative dates 
 
exportCSV(array $a_data, $a_scale)
 
static getNumberOfSessionsByType(int $a_from, int $a_to)
Get session counters by type (opened, closed) 
 
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
 
static parseIncomingDate($value, bool $add_time=false)
Try to parse incoming value to date object. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
const SCALE_PERIODIC_WEEK
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
render(array $a_data, int $a_scale, string $a_measure=null)
 
static _destroyExpiredSessions()
Destroy expired sessions. 
 
static aggretateRaw(int $a_now)
Aggregate raw session data (older than given time) 
 
getChart(array $a_data, string $a_title, int $a_scale=self::SCALE_DAY, string $a_measure=null)
Build chart for active sessions. 
 
adaptDataToScale(int $a_scale, array $a_data)
 
ilGlobalTemplateInterface $tpl
 
static getLastAggregation()
Get timestamp of last aggregation. 
 
importDate(string $a_incoming, int $a_default=null)
 
static getExistingSessionCount(array $a_types)
returns number of valid sessions relating to given session types 
 
static array $session_types_controlled
 
static _numericDayToString(int $a_day, bool $a_long=true, ilLanguage $lng=null)
 
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ilObjUser $user=null)
Format a period of two dates Shows: 14. 
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
current(bool $a_export=false)
 
periodic($a_export=false)
 
short(bool $a_export=false)
 
buildData(int $a_time_from, int $a_time_to, string $a_title)
 
static getInstanceByType(int $a_type, string $a_id)