ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
BaseRule.php
Go to the documentation of this file.
1<?php
2/*
3 * @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
4 * @package SimpleSAMLphp
5 */
7{
8 protected $statconfig;
9 protected $ruleconfig;
10 protected $ruleid;
11 protected $available;
12
17 {
18 assert('$statconfig instanceof SimpleSAML_Configuration');
19 assert('$ruleconfig instanceof SimpleSAML_Configuration');
20 $this->statconfig = $statconfig;
21 $this->ruleconfig = $ruleconfig;
22 $this->ruleid = $ruleid;
23
24 $this->available = null;
25 if (array_key_exists($ruleid, $available)) {
26 $this->available = $available[$ruleid];
27 }
28 }
29
30 public function getRuleID()
31 {
32 return $this->ruleid;
33 }
34
35 public function availableTimeRes() {
36 $timeresConfigs = $this->statconfig->getValue('timeres');
37 $available_times = array();
38 foreach ($timeresConfigs as $tres => $tresconfig) {
39 if (array_key_exists($tres, $this->available)) {
40 $available_times[$tres] = $tresconfig['name'];
41 }
42 }
43 return $available_times;
44 }
45
47 {
48 $timeresConfigs = $this->statconfig->getValue('timeres');
49 $timeresConfig = $timeresConfigs[$timeres];
50
51 if (isset($timeresConfig['customDateHandler']) && $timeresConfig['customDateHandler'] == 'month') {
52 $datehandler = new sspmod_statistics_DateHandlerMonth(0);
53 } else {
54 $datehandler = new sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
55 }
56
57 /*
58 * Get list of avaiable times in current file (rule)
59 */
60 $available_times = array();
61 foreach ($this->available[$timeres] as $slot) {
62 $available_times[$slot] = $datehandler->prettyHeader($slot, $slot + 1, $timeresConfig['fileslot'], $timeresConfig['dateformat-period']);
63 }
64 return $available_times;
65 }
66
67 protected function resolveTimeRes($preferTimeRes)
68 {
69 $timeresavailable = array_keys($this->available);
70 $timeres = $timeresavailable[0];
71
72 // Then check if the user have provided one that is valid
73 if (in_array($preferTimeRes, $timeresavailable, true)) {
75 }
76 return $timeres;
77 }
78
80 {
81 // Get which time (fileslot) to use.. First get a default, which is the most recent one.
82 $fileslot = $this->available[$timeres][count($this->available[$timeres]) - 1];
83 // Then check if the user have provided one.
84 if (in_array($preferTime, $this->available[$timeres], true)) {
86 }
87 return $fileslot;
88 }
89
91 {
93
94 // Extract previous and next time slots...
95 $available_times_prev = null;
96 $available_times_next = null;
97
98 $timeslots = array_values($this->available[$timeres]);
99 sort($timeslots, SORT_NUMERIC);
100 $timeslotindex = array_flip($timeslots);
101
102 if ($timeslotindex[$fileslot] > 0) {
103 $available_times_prev = $timeslots[$timeslotindex[$fileslot] - 1];
104 }
105 if ($timeslotindex[$fileslot] < (count($timeslotindex) - 1)) {
106 $available_times_next = $timeslots[$timeslotindex[$fileslot] + 1];
107 }
108 return array('prev' => $available_times_prev, 'next' => $available_times_next);
109 }
110
112 {
115 $dataset = new sspmod_statistics_StatDataset($this->statconfig, $this->ruleconfig, $this->ruleid, $timeres, $fileslot);
116 return $dataset;
117 }
118}
119
An exception for terminatinating execution or to throw for unit testing.
__construct($statconfig, $ruleconfig, $ruleid, $available)
Constructor.
Definition: BaseRule.php:16
getDataSet($preferTimeRes, $preferTime)
Definition: BaseRule.php:111
$timeres
Definition: showstats.php:50
$preferTime
Definition: showstats.php:14
$dataset
Definition: showstats.php:45
$fileslot
Definition: showstats.php:51
$preferTimeRes
Definition: showstats.php:15