1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Scriptotek\Alma\Analytics; |
4
|
|
|
|
5
|
|
|
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* A single Row belonging to some Report. |
9
|
|
|
*/ |
10
|
|
|
class Row implements \ArrayAccess, \IteratorAggregate, \Countable |
11
|
|
|
{ |
12
|
|
|
protected $byIndex = []; |
13
|
|
|
protected $byHeader = []; |
14
|
|
|
protected $headers; |
15
|
|
|
|
16
|
|
|
public function __construct(QuiteSimpleXMLElement $data, $headers) |
17
|
|
|
{ |
18
|
|
|
$this->headers = $headers; |
19
|
|
|
foreach ($headers as $idx => $header) { |
20
|
|
|
$value = $data->text('rowset:Column' . ($idx + 1)) ?: null; |
21
|
|
|
$this->byIndex[$idx] = $value; |
22
|
|
|
$this->byHeader[$header] = $value; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function __get($name) |
27
|
|
|
{ |
28
|
|
|
return $this->byHeader[$name]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function offsetSet($offset, $value) |
32
|
|
|
{ |
33
|
|
|
throw new \RuntimeException('Sorry, column values cannot be modified.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function offsetExists($offset) |
37
|
|
|
{ |
38
|
|
|
return isset($this->byIndex[$offset]) || isset($this->byHeader[$offset]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function offsetUnset($offset) |
42
|
|
|
{ |
43
|
|
|
throw new \RuntimeException('Sorry, column values cannot be modified.'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function offsetGet($offset) |
47
|
|
|
{ |
48
|
|
|
if (isset($this->byIndex[$offset])) { |
49
|
|
|
return $this->byIndex[$offset]; |
50
|
|
|
} |
51
|
|
|
if (isset($this->byHeader[$offset])) { |
52
|
|
|
return $this->byHeader[$offset]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getIterator() |
57
|
|
|
{ |
58
|
|
|
return new \ArrayIterator($this->byHeader); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function count() |
62
|
|
|
{ |
63
|
|
|
return count($this->byIndex); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function toArray() |
67
|
|
|
{ |
68
|
|
|
return $this->byHeader; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|