forked from stephpy/timeline-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManager.php
More file actions
168 lines (145 loc) · 4.56 KB
/
Manager.php
File metadata and controls
168 lines (145 loc) · 4.56 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace Highco\TimelineBundle;
use Highco\TimelineBundle\Model\TimelineAction;
use Highco\TimelineBundle\Model\Collection;
use Highco\TimelineBundle\Provider\ProviderInterface;
use Highco\TimelineBundle\Model\TimelineActionManagerInterface;
use Highco\TimelineBundle\Spread\Deployer;
use Highco\TimelineBundle\Filter\FilterInterface;
/**
* Manager timeline
* Allow to push a timeline action or pull a list of timeline action
*
* @author Stephane PY <py.stephane1@gmail.com>
*/
class Manager
{
/**
* @var TimelineActionManagerInterface
*/
protected $timelineActionManager;
/**
* @var Deployer
*/
protected $deployer;
/**
* @var ProviderInterface
*/
protected $provider;
/**
* @var array
*/
protected $filters = array();
/**
* @param TimelineActionManagerInterface $timelineActionManager Manager to retrieve from local storage
* @param Deployer $deployer Deploy to notify on deploy on spreads
* @param ProviderInterface $provider Provider to pull
*/
public function __construct(TimelineActionManagerInterface $timelineActionManager, Deployer $deployer, ProviderInterface $provider)
{
$this->provider = $provider;
$this->deployer = $deployer;
$this->timelineActionManager = $timelineActionManager;
}
/**
* @param TimelineAction $timelineAction
*
* @return boolean
*/
public function push(TimelineAction $timelineAction)
{
$this->timelineActionManager->updateTimelineAction($timelineAction);
if ($this->deployer->getDelivery() == Deployer::DELIVERY_IMMEDIATE) {
$this->deployer->deploy($timelineAction);
return true;
}
return false;
}
/**
* The wall of a subject is all timeline actions of his spreads, exemple, i'm Chuck Norris
* I'm friend with Steven Seagal and God.
*
* I'll see on the wall all actions of Steven Seagal and God (and may my actions if i want).
*
* Define a context to get an other one than GLOBAL
*
* @param string $subjectModel The class of the subject
* @param string $subjectId The oid of the subject
* @param string $context default GLOBAL
* @param array $options An array of options
*
* @return array
*/
public function getWall($subjectModel, $subjectId, $context = 'GLOBAL', $options = array())
{
$params = array(
'subjectModel' => $subjectModel,
'subjectId' => $subjectId,
'context' => $context,
);
$results = new Collection($this->provider->getWall($params, $options));
return $this->applyFilters($results);
}
/**
* @param string $subjectModel subjectModel
* @param string $subjectId subjectId
* @param string $context context
*
* @return integer
*/
public function countWallEntries($subjectModel, $subjectId, $context = 'GLOBAL')
{
return $this->provider->countKeys($context, $subjectModel, $subjectId);
}
/**
* That's all actions of the subject
*
* @param string $subjectModel The class of the subject
* @param string $subjectId The oid of the subject
* @param array $options An array of options to give
*
* @return array
*/
public function getTimeline($subjectModel, $subjectId, $options = array())
{
$params = array(
'subjectModel' => $subjectModel,
'subjectId' => $subjectId,
);
$results = new Collection($this->timelineActionManager->getTimeline($params, $options));
return $this->applyFilters($results);
}
/**
* This action will filters each results given in parameters
* You have to return results
*
* @param array $results
*
* @return array
*/
public function applyFilters($results)
{
foreach ($this->filters as $filter) {
$results = $filter->filter($results);
}
return $results;
}
/**
* @param FilterInterface $filter
*/
public function addFilter(FilterInterface $filter)
{
$this->filters[] = $filter;
}
/**
* @param FilterInterface $filter
*/
public function removeFilter(FilterInterface $filter)
{
foreach ($this->filters as $key => $filterExisting) {
if ($filterExisting == $filter) {
unset($this->filters[$key]);
}
}
}
}