/
Fact.php
executable file
·100 lines (76 loc) · 2.06 KB
/
Fact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace OLAP;
class Fact extends Model {
const PREFIX = 'fact_';
/**
* @var Dimension[]
*/
private $dimensions = [];
/**
* @var Type
*/
private $dataType;
public function __construct($name, $dimensions = [], $options = []) {
$this->name = $name;
foreach ($dimensions as $dimension) {
if (is_array($dimension) && !empty($dimension['name']) && !empty($dimension['type'])) {
$dimension = new Dimension(
$dimension['name'],
$dimension['type'],
array_diff_key( $dimension, array_flip(['name', 'type']) )
);
}
if ($dimension instanceof Dimension) {
$this->dimensions[strtolower($dimension->getName())] = $dimension;
} else {
throw new Exception('Bad fact format');
}
}
$this->options = $options;
}
/**
* @return Dimension[]
*/
public function getDimensions() {
return $this->dimensions;
}
/**
* @param $name
* @return Dimension
*/
public function getDimension($name) {
return empty($this->dimensions[$name]) ? false : $this->dimensions[$name];
}
/**
* @return Type
*/
public function getDataType() {
return $this->dataType;
}
/**
* @return string
*/
public function getParent() {
$parent = $this->getOption('parent', null);
return $parent ? $this->makeName($parent) : null;
}
public function isSpecial() {
return $this->getOption('special', false);
}
/**
* @return bool
*/
public function isDefaultDrill() {
return (bool)$this->getOption('default_drill', false);
}
/**
* @param string $drill
* @return bool
*/
public function isDrill($drill) {
return $this->name === $drill;
}
protected function makeName($name) {
return self::PREFIX . $this->getOption('cube_name', 'cube') . '_' . $name;
}
}