/
ObjectList.php
87 lines (69 loc) · 1.73 KB
/
ObjectList.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
<?php
namespace Icinga\Module\Monitoring\Object;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
abstract class ObjectList implements Countable, IteratorAggregate
{
protected $dataViewName;
protected $backend;
protected $columns;
protected $filter;
protected $objects;
protected $count;
public function __construct(MonitoringBackend $backend)
{
$this->backend = $backend;
}
public function setColumns(array $columns)
{
$this->columns = $columns;
return $this;
}
public function getColumns()
{
return $this->columns;
}
public function setFilter($filter)
{
$this->filter = $filter;
return $this;
}
public function getFilter()
{
return $this->filter;
}
abstract protected function fetchObjects();
public function fetch()
{
if ($this->objects === null) {
$this->objects = $this->fetchObjects();
}
return $this->objects;
}
public function count()
{
if ($this->count === null) {
$this->count = (int) $this->backend->select()->from($this->dataViewName)->applyFilter($this->filter)
->getQuery()->count();
}
return $this->count;
}
public function getIterator()
{
if ($this->objects === null) {
$this->fetch();
}
return new ArrayIterator($this->objects);
}
/**
* Get the comments
*
* @return \Icinga\Module\Monitoring\DataView\Comment
*/
public function getComments()
{
return $this->backend->select()->from('comment')->applyFilter($this->filter);
}
}