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