ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Ruleset.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  private $statconfig;
9  private $availrulenames;
10  private $availrules;
11  private $available;
12 
16  public function __construct($statconfig)
17  {
18  $this->statconfig = $statconfig;
19  $this->init();
20  }
21 
22  private function init()
23  {
24  $statdir = $this->statconfig->getValue('statdir');
25  $statrules = $this->statconfig->getValue('statrules');
26  $timeres = $this->statconfig->getValue('timeres');
27 
28  /*
29  * Walk through file lists, and get available [rule][fileslot]...
30  */
31  if (!is_dir($statdir)) {
32  throw new Exception('Statisics output directory [' . $statdir . '] does not exists.');
33  }
34  $filelist = scandir($statdir);
35  $this->available = array();
36  foreach ($filelist as $file) {
37  if (preg_match('/([a-z0-9_]+)-([a-z0-9_]+)-([0-9]+)\.stat/', $file, $matches)) {
38  if (array_key_exists($matches[1], $statrules)) {
39  if (array_key_exists($matches[2], $timeres))
40  $this->available[$matches[1]][$matches[2]][] = $matches[3];
41  }
42  }
43  }
44  if (empty($this->available)) {
45  throw new Exception('No aggregated statistics files found in [' . $statdir . ']');
46  }
47 
48  /*
49  * Create array with information about available rules..
50  */
51  $this->availrules = array_keys($statrules);
52  $available_rules = array();
53  foreach ($this->availrules as $key) {
54  $available_rules[$key] = array('name' => $statrules[$key]['name'], 'descr' => $statrules[$key]['descr']);
55  }
56  $this->availrulenames = $available_rules;
57  }
58 
59  public function availableRules()
60  {
61  return $this->availrules;
62  }
63 
64  public function availableRulesNames()
65  {
66  return $this->availrulenames;
67  }
68 
72  private function resolveSelectedRule($preferRule = null)
73  {
74  $rule = $this->statconfig->getString('default', $this->availrules[0]);
75  if (!empty($preferRule)) {
76  if (in_array($preferRule, $this->availrules, true)) {
78  }
79  }
80  return $rule;
81  }
82 
83  public function getRule($preferRule)
84  {
86  $statrulesConfig = $this->statconfig->getConfigItem('statrules');
87  $statruleConfig = $statrulesConfig->getConfigItem($rule);
88 
89  $presenterClass = SimpleSAML\Module::resolveClass($statruleConfig->getValue('presenter', 'statistics:BaseRule'), 'Statistics_Rulesets');
90  $statrule = new $presenterClass($this->statconfig, $statruleConfig, $rule, $this->available);
91  return $statrule;
92  }
93 }
94 
$timeres
Definition: showstats.php:77
getRule($preferRule)
Definition: Ruleset.php:83
$preferRule
Definition: showstats.php:12
$rule
Definition: showstats.php:43
$statrule
Definition: showstats.php:42
__construct($statconfig)
Constructor.
Definition: Ruleset.php:16
static resolveClass($id, $type, $subclass=null)
Resolve module class.
Definition: Module.php:169
resolveSelectedRule($preferRule=null)
Resolve which rule is selected.
Definition: Ruleset.php:72
$key
Definition: croninfo.php:18