1 | <?php |
||
30 | class GroupHelper { |
||
31 | /** @var array */ |
||
32 | protected $activities = array(); |
||
33 | |||
34 | /** @var array */ |
||
35 | protected $openGroup = array(); |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $groupKey = ''; |
||
39 | |||
40 | /** @var int */ |
||
41 | protected $groupTime = 0; |
||
42 | |||
43 | /** @var bool */ |
||
44 | protected $allowGrouping; |
||
45 | |||
46 | /** @var \OCP\Activity\IManager */ |
||
47 | protected $activityManager; |
||
48 | |||
49 | /** @var \OCA\Activity\DataHelper */ |
||
50 | protected $dataHelper; |
||
51 | |||
52 | /** |
||
53 | * @param \OCP\Activity\IManager $activityManager |
||
54 | * @param \OCA\Activity\DataHelper $dataHelper |
||
55 | * @param bool $allowGrouping |
||
56 | */ |
||
57 | 31 | public function __construct(IManager $activityManager, DataHelper $dataHelper, $allowGrouping) { |
|
58 | 31 | $this->allowGrouping = $allowGrouping; |
|
59 | |||
60 | 31 | $this->activityManager = $activityManager; |
|
61 | 31 | $this->dataHelper = $dataHelper; |
|
62 | 31 | } |
|
63 | |||
64 | /** |
||
65 | * @param string $user |
||
66 | */ |
||
67 | 6 | public function setUser($user) { |
|
70 | |||
71 | /** |
||
72 | * @param IL10N $l |
||
73 | */ |
||
74 | 1 | public function setL10n(IL10N $l) { |
|
77 | |||
78 | /** |
||
79 | * Add an activity to the internal array |
||
80 | * |
||
81 | * @param array $activity |
||
82 | */ |
||
83 | 12 | public function addActivity($activity) { |
|
145 | |||
146 | /** |
||
147 | * Closes the currently open group and adds it to the list of activities |
||
148 | */ |
||
149 | 13 | protected function closeOpenGroup() { |
|
158 | |||
159 | /** |
||
160 | * Get grouping key for an activity |
||
161 | * |
||
162 | * @param array $activity |
||
163 | * @return false|string False, if grouping is not allowed, grouping key otherwise |
||
164 | */ |
||
165 | 7 | protected function getGroupKey($activity) { |
|
180 | |||
181 | /** |
||
182 | * Get the parameter which is the varying part |
||
183 | * |
||
184 | * @param array $activity |
||
185 | * @return bool|int False if the activity should not be grouped, parameter position otherwise |
||
186 | */ |
||
187 | 8 | protected function getGroupParameter($activity) { |
|
195 | |||
196 | /** |
||
197 | * Get the prepared activities |
||
198 | * |
||
199 | * @return array translated activities ready for use |
||
200 | */ |
||
201 | 8 | public function getActivities() { |
|
202 | 8 | $this->closeOpenGroup(); |
|
203 | |||
204 | 8 | $return = array(); |
|
205 | 8 | foreach ($this->activities as $activity) { |
|
206 | 6 | $this->activityManager->setFormattingObject($activity['object_type'], $activity['object_id']); |
|
207 | 6 | $activity = $this->dataHelper->formatStrings($activity, 'subject'); |
|
208 | 6 | $activity = $this->dataHelper->formatStrings($activity, 'message'); |
|
209 | |||
210 | 6 | foreach ($activity['subjectparams'] as $i => $param) { |
|
|
|||
211 | /** @var IParameter $param */ |
||
212 | 4 | $activity['subjectparams'][$i] = $param->getParameterInfo(); |
|
213 | } |
||
214 | 6 | foreach ($activity['messageparams'] as $i => $param) { |
|
215 | /** @var IParameter $param */ |
||
216 | $activity['messageparams'][$i] = $param->getParameterInfo(); |
||
217 | } |
||
218 | |||
219 | 6 | $activity['typeicon'] = $this->activityManager->getTypeIcon($activity['type']); |
|
220 | 6 | $return[] = $activity; |
|
221 | } |
||
222 | 8 | $this->activityManager->setFormattingObject('', 0); |
|
223 | 8 | $this->activities = []; |
|
224 | |||
225 | 8 | return $return; |
|
226 | } |
||
227 | |||
228 | /** |
||
229 | * @param array $activity |
||
230 | * @return IEvent |
||
231 | */ |
||
232 | 6 | public function getEventFromArray(array $activity) { |
|
246 | } |
||
247 |