@@ -31,111 +31,111 @@ |
||
31 | 31 | |
32 | 32 | class Event extends Base { |
33 | 33 | |
34 | - const SUBJECT_OBJECT_ADD = 'object_add'; |
|
35 | - const SUBJECT_OBJECT_UPDATE = 'object_update'; |
|
36 | - const SUBJECT_OBJECT_DELETE = 'object_delete'; |
|
37 | - |
|
38 | - /** @var IFactory */ |
|
39 | - protected $languageFactory; |
|
40 | - |
|
41 | - /** @var IL10N */ |
|
42 | - protected $l; |
|
43 | - |
|
44 | - /** @var IURLGenerator */ |
|
45 | - protected $url; |
|
46 | - |
|
47 | - /** @var IManager */ |
|
48 | - protected $activityManager; |
|
49 | - |
|
50 | - /** @var IEventMerger */ |
|
51 | - protected $eventMerger; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param IFactory $languageFactory |
|
55 | - * @param IURLGenerator $url |
|
56 | - * @param IManager $activityManager |
|
57 | - * @param IUserManager $userManager |
|
58 | - * @param IEventMerger $eventMerger |
|
59 | - */ |
|
60 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
61 | - parent::__construct($userManager); |
|
62 | - $this->languageFactory = $languageFactory; |
|
63 | - $this->url = $url; |
|
64 | - $this->activityManager = $activityManager; |
|
65 | - $this->eventMerger = $eventMerger; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param string $language |
|
70 | - * @param IEvent $event |
|
71 | - * @param IEvent|null $previousEvent |
|
72 | - * @return IEvent |
|
73 | - * @throws \InvalidArgumentException |
|
74 | - * @since 11.0.0 |
|
75 | - */ |
|
76 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
77 | - if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_event') { |
|
78 | - throw new \InvalidArgumentException(); |
|
79 | - } |
|
80 | - |
|
81 | - $this->l = $this->languageFactory->get('dav', $language); |
|
82 | - |
|
83 | - if ($this->activityManager->getRequirePNG()) { |
|
84 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png'))); |
|
85 | - } else { |
|
86 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'))); |
|
87 | - } |
|
88 | - |
|
89 | - if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event') { |
|
90 | - $subject = $this->l->t('{actor} created event {event} in calendar {calendar}'); |
|
91 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event_self') { |
|
92 | - $subject = $this->l->t('You created event {event} in calendar {calendar}'); |
|
93 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event') { |
|
94 | - $subject = $this->l->t('{actor} deleted event {event} from calendar {calendar}'); |
|
95 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event_self') { |
|
96 | - $subject = $this->l->t('You deleted event {event} from calendar {calendar}'); |
|
97 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') { |
|
98 | - $subject = $this->l->t('{actor} updated event {event} in calendar {calendar}'); |
|
99 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event_self') { |
|
100 | - $subject = $this->l->t('You updated event {event} in calendar {calendar}'); |
|
101 | - } else { |
|
102 | - throw new \InvalidArgumentException(); |
|
103 | - } |
|
104 | - |
|
105 | - $parsedParameters = $this->getParameters($event); |
|
106 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
107 | - |
|
108 | - $event = $this->eventMerger->mergeEvents('event', $event, $previousEvent); |
|
109 | - |
|
110 | - return $event; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param IEvent $event |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - protected function getParameters(IEvent $event) { |
|
118 | - $subject = $event->getSubject(); |
|
119 | - $parameters = $event->getSubjectParameters(); |
|
120 | - |
|
121 | - switch ($subject) { |
|
122 | - case self::SUBJECT_OBJECT_ADD . '_event': |
|
123 | - case self::SUBJECT_OBJECT_DELETE . '_event': |
|
124 | - case self::SUBJECT_OBJECT_UPDATE . '_event': |
|
125 | - return [ |
|
126 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
127 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
128 | - 'event' => $this->generateObjectParameter($parameters[2]), |
|
129 | - ]; |
|
130 | - case self::SUBJECT_OBJECT_ADD . '_event_self': |
|
131 | - case self::SUBJECT_OBJECT_DELETE . '_event_self': |
|
132 | - case self::SUBJECT_OBJECT_UPDATE . '_event_self': |
|
133 | - return [ |
|
134 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
135 | - 'event' => $this->generateObjectParameter($parameters[2]), |
|
136 | - ]; |
|
137 | - } |
|
138 | - |
|
139 | - throw new \InvalidArgumentException(); |
|
140 | - } |
|
34 | + const SUBJECT_OBJECT_ADD = 'object_add'; |
|
35 | + const SUBJECT_OBJECT_UPDATE = 'object_update'; |
|
36 | + const SUBJECT_OBJECT_DELETE = 'object_delete'; |
|
37 | + |
|
38 | + /** @var IFactory */ |
|
39 | + protected $languageFactory; |
|
40 | + |
|
41 | + /** @var IL10N */ |
|
42 | + protected $l; |
|
43 | + |
|
44 | + /** @var IURLGenerator */ |
|
45 | + protected $url; |
|
46 | + |
|
47 | + /** @var IManager */ |
|
48 | + protected $activityManager; |
|
49 | + |
|
50 | + /** @var IEventMerger */ |
|
51 | + protected $eventMerger; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param IFactory $languageFactory |
|
55 | + * @param IURLGenerator $url |
|
56 | + * @param IManager $activityManager |
|
57 | + * @param IUserManager $userManager |
|
58 | + * @param IEventMerger $eventMerger |
|
59 | + */ |
|
60 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
61 | + parent::__construct($userManager); |
|
62 | + $this->languageFactory = $languageFactory; |
|
63 | + $this->url = $url; |
|
64 | + $this->activityManager = $activityManager; |
|
65 | + $this->eventMerger = $eventMerger; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param string $language |
|
70 | + * @param IEvent $event |
|
71 | + * @param IEvent|null $previousEvent |
|
72 | + * @return IEvent |
|
73 | + * @throws \InvalidArgumentException |
|
74 | + * @since 11.0.0 |
|
75 | + */ |
|
76 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
77 | + if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_event') { |
|
78 | + throw new \InvalidArgumentException(); |
|
79 | + } |
|
80 | + |
|
81 | + $this->l = $this->languageFactory->get('dav', $language); |
|
82 | + |
|
83 | + if ($this->activityManager->getRequirePNG()) { |
|
84 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png'))); |
|
85 | + } else { |
|
86 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'))); |
|
87 | + } |
|
88 | + |
|
89 | + if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event') { |
|
90 | + $subject = $this->l->t('{actor} created event {event} in calendar {calendar}'); |
|
91 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event_self') { |
|
92 | + $subject = $this->l->t('You created event {event} in calendar {calendar}'); |
|
93 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event') { |
|
94 | + $subject = $this->l->t('{actor} deleted event {event} from calendar {calendar}'); |
|
95 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event_self') { |
|
96 | + $subject = $this->l->t('You deleted event {event} from calendar {calendar}'); |
|
97 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') { |
|
98 | + $subject = $this->l->t('{actor} updated event {event} in calendar {calendar}'); |
|
99 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event_self') { |
|
100 | + $subject = $this->l->t('You updated event {event} in calendar {calendar}'); |
|
101 | + } else { |
|
102 | + throw new \InvalidArgumentException(); |
|
103 | + } |
|
104 | + |
|
105 | + $parsedParameters = $this->getParameters($event); |
|
106 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
107 | + |
|
108 | + $event = $this->eventMerger->mergeEvents('event', $event, $previousEvent); |
|
109 | + |
|
110 | + return $event; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param IEvent $event |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + protected function getParameters(IEvent $event) { |
|
118 | + $subject = $event->getSubject(); |
|
119 | + $parameters = $event->getSubjectParameters(); |
|
120 | + |
|
121 | + switch ($subject) { |
|
122 | + case self::SUBJECT_OBJECT_ADD . '_event': |
|
123 | + case self::SUBJECT_OBJECT_DELETE . '_event': |
|
124 | + case self::SUBJECT_OBJECT_UPDATE . '_event': |
|
125 | + return [ |
|
126 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
127 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
128 | + 'event' => $this->generateObjectParameter($parameters[2]), |
|
129 | + ]; |
|
130 | + case self::SUBJECT_OBJECT_ADD . '_event_self': |
|
131 | + case self::SUBJECT_OBJECT_DELETE . '_event_self': |
|
132 | + case self::SUBJECT_OBJECT_UPDATE . '_event_self': |
|
133 | + return [ |
|
134 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
135 | + 'event' => $this->generateObjectParameter($parameters[2]), |
|
136 | + ]; |
|
137 | + } |
|
138 | + |
|
139 | + throw new \InvalidArgumentException(); |
|
140 | + } |
|
141 | 141 | } |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'))); |
87 | 87 | } |
88 | 88 | |
89 | - if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event') { |
|
89 | + if ($event->getSubject() === self::SUBJECT_OBJECT_ADD.'_event') { |
|
90 | 90 | $subject = $this->l->t('{actor} created event {event} in calendar {calendar}'); |
91 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event_self') { |
|
91 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD.'_event_self') { |
|
92 | 92 | $subject = $this->l->t('You created event {event} in calendar {calendar}'); |
93 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event') { |
|
93 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE.'_event') { |
|
94 | 94 | $subject = $this->l->t('{actor} deleted event {event} from calendar {calendar}'); |
95 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event_self') { |
|
95 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE.'_event_self') { |
|
96 | 96 | $subject = $this->l->t('You deleted event {event} from calendar {calendar}'); |
97 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') { |
|
97 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_event') { |
|
98 | 98 | $subject = $this->l->t('{actor} updated event {event} in calendar {calendar}'); |
99 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event_self') { |
|
99 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_event_self') { |
|
100 | 100 | $subject = $this->l->t('You updated event {event} in calendar {calendar}'); |
101 | 101 | } else { |
102 | 102 | throw new \InvalidArgumentException(); |
@@ -119,17 +119,17 @@ discard block |
||
119 | 119 | $parameters = $event->getSubjectParameters(); |
120 | 120 | |
121 | 121 | switch ($subject) { |
122 | - case self::SUBJECT_OBJECT_ADD . '_event': |
|
123 | - case self::SUBJECT_OBJECT_DELETE . '_event': |
|
124 | - case self::SUBJECT_OBJECT_UPDATE . '_event': |
|
122 | + case self::SUBJECT_OBJECT_ADD.'_event': |
|
123 | + case self::SUBJECT_OBJECT_DELETE.'_event': |
|
124 | + case self::SUBJECT_OBJECT_UPDATE.'_event': |
|
125 | 125 | return [ |
126 | 126 | 'actor' => $this->generateUserParameter($parameters[0]), |
127 | 127 | 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
128 | 128 | 'event' => $this->generateObjectParameter($parameters[2]), |
129 | 129 | ]; |
130 | - case self::SUBJECT_OBJECT_ADD . '_event_self': |
|
131 | - case self::SUBJECT_OBJECT_DELETE . '_event_self': |
|
132 | - case self::SUBJECT_OBJECT_UPDATE . '_event_self': |
|
130 | + case self::SUBJECT_OBJECT_ADD.'_event_self': |
|
131 | + case self::SUBJECT_OBJECT_DELETE.'_event_self': |
|
132 | + case self::SUBJECT_OBJECT_UPDATE.'_event_self': |
|
133 | 133 | return [ |
134 | 134 | 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
135 | 135 | 'event' => $this->generateObjectParameter($parameters[2]), |
@@ -31,173 +31,173 @@ |
||
31 | 31 | |
32 | 32 | class Calendar extends Base { |
33 | 33 | |
34 | - const SUBJECT_ADD = 'calendar_add'; |
|
35 | - const SUBJECT_UPDATE = 'calendar_update'; |
|
36 | - const SUBJECT_DELETE = 'calendar_delete'; |
|
37 | - const SUBJECT_SHARE_USER = 'calendar_user_share'; |
|
38 | - const SUBJECT_SHARE_GROUP = 'calendar_group_share'; |
|
39 | - const SUBJECT_UNSHARE_USER = 'calendar_user_unshare'; |
|
40 | - const SUBJECT_UNSHARE_GROUP = 'calendar_group_unshare'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IManager */ |
|
52 | - protected $activityManager; |
|
53 | - |
|
54 | - /** @var IEventMerger */ |
|
55 | - protected $eventMerger; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param IFactory $languageFactory |
|
59 | - * @param IURLGenerator $url |
|
60 | - * @param IManager $activityManager |
|
61 | - * @param IUserManager $userManager |
|
62 | - * @param IEventMerger $eventMerger |
|
63 | - */ |
|
64 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
65 | - parent::__construct($userManager); |
|
66 | - $this->languageFactory = $languageFactory; |
|
67 | - $this->url = $url; |
|
68 | - $this->activityManager = $activityManager; |
|
69 | - $this->eventMerger = $eventMerger; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $language |
|
74 | - * @param IEvent $event |
|
75 | - * @param IEvent|null $previousEvent |
|
76 | - * @return IEvent |
|
77 | - * @throws \InvalidArgumentException |
|
78 | - * @since 11.0.0 |
|
79 | - */ |
|
80 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
81 | - if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar') { |
|
82 | - throw new \InvalidArgumentException(); |
|
83 | - } |
|
84 | - |
|
85 | - $this->l = $this->languageFactory->get('dav', $language); |
|
86 | - |
|
87 | - if ($this->activityManager->getRequirePNG()) { |
|
88 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png'))); |
|
89 | - } else { |
|
90 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'))); |
|
91 | - } |
|
92 | - |
|
93 | - if ($event->getSubject() === self::SUBJECT_ADD) { |
|
94 | - $subject = $this->l->t('{actor} created calendar {calendar}'); |
|
95 | - } else if ($event->getSubject() === self::SUBJECT_ADD . '_self') { |
|
96 | - $subject = $this->l->t('You created calendar {calendar}'); |
|
97 | - } else if ($event->getSubject() === self::SUBJECT_DELETE) { |
|
98 | - $subject = $this->l->t('{actor} deleted calendar {calendar}'); |
|
99 | - } else if ($event->getSubject() === self::SUBJECT_DELETE . '_self') { |
|
100 | - $subject = $this->l->t('You deleted calendar {calendar}'); |
|
101 | - } else if ($event->getSubject() === self::SUBJECT_UPDATE) { |
|
102 | - $subject = $this->l->t('{actor} updated calendar {calendar}'); |
|
103 | - } else if ($event->getSubject() === self::SUBJECT_UPDATE . '_self') { |
|
104 | - $subject = $this->l->t('You updated calendar {calendar}'); |
|
105 | - |
|
106 | - } else if ($event->getSubject() === self::SUBJECT_SHARE_USER) { |
|
107 | - $subject = $this->l->t('{actor} shared calendar {calendar} with you'); |
|
108 | - } else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') { |
|
109 | - $subject = $this->l->t('You shared calendar {calendar} with {user}'); |
|
110 | - } else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_by') { |
|
111 | - $subject = $this->l->t('{actor} shared calendar {calendar} with {user}'); |
|
112 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER) { |
|
113 | - $subject = $this->l->t('{actor} unshared calendar {calendar} from you'); |
|
114 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_you') { |
|
115 | - $subject = $this->l->t('You unshared calendar {calendar} from {user}'); |
|
116 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_by') { |
|
117 | - $subject = $this->l->t('{actor} unshared calendar {calendar} from {user}'); |
|
118 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_self') { |
|
119 | - $subject = $this->l->t('{actor} unshared calendar {calendar} from themselves'); |
|
120 | - |
|
121 | - } else if ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_you') { |
|
122 | - $subject = $this->l->t('You shared calendar {calendar} with group {group}'); |
|
123 | - } else if ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_by') { |
|
124 | - $subject = $this->l->t('{actor} shared calendar {calendar} with group {group}'); |
|
125 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_you') { |
|
126 | - $subject = $this->l->t('You unshared calendar {calendar} from group {group}'); |
|
127 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') { |
|
128 | - $subject = $this->l->t('{actor} unshared calendar {calendar} from group {group}'); |
|
129 | - } else { |
|
130 | - throw new \InvalidArgumentException(); |
|
131 | - } |
|
132 | - |
|
133 | - $parsedParameters = $this->getParameters($event); |
|
134 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
135 | - |
|
136 | - $event = $this->eventMerger->mergeEvents('calendar', $event, $previousEvent); |
|
137 | - |
|
138 | - if ($event->getChildEvent() === null) { |
|
139 | - if (isset($parsedParameters['user'])) { |
|
140 | - // Couldn't group by calendar, maybe we can group by users |
|
141 | - $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
142 | - } else if (isset($parsedParameters['group'])) { |
|
143 | - // Couldn't group by calendar, maybe we can group by groups |
|
144 | - $event = $this->eventMerger->mergeEvents('group', $event, $previousEvent); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return $event; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param IEvent $event |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function getParameters(IEvent $event) { |
|
156 | - $subject = $event->getSubject(); |
|
157 | - $parameters = $event->getSubjectParameters(); |
|
158 | - |
|
159 | - switch ($subject) { |
|
160 | - case self::SUBJECT_ADD: |
|
161 | - case self::SUBJECT_ADD . '_self': |
|
162 | - case self::SUBJECT_DELETE: |
|
163 | - case self::SUBJECT_DELETE . '_self': |
|
164 | - case self::SUBJECT_UPDATE: |
|
165 | - case self::SUBJECT_UPDATE . '_self': |
|
166 | - case self::SUBJECT_SHARE_USER: |
|
167 | - case self::SUBJECT_UNSHARE_USER: |
|
168 | - case self::SUBJECT_UNSHARE_USER . '_self': |
|
169 | - return [ |
|
170 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
171 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
172 | - ]; |
|
173 | - case self::SUBJECT_SHARE_USER . '_you': |
|
174 | - case self::SUBJECT_UNSHARE_USER . '_you': |
|
175 | - return [ |
|
176 | - 'user' => $this->generateUserParameter($parameters[0]), |
|
177 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
178 | - ]; |
|
179 | - case self::SUBJECT_SHARE_USER . '_by': |
|
180 | - case self::SUBJECT_UNSHARE_USER . '_by': |
|
181 | - return [ |
|
182 | - 'user' => $this->generateUserParameter($parameters[0]), |
|
183 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
184 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
185 | - ]; |
|
186 | - case self::SUBJECT_SHARE_GROUP . '_you': |
|
187 | - case self::SUBJECT_UNSHARE_GROUP . '_you': |
|
188 | - return [ |
|
189 | - 'group' => $this->generateGroupParameter($parameters[0]), |
|
190 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
191 | - ]; |
|
192 | - case self::SUBJECT_SHARE_GROUP . '_by': |
|
193 | - case self::SUBJECT_UNSHARE_GROUP . '_by': |
|
194 | - return [ |
|
195 | - 'group' => $this->generateGroupParameter($parameters[0]), |
|
196 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
197 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
198 | - ]; |
|
199 | - } |
|
200 | - |
|
201 | - throw new \InvalidArgumentException(); |
|
202 | - } |
|
34 | + const SUBJECT_ADD = 'calendar_add'; |
|
35 | + const SUBJECT_UPDATE = 'calendar_update'; |
|
36 | + const SUBJECT_DELETE = 'calendar_delete'; |
|
37 | + const SUBJECT_SHARE_USER = 'calendar_user_share'; |
|
38 | + const SUBJECT_SHARE_GROUP = 'calendar_group_share'; |
|
39 | + const SUBJECT_UNSHARE_USER = 'calendar_user_unshare'; |
|
40 | + const SUBJECT_UNSHARE_GROUP = 'calendar_group_unshare'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IManager */ |
|
52 | + protected $activityManager; |
|
53 | + |
|
54 | + /** @var IEventMerger */ |
|
55 | + protected $eventMerger; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param IFactory $languageFactory |
|
59 | + * @param IURLGenerator $url |
|
60 | + * @param IManager $activityManager |
|
61 | + * @param IUserManager $userManager |
|
62 | + * @param IEventMerger $eventMerger |
|
63 | + */ |
|
64 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
65 | + parent::__construct($userManager); |
|
66 | + $this->languageFactory = $languageFactory; |
|
67 | + $this->url = $url; |
|
68 | + $this->activityManager = $activityManager; |
|
69 | + $this->eventMerger = $eventMerger; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $language |
|
74 | + * @param IEvent $event |
|
75 | + * @param IEvent|null $previousEvent |
|
76 | + * @return IEvent |
|
77 | + * @throws \InvalidArgumentException |
|
78 | + * @since 11.0.0 |
|
79 | + */ |
|
80 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
81 | + if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar') { |
|
82 | + throw new \InvalidArgumentException(); |
|
83 | + } |
|
84 | + |
|
85 | + $this->l = $this->languageFactory->get('dav', $language); |
|
86 | + |
|
87 | + if ($this->activityManager->getRequirePNG()) { |
|
88 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png'))); |
|
89 | + } else { |
|
90 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'))); |
|
91 | + } |
|
92 | + |
|
93 | + if ($event->getSubject() === self::SUBJECT_ADD) { |
|
94 | + $subject = $this->l->t('{actor} created calendar {calendar}'); |
|
95 | + } else if ($event->getSubject() === self::SUBJECT_ADD . '_self') { |
|
96 | + $subject = $this->l->t('You created calendar {calendar}'); |
|
97 | + } else if ($event->getSubject() === self::SUBJECT_DELETE) { |
|
98 | + $subject = $this->l->t('{actor} deleted calendar {calendar}'); |
|
99 | + } else if ($event->getSubject() === self::SUBJECT_DELETE . '_self') { |
|
100 | + $subject = $this->l->t('You deleted calendar {calendar}'); |
|
101 | + } else if ($event->getSubject() === self::SUBJECT_UPDATE) { |
|
102 | + $subject = $this->l->t('{actor} updated calendar {calendar}'); |
|
103 | + } else if ($event->getSubject() === self::SUBJECT_UPDATE . '_self') { |
|
104 | + $subject = $this->l->t('You updated calendar {calendar}'); |
|
105 | + |
|
106 | + } else if ($event->getSubject() === self::SUBJECT_SHARE_USER) { |
|
107 | + $subject = $this->l->t('{actor} shared calendar {calendar} with you'); |
|
108 | + } else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') { |
|
109 | + $subject = $this->l->t('You shared calendar {calendar} with {user}'); |
|
110 | + } else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_by') { |
|
111 | + $subject = $this->l->t('{actor} shared calendar {calendar} with {user}'); |
|
112 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER) { |
|
113 | + $subject = $this->l->t('{actor} unshared calendar {calendar} from you'); |
|
114 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_you') { |
|
115 | + $subject = $this->l->t('You unshared calendar {calendar} from {user}'); |
|
116 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_by') { |
|
117 | + $subject = $this->l->t('{actor} unshared calendar {calendar} from {user}'); |
|
118 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_self') { |
|
119 | + $subject = $this->l->t('{actor} unshared calendar {calendar} from themselves'); |
|
120 | + |
|
121 | + } else if ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_you') { |
|
122 | + $subject = $this->l->t('You shared calendar {calendar} with group {group}'); |
|
123 | + } else if ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_by') { |
|
124 | + $subject = $this->l->t('{actor} shared calendar {calendar} with group {group}'); |
|
125 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_you') { |
|
126 | + $subject = $this->l->t('You unshared calendar {calendar} from group {group}'); |
|
127 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') { |
|
128 | + $subject = $this->l->t('{actor} unshared calendar {calendar} from group {group}'); |
|
129 | + } else { |
|
130 | + throw new \InvalidArgumentException(); |
|
131 | + } |
|
132 | + |
|
133 | + $parsedParameters = $this->getParameters($event); |
|
134 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
135 | + |
|
136 | + $event = $this->eventMerger->mergeEvents('calendar', $event, $previousEvent); |
|
137 | + |
|
138 | + if ($event->getChildEvent() === null) { |
|
139 | + if (isset($parsedParameters['user'])) { |
|
140 | + // Couldn't group by calendar, maybe we can group by users |
|
141 | + $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
142 | + } else if (isset($parsedParameters['group'])) { |
|
143 | + // Couldn't group by calendar, maybe we can group by groups |
|
144 | + $event = $this->eventMerger->mergeEvents('group', $event, $previousEvent); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return $event; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param IEvent $event |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function getParameters(IEvent $event) { |
|
156 | + $subject = $event->getSubject(); |
|
157 | + $parameters = $event->getSubjectParameters(); |
|
158 | + |
|
159 | + switch ($subject) { |
|
160 | + case self::SUBJECT_ADD: |
|
161 | + case self::SUBJECT_ADD . '_self': |
|
162 | + case self::SUBJECT_DELETE: |
|
163 | + case self::SUBJECT_DELETE . '_self': |
|
164 | + case self::SUBJECT_UPDATE: |
|
165 | + case self::SUBJECT_UPDATE . '_self': |
|
166 | + case self::SUBJECT_SHARE_USER: |
|
167 | + case self::SUBJECT_UNSHARE_USER: |
|
168 | + case self::SUBJECT_UNSHARE_USER . '_self': |
|
169 | + return [ |
|
170 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
171 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
172 | + ]; |
|
173 | + case self::SUBJECT_SHARE_USER . '_you': |
|
174 | + case self::SUBJECT_UNSHARE_USER . '_you': |
|
175 | + return [ |
|
176 | + 'user' => $this->generateUserParameter($parameters[0]), |
|
177 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
178 | + ]; |
|
179 | + case self::SUBJECT_SHARE_USER . '_by': |
|
180 | + case self::SUBJECT_UNSHARE_USER . '_by': |
|
181 | + return [ |
|
182 | + 'user' => $this->generateUserParameter($parameters[0]), |
|
183 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
184 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
185 | + ]; |
|
186 | + case self::SUBJECT_SHARE_GROUP . '_you': |
|
187 | + case self::SUBJECT_UNSHARE_GROUP . '_you': |
|
188 | + return [ |
|
189 | + 'group' => $this->generateGroupParameter($parameters[0]), |
|
190 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
191 | + ]; |
|
192 | + case self::SUBJECT_SHARE_GROUP . '_by': |
|
193 | + case self::SUBJECT_UNSHARE_GROUP . '_by': |
|
194 | + return [ |
|
195 | + 'group' => $this->generateGroupParameter($parameters[0]), |
|
196 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
197 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
198 | + ]; |
|
199 | + } |
|
200 | + |
|
201 | + throw new \InvalidArgumentException(); |
|
202 | + } |
|
203 | 203 | } |
@@ -25,90 +25,90 @@ |
||
25 | 25 | |
26 | 26 | class Todo extends Event { |
27 | 27 | |
28 | - /** |
|
29 | - * @param string $language |
|
30 | - * @param IEvent $event |
|
31 | - * @param IEvent|null $previousEvent |
|
32 | - * @return IEvent |
|
33 | - * @throws \InvalidArgumentException |
|
34 | - * @since 11.0.0 |
|
35 | - */ |
|
36 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
37 | - if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_todo') { |
|
38 | - throw new \InvalidArgumentException(); |
|
39 | - } |
|
28 | + /** |
|
29 | + * @param string $language |
|
30 | + * @param IEvent $event |
|
31 | + * @param IEvent|null $previousEvent |
|
32 | + * @return IEvent |
|
33 | + * @throws \InvalidArgumentException |
|
34 | + * @since 11.0.0 |
|
35 | + */ |
|
36 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
37 | + if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_todo') { |
|
38 | + throw new \InvalidArgumentException(); |
|
39 | + } |
|
40 | 40 | |
41 | - $this->l = $this->languageFactory->get('dav', $language); |
|
41 | + $this->l = $this->languageFactory->get('dav', $language); |
|
42 | 42 | |
43 | - if ($this->activityManager->getRequirePNG()) { |
|
44 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.png'))); |
|
45 | - } else { |
|
46 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg'))); |
|
47 | - } |
|
43 | + if ($this->activityManager->getRequirePNG()) { |
|
44 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.png'))); |
|
45 | + } else { |
|
46 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg'))); |
|
47 | + } |
|
48 | 48 | |
49 | - if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo') { |
|
50 | - $subject = $this->l->t('{actor} created todo {todo} in list {calendar}'); |
|
51 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo_self') { |
|
52 | - $subject = $this->l->t('You created todo {todo} in list {calendar}'); |
|
53 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo') { |
|
54 | - $subject = $this->l->t('{actor} deleted todo {todo} from list {calendar}'); |
|
55 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo_self') { |
|
56 | - $subject = $this->l->t('You deleted todo {todo} from list {calendar}'); |
|
57 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo') { |
|
58 | - $subject = $this->l->t('{actor} updated todo {todo} in list {calendar}'); |
|
59 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_self') { |
|
60 | - $subject = $this->l->t('You updated todo {todo} in list {calendar}'); |
|
49 | + if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo') { |
|
50 | + $subject = $this->l->t('{actor} created todo {todo} in list {calendar}'); |
|
51 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo_self') { |
|
52 | + $subject = $this->l->t('You created todo {todo} in list {calendar}'); |
|
53 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo') { |
|
54 | + $subject = $this->l->t('{actor} deleted todo {todo} from list {calendar}'); |
|
55 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo_self') { |
|
56 | + $subject = $this->l->t('You deleted todo {todo} from list {calendar}'); |
|
57 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo') { |
|
58 | + $subject = $this->l->t('{actor} updated todo {todo} in list {calendar}'); |
|
59 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_self') { |
|
60 | + $subject = $this->l->t('You updated todo {todo} in list {calendar}'); |
|
61 | 61 | |
62 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed') { |
|
63 | - $subject = $this->l->t('{actor} solved todo {todo} in list {calendar}'); |
|
64 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self') { |
|
65 | - $subject = $this->l->t('You solved todo {todo} in list {calendar}'); |
|
66 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action') { |
|
67 | - $subject = $this->l->t('{actor} reopened todo {todo} in list {calendar}'); |
|
68 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self') { |
|
69 | - $subject = $this->l->t('You reopened todo {todo} in list {calendar}'); |
|
70 | - } else { |
|
71 | - throw new \InvalidArgumentException(); |
|
72 | - } |
|
62 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed') { |
|
63 | + $subject = $this->l->t('{actor} solved todo {todo} in list {calendar}'); |
|
64 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self') { |
|
65 | + $subject = $this->l->t('You solved todo {todo} in list {calendar}'); |
|
66 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action') { |
|
67 | + $subject = $this->l->t('{actor} reopened todo {todo} in list {calendar}'); |
|
68 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self') { |
|
69 | + $subject = $this->l->t('You reopened todo {todo} in list {calendar}'); |
|
70 | + } else { |
|
71 | + throw new \InvalidArgumentException(); |
|
72 | + } |
|
73 | 73 | |
74 | - $parsedParameters = $this->getParameters($event); |
|
75 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
74 | + $parsedParameters = $this->getParameters($event); |
|
75 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
76 | 76 | |
77 | - $event = $this->eventMerger->mergeEvents('todo', $event, $previousEvent); |
|
77 | + $event = $this->eventMerger->mergeEvents('todo', $event, $previousEvent); |
|
78 | 78 | |
79 | - return $event; |
|
80 | - } |
|
79 | + return $event; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param IEvent $event |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getParameters(IEvent $event) { |
|
87 | - $subject = $event->getSubject(); |
|
88 | - $parameters = $event->getSubjectParameters(); |
|
82 | + /** |
|
83 | + * @param IEvent $event |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getParameters(IEvent $event) { |
|
87 | + $subject = $event->getSubject(); |
|
88 | + $parameters = $event->getSubjectParameters(); |
|
89 | 89 | |
90 | - switch ($subject) { |
|
91 | - case self::SUBJECT_OBJECT_ADD . '_todo': |
|
92 | - case self::SUBJECT_OBJECT_DELETE . '_todo': |
|
93 | - case self::SUBJECT_OBJECT_UPDATE . '_todo': |
|
94 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_completed': |
|
95 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action': |
|
96 | - return [ |
|
97 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
98 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
99 | - 'todo' => $this->generateObjectParameter($parameters[2]), |
|
100 | - ]; |
|
101 | - case self::SUBJECT_OBJECT_ADD . '_todo_self': |
|
102 | - case self::SUBJECT_OBJECT_DELETE . '_todo_self': |
|
103 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_self': |
|
104 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self': |
|
105 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self': |
|
106 | - return [ |
|
107 | - 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
108 | - 'todo' => $this->generateObjectParameter($parameters[2]), |
|
109 | - ]; |
|
110 | - } |
|
90 | + switch ($subject) { |
|
91 | + case self::SUBJECT_OBJECT_ADD . '_todo': |
|
92 | + case self::SUBJECT_OBJECT_DELETE . '_todo': |
|
93 | + case self::SUBJECT_OBJECT_UPDATE . '_todo': |
|
94 | + case self::SUBJECT_OBJECT_UPDATE . '_todo_completed': |
|
95 | + case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action': |
|
96 | + return [ |
|
97 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
98 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
99 | + 'todo' => $this->generateObjectParameter($parameters[2]), |
|
100 | + ]; |
|
101 | + case self::SUBJECT_OBJECT_ADD . '_todo_self': |
|
102 | + case self::SUBJECT_OBJECT_DELETE . '_todo_self': |
|
103 | + case self::SUBJECT_OBJECT_UPDATE . '_todo_self': |
|
104 | + case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self': |
|
105 | + case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self': |
|
106 | + return [ |
|
107 | + 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
|
108 | + 'todo' => $this->generateObjectParameter($parameters[2]), |
|
109 | + ]; |
|
110 | + } |
|
111 | 111 | |
112 | - throw new \InvalidArgumentException(); |
|
113 | - } |
|
112 | + throw new \InvalidArgumentException(); |
|
113 | + } |
|
114 | 114 | } |
@@ -46,26 +46,26 @@ discard block |
||
46 | 46 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg'))); |
47 | 47 | } |
48 | 48 | |
49 | - if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo') { |
|
49 | + if ($event->getSubject() === self::SUBJECT_OBJECT_ADD.'_todo') { |
|
50 | 50 | $subject = $this->l->t('{actor} created todo {todo} in list {calendar}'); |
51 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo_self') { |
|
51 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_ADD.'_todo_self') { |
|
52 | 52 | $subject = $this->l->t('You created todo {todo} in list {calendar}'); |
53 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo') { |
|
53 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE.'_todo') { |
|
54 | 54 | $subject = $this->l->t('{actor} deleted todo {todo} from list {calendar}'); |
55 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo_self') { |
|
55 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_DELETE.'_todo_self') { |
|
56 | 56 | $subject = $this->l->t('You deleted todo {todo} from list {calendar}'); |
57 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo') { |
|
57 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo') { |
|
58 | 58 | $subject = $this->l->t('{actor} updated todo {todo} in list {calendar}'); |
59 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_self') { |
|
59 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo_self') { |
|
60 | 60 | $subject = $this->l->t('You updated todo {todo} in list {calendar}'); |
61 | 61 | |
62 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed') { |
|
62 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo_completed') { |
|
63 | 63 | $subject = $this->l->t('{actor} solved todo {todo} in list {calendar}'); |
64 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self') { |
|
64 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo_completed_self') { |
|
65 | 65 | $subject = $this->l->t('You solved todo {todo} in list {calendar}'); |
66 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action') { |
|
66 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo_needs_action') { |
|
67 | 67 | $subject = $this->l->t('{actor} reopened todo {todo} in list {calendar}'); |
68 | - } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self') { |
|
68 | + } else if ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE.'_todo_needs_action_self') { |
|
69 | 69 | $subject = $this->l->t('You reopened todo {todo} in list {calendar}'); |
70 | 70 | } else { |
71 | 71 | throw new \InvalidArgumentException(); |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | $parameters = $event->getSubjectParameters(); |
89 | 89 | |
90 | 90 | switch ($subject) { |
91 | - case self::SUBJECT_OBJECT_ADD . '_todo': |
|
92 | - case self::SUBJECT_OBJECT_DELETE . '_todo': |
|
93 | - case self::SUBJECT_OBJECT_UPDATE . '_todo': |
|
94 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_completed': |
|
95 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action': |
|
91 | + case self::SUBJECT_OBJECT_ADD.'_todo': |
|
92 | + case self::SUBJECT_OBJECT_DELETE.'_todo': |
|
93 | + case self::SUBJECT_OBJECT_UPDATE.'_todo': |
|
94 | + case self::SUBJECT_OBJECT_UPDATE.'_todo_completed': |
|
95 | + case self::SUBJECT_OBJECT_UPDATE.'_todo_needs_action': |
|
96 | 96 | return [ |
97 | 97 | 'actor' => $this->generateUserParameter($parameters[0]), |
98 | 98 | 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
99 | 99 | 'todo' => $this->generateObjectParameter($parameters[2]), |
100 | 100 | ]; |
101 | - case self::SUBJECT_OBJECT_ADD . '_todo_self': |
|
102 | - case self::SUBJECT_OBJECT_DELETE . '_todo_self': |
|
103 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_self': |
|
104 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self': |
|
105 | - case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self': |
|
101 | + case self::SUBJECT_OBJECT_ADD.'_todo_self': |
|
102 | + case self::SUBJECT_OBJECT_DELETE.'_todo_self': |
|
103 | + case self::SUBJECT_OBJECT_UPDATE.'_todo_self': |
|
104 | + case self::SUBJECT_OBJECT_UPDATE.'_todo_completed_self': |
|
105 | + case self::SUBJECT_OBJECT_UPDATE.'_todo_needs_action_self': |
|
106 | 106 | return [ |
107 | 107 | 'calendar' => $this->generateCalendarParameter($event->getObjectId(), $parameters[1]), |
108 | 108 | 'todo' => $this->generateObjectParameter($parameters[2]), |
@@ -33,366 +33,366 @@ |
||
33 | 33 | |
34 | 34 | class Provider implements IProvider { |
35 | 35 | |
36 | - /** @var IFactory */ |
|
37 | - protected $languageFactory; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - /** @var IL10N */ |
|
42 | - protected $activityLang; |
|
43 | - |
|
44 | - /** @var IURLGenerator */ |
|
45 | - protected $url; |
|
46 | - |
|
47 | - /** @var IManager */ |
|
48 | - protected $activityManager; |
|
49 | - |
|
50 | - /** @var IUserManager */ |
|
51 | - protected $userManager; |
|
52 | - |
|
53 | - /** @var IEventMerger */ |
|
54 | - protected $eventMerger; |
|
55 | - |
|
56 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
57 | - protected $displayNames = []; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IFactory $languageFactory |
|
61 | - * @param IURLGenerator $url |
|
62 | - * @param IManager $activityManager |
|
63 | - * @param IUserManager $userManager |
|
64 | - * @param IEventMerger $eventMerger |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
69 | - $this->activityManager = $activityManager; |
|
70 | - $this->userManager = $userManager; |
|
71 | - $this->eventMerger = $eventMerger; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $language |
|
76 | - * @param IEvent $event |
|
77 | - * @param IEvent|null $previousEvent |
|
78 | - * @return IEvent |
|
79 | - * @throws \InvalidArgumentException |
|
80 | - * @since 11.0.0 |
|
81 | - */ |
|
82 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
83 | - if ($event->getApp() !== 'files') { |
|
84 | - throw new \InvalidArgumentException(); |
|
85 | - } |
|
86 | - |
|
87 | - $this->l = $this->languageFactory->get('files', $language); |
|
88 | - $this->activityLang = $this->languageFactory->get('activity', $language); |
|
89 | - |
|
90 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
91 | - try { |
|
92 | - return $this->parseShortVersion($event, $previousEvent); |
|
93 | - } catch (\InvalidArgumentException $e) { |
|
94 | - // Ignore and simply use the long version... |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - return $this->parseLongVersion($event, $previousEvent); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param IEvent $event |
|
103 | - * @param IEvent|null $previousEvent |
|
104 | - * @return IEvent |
|
105 | - * @throws \InvalidArgumentException |
|
106 | - * @since 11.0.0 |
|
107 | - */ |
|
108 | - public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
109 | - $parsedParameters = $this->getParameters($event); |
|
110 | - |
|
111 | - if ($event->getSubject() === 'created_by') { |
|
112 | - $subject = $this->l->t('Created by {user}'); |
|
113 | - if ($this->activityManager->getRequirePNG()) { |
|
114 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
115 | - } else { |
|
116 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
117 | - } |
|
118 | - } else if ($event->getSubject() === 'changed_by') { |
|
119 | - $subject = $this->l->t('Changed by {user}'); |
|
120 | - if ($this->activityManager->getRequirePNG()) { |
|
121 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
122 | - } else { |
|
123 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
124 | - } |
|
125 | - } else if ($event->getSubject() === 'deleted_by') { |
|
126 | - $subject = $this->l->t('Deleted by {user}'); |
|
127 | - if ($this->activityManager->getRequirePNG()) { |
|
128 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
129 | - } else { |
|
130 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
131 | - } |
|
132 | - } else if ($event->getSubject() === 'restored_by') { |
|
133 | - $subject = $this->l->t('Restored by {user}'); |
|
134 | - } else if ($event->getSubject() === 'renamed_by') { |
|
135 | - $subject = $this->l->t('Renamed by {user}'); |
|
136 | - if ($this->activityManager->getRequirePNG()) { |
|
137 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
138 | - } else { |
|
139 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
140 | - } |
|
141 | - } else if ($event->getSubject() === 'moved_by') { |
|
142 | - $subject = $this->l->t('Moved by {user}'); |
|
143 | - if ($this->activityManager->getRequirePNG()) { |
|
144 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
145 | - } else { |
|
146 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
147 | - } |
|
148 | - } else { |
|
149 | - throw new \InvalidArgumentException(); |
|
150 | - } |
|
151 | - |
|
152 | - if (!isset($parsedParameters['user'])) { |
|
153 | - // External user via public link share |
|
154 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
155 | - } |
|
156 | - |
|
157 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
158 | - |
|
159 | - return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @param IEvent $event |
|
164 | - * @param IEvent|null $previousEvent |
|
165 | - * @return IEvent |
|
166 | - * @throws \InvalidArgumentException |
|
167 | - * @since 11.0.0 |
|
168 | - */ |
|
169 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
170 | - $parsedParameters = $this->getParameters($event); |
|
171 | - |
|
172 | - if ($event->getSubject() === 'created_self') { |
|
173 | - $subject = $this->l->t('You created {file}'); |
|
174 | - if ($this->activityManager->getRequirePNG()) { |
|
175 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
176 | - } else { |
|
177 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
178 | - } |
|
179 | - } else if ($event->getSubject() === 'created_by') { |
|
180 | - $subject = $this->l->t('{user} created {file}'); |
|
181 | - if ($this->activityManager->getRequirePNG()) { |
|
182 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
183 | - } else { |
|
184 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
185 | - } |
|
186 | - } else if ($event->getSubject() === 'created_public') { |
|
187 | - $subject = $this->l->t('{file} was created in a public folder'); |
|
188 | - if ($this->activityManager->getRequirePNG()) { |
|
189 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
190 | - } else { |
|
191 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
192 | - } |
|
193 | - } else if ($event->getSubject() === 'changed_self') { |
|
194 | - $subject = $this->l->t('You changed {file}'); |
|
195 | - if ($this->activityManager->getRequirePNG()) { |
|
196 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
197 | - } else { |
|
198 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
199 | - } |
|
200 | - } else if ($event->getSubject() === 'changed_by') { |
|
201 | - $subject = $this->l->t('{user} changed {file}'); |
|
202 | - if ($this->activityManager->getRequirePNG()) { |
|
203 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
204 | - } else { |
|
205 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
206 | - } |
|
207 | - } else if ($event->getSubject() === 'deleted_self') { |
|
208 | - $subject = $this->l->t('You deleted {file}'); |
|
209 | - if ($this->activityManager->getRequirePNG()) { |
|
210 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
211 | - } else { |
|
212 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
213 | - } |
|
214 | - } else if ($event->getSubject() === 'deleted_by') { |
|
215 | - $subject = $this->l->t('{user} deleted {file}'); |
|
216 | - if ($this->activityManager->getRequirePNG()) { |
|
217 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
218 | - } else { |
|
219 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
220 | - } |
|
221 | - } else if ($event->getSubject() === 'restored_self') { |
|
222 | - $subject = $this->l->t('You restored {file}'); |
|
223 | - } else if ($event->getSubject() === 'restored_by') { |
|
224 | - $subject = $this->l->t('{user} restored {file}'); |
|
225 | - } else if ($event->getSubject() === 'renamed_self') { |
|
226 | - $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
227 | - if ($this->activityManager->getRequirePNG()) { |
|
228 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
229 | - } else { |
|
230 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
231 | - } |
|
232 | - } else if ($event->getSubject() === 'renamed_by') { |
|
233 | - $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
234 | - if ($this->activityManager->getRequirePNG()) { |
|
235 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
236 | - } else { |
|
237 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
238 | - } |
|
239 | - } else if ($event->getSubject() === 'moved_self') { |
|
240 | - $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
241 | - if ($this->activityManager->getRequirePNG()) { |
|
242 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
243 | - } else { |
|
244 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
245 | - } |
|
246 | - } else if ($event->getSubject() === 'moved_by') { |
|
247 | - $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
248 | - if ($this->activityManager->getRequirePNG()) { |
|
249 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
250 | - } else { |
|
251 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
252 | - } |
|
253 | - } else { |
|
254 | - throw new \InvalidArgumentException(); |
|
255 | - } |
|
256 | - |
|
257 | - if (!isset($parsedParameters['user'])) { |
|
258 | - // External user via public link share |
|
259 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
260 | - } |
|
261 | - |
|
262 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
263 | - |
|
264 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
265 | - |
|
266 | - if ($event->getChildEvent() === null) { |
|
267 | - // Couldn't group by file, maybe we can group by user |
|
268 | - $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
269 | - } |
|
270 | - |
|
271 | - return $event; |
|
272 | - } |
|
273 | - |
|
274 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
275 | - $placeholders = $replacements = []; |
|
276 | - foreach ($parameters as $placeholder => $parameter) { |
|
277 | - $placeholders[] = '{' . $placeholder . '}'; |
|
278 | - if ($parameter['type'] === 'file') { |
|
279 | - $replacements[] = $parameter['path']; |
|
280 | - } else { |
|
281 | - $replacements[] = $parameter['name']; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
286 | - ->setRichSubject($subject, $parameters); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param IEvent $event |
|
291 | - * @return array |
|
292 | - * @throws \InvalidArgumentException |
|
293 | - */ |
|
294 | - protected function getParameters(IEvent $event) { |
|
295 | - $parameters = $event->getSubjectParameters(); |
|
296 | - switch ($event->getSubject()) { |
|
297 | - case 'created_self': |
|
298 | - case 'created_public': |
|
299 | - case 'changed_self': |
|
300 | - case 'deleted_self': |
|
301 | - case 'restored_self': |
|
302 | - return [ |
|
303 | - 'file' => $this->getFile($parameters[0], $event), |
|
304 | - ]; |
|
305 | - case 'created_by': |
|
306 | - case 'changed_by': |
|
307 | - case 'deleted_by': |
|
308 | - case 'restored_by': |
|
309 | - if ($parameters[1] === '') { |
|
310 | - // External user via public link share |
|
311 | - return [ |
|
312 | - 'file' => $this->getFile($parameters[0], $event), |
|
313 | - ]; |
|
314 | - } |
|
315 | - return [ |
|
316 | - 'file' => $this->getFile($parameters[0], $event), |
|
317 | - 'user' => $this->getUser($parameters[1]), |
|
318 | - ]; |
|
319 | - case 'renamed_self': |
|
320 | - case 'moved_self': |
|
321 | - return [ |
|
322 | - 'newfile' => $this->getFile($parameters[0]), |
|
323 | - 'oldfile' => $this->getFile($parameters[1]), |
|
324 | - ]; |
|
325 | - case 'renamed_by': |
|
326 | - case 'moved_by': |
|
327 | - if ($parameters[1] === '') { |
|
328 | - // External user via public link share |
|
329 | - return [ |
|
330 | - 'newfile' => $this->getFile($parameters[0]), |
|
331 | - 'oldfile' => $this->getFile($parameters[2]), |
|
332 | - ]; |
|
333 | - } |
|
334 | - return [ |
|
335 | - 'newfile' => $this->getFile($parameters[0]), |
|
336 | - 'user' => $this->getUser($parameters[1]), |
|
337 | - 'oldfile' => $this->getFile($parameters[2]), |
|
338 | - ]; |
|
339 | - } |
|
340 | - return []; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @param array|string $parameter |
|
345 | - * @param IEvent|null $event |
|
346 | - * @return array |
|
347 | - * @throws \InvalidArgumentException |
|
348 | - */ |
|
349 | - protected function getFile($parameter, IEvent $event = null) { |
|
350 | - if (is_array($parameter)) { |
|
351 | - $path = reset($parameter); |
|
352 | - $id = (string) key($parameter); |
|
353 | - } else if ($event !== null) { |
|
354 | - // Legacy from before ownCloud 8.2 |
|
355 | - $path = $parameter; |
|
356 | - $id = $event->getObjectId(); |
|
357 | - } else { |
|
358 | - throw new \InvalidArgumentException('Could not generate file parameter'); |
|
359 | - } |
|
360 | - |
|
361 | - return [ |
|
362 | - 'type' => 'file', |
|
363 | - 'id' => $id, |
|
364 | - 'name' => basename($path), |
|
365 | - 'path' => trim($path, '/'), |
|
366 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
367 | - ]; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $uid |
|
372 | - * @return array |
|
373 | - */ |
|
374 | - protected function getUser($uid) { |
|
375 | - if (!isset($this->displayNames[$uid])) { |
|
376 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
377 | - } |
|
378 | - |
|
379 | - return [ |
|
380 | - 'type' => 'user', |
|
381 | - 'id' => $uid, |
|
382 | - 'name' => $this->displayNames[$uid], |
|
383 | - ]; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $uid |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - protected function getDisplayName($uid) { |
|
391 | - $user = $this->userManager->get($uid); |
|
392 | - if ($user instanceof IUser) { |
|
393 | - return $user->getDisplayName(); |
|
394 | - } else { |
|
395 | - return $uid; |
|
396 | - } |
|
397 | - } |
|
36 | + /** @var IFactory */ |
|
37 | + protected $languageFactory; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + /** @var IL10N */ |
|
42 | + protected $activityLang; |
|
43 | + |
|
44 | + /** @var IURLGenerator */ |
|
45 | + protected $url; |
|
46 | + |
|
47 | + /** @var IManager */ |
|
48 | + protected $activityManager; |
|
49 | + |
|
50 | + /** @var IUserManager */ |
|
51 | + protected $userManager; |
|
52 | + |
|
53 | + /** @var IEventMerger */ |
|
54 | + protected $eventMerger; |
|
55 | + |
|
56 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
57 | + protected $displayNames = []; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IFactory $languageFactory |
|
61 | + * @param IURLGenerator $url |
|
62 | + * @param IManager $activityManager |
|
63 | + * @param IUserManager $userManager |
|
64 | + * @param IEventMerger $eventMerger |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
69 | + $this->activityManager = $activityManager; |
|
70 | + $this->userManager = $userManager; |
|
71 | + $this->eventMerger = $eventMerger; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $language |
|
76 | + * @param IEvent $event |
|
77 | + * @param IEvent|null $previousEvent |
|
78 | + * @return IEvent |
|
79 | + * @throws \InvalidArgumentException |
|
80 | + * @since 11.0.0 |
|
81 | + */ |
|
82 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
83 | + if ($event->getApp() !== 'files') { |
|
84 | + throw new \InvalidArgumentException(); |
|
85 | + } |
|
86 | + |
|
87 | + $this->l = $this->languageFactory->get('files', $language); |
|
88 | + $this->activityLang = $this->languageFactory->get('activity', $language); |
|
89 | + |
|
90 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
91 | + try { |
|
92 | + return $this->parseShortVersion($event, $previousEvent); |
|
93 | + } catch (\InvalidArgumentException $e) { |
|
94 | + // Ignore and simply use the long version... |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + return $this->parseLongVersion($event, $previousEvent); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param IEvent $event |
|
103 | + * @param IEvent|null $previousEvent |
|
104 | + * @return IEvent |
|
105 | + * @throws \InvalidArgumentException |
|
106 | + * @since 11.0.0 |
|
107 | + */ |
|
108 | + public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
109 | + $parsedParameters = $this->getParameters($event); |
|
110 | + |
|
111 | + if ($event->getSubject() === 'created_by') { |
|
112 | + $subject = $this->l->t('Created by {user}'); |
|
113 | + if ($this->activityManager->getRequirePNG()) { |
|
114 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
115 | + } else { |
|
116 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
117 | + } |
|
118 | + } else if ($event->getSubject() === 'changed_by') { |
|
119 | + $subject = $this->l->t('Changed by {user}'); |
|
120 | + if ($this->activityManager->getRequirePNG()) { |
|
121 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
122 | + } else { |
|
123 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
124 | + } |
|
125 | + } else if ($event->getSubject() === 'deleted_by') { |
|
126 | + $subject = $this->l->t('Deleted by {user}'); |
|
127 | + if ($this->activityManager->getRequirePNG()) { |
|
128 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
129 | + } else { |
|
130 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
131 | + } |
|
132 | + } else if ($event->getSubject() === 'restored_by') { |
|
133 | + $subject = $this->l->t('Restored by {user}'); |
|
134 | + } else if ($event->getSubject() === 'renamed_by') { |
|
135 | + $subject = $this->l->t('Renamed by {user}'); |
|
136 | + if ($this->activityManager->getRequirePNG()) { |
|
137 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
138 | + } else { |
|
139 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
140 | + } |
|
141 | + } else if ($event->getSubject() === 'moved_by') { |
|
142 | + $subject = $this->l->t('Moved by {user}'); |
|
143 | + if ($this->activityManager->getRequirePNG()) { |
|
144 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
145 | + } else { |
|
146 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
147 | + } |
|
148 | + } else { |
|
149 | + throw new \InvalidArgumentException(); |
|
150 | + } |
|
151 | + |
|
152 | + if (!isset($parsedParameters['user'])) { |
|
153 | + // External user via public link share |
|
154 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
155 | + } |
|
156 | + |
|
157 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
158 | + |
|
159 | + return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @param IEvent $event |
|
164 | + * @param IEvent|null $previousEvent |
|
165 | + * @return IEvent |
|
166 | + * @throws \InvalidArgumentException |
|
167 | + * @since 11.0.0 |
|
168 | + */ |
|
169 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
170 | + $parsedParameters = $this->getParameters($event); |
|
171 | + |
|
172 | + if ($event->getSubject() === 'created_self') { |
|
173 | + $subject = $this->l->t('You created {file}'); |
|
174 | + if ($this->activityManager->getRequirePNG()) { |
|
175 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
176 | + } else { |
|
177 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
178 | + } |
|
179 | + } else if ($event->getSubject() === 'created_by') { |
|
180 | + $subject = $this->l->t('{user} created {file}'); |
|
181 | + if ($this->activityManager->getRequirePNG()) { |
|
182 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
183 | + } else { |
|
184 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
185 | + } |
|
186 | + } else if ($event->getSubject() === 'created_public') { |
|
187 | + $subject = $this->l->t('{file} was created in a public folder'); |
|
188 | + if ($this->activityManager->getRequirePNG()) { |
|
189 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
|
190 | + } else { |
|
191 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
|
192 | + } |
|
193 | + } else if ($event->getSubject() === 'changed_self') { |
|
194 | + $subject = $this->l->t('You changed {file}'); |
|
195 | + if ($this->activityManager->getRequirePNG()) { |
|
196 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
197 | + } else { |
|
198 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
199 | + } |
|
200 | + } else if ($event->getSubject() === 'changed_by') { |
|
201 | + $subject = $this->l->t('{user} changed {file}'); |
|
202 | + if ($this->activityManager->getRequirePNG()) { |
|
203 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
204 | + } else { |
|
205 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
206 | + } |
|
207 | + } else if ($event->getSubject() === 'deleted_self') { |
|
208 | + $subject = $this->l->t('You deleted {file}'); |
|
209 | + if ($this->activityManager->getRequirePNG()) { |
|
210 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
211 | + } else { |
|
212 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
213 | + } |
|
214 | + } else if ($event->getSubject() === 'deleted_by') { |
|
215 | + $subject = $this->l->t('{user} deleted {file}'); |
|
216 | + if ($this->activityManager->getRequirePNG()) { |
|
217 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
|
218 | + } else { |
|
219 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
|
220 | + } |
|
221 | + } else if ($event->getSubject() === 'restored_self') { |
|
222 | + $subject = $this->l->t('You restored {file}'); |
|
223 | + } else if ($event->getSubject() === 'restored_by') { |
|
224 | + $subject = $this->l->t('{user} restored {file}'); |
|
225 | + } else if ($event->getSubject() === 'renamed_self') { |
|
226 | + $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
227 | + if ($this->activityManager->getRequirePNG()) { |
|
228 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
229 | + } else { |
|
230 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
231 | + } |
|
232 | + } else if ($event->getSubject() === 'renamed_by') { |
|
233 | + $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
234 | + if ($this->activityManager->getRequirePNG()) { |
|
235 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
236 | + } else { |
|
237 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
238 | + } |
|
239 | + } else if ($event->getSubject() === 'moved_self') { |
|
240 | + $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
241 | + if ($this->activityManager->getRequirePNG()) { |
|
242 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
243 | + } else { |
|
244 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
245 | + } |
|
246 | + } else if ($event->getSubject() === 'moved_by') { |
|
247 | + $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
248 | + if ($this->activityManager->getRequirePNG()) { |
|
249 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
|
250 | + } else { |
|
251 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
|
252 | + } |
|
253 | + } else { |
|
254 | + throw new \InvalidArgumentException(); |
|
255 | + } |
|
256 | + |
|
257 | + if (!isset($parsedParameters['user'])) { |
|
258 | + // External user via public link share |
|
259 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
260 | + } |
|
261 | + |
|
262 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
263 | + |
|
264 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
265 | + |
|
266 | + if ($event->getChildEvent() === null) { |
|
267 | + // Couldn't group by file, maybe we can group by user |
|
268 | + $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
269 | + } |
|
270 | + |
|
271 | + return $event; |
|
272 | + } |
|
273 | + |
|
274 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
275 | + $placeholders = $replacements = []; |
|
276 | + foreach ($parameters as $placeholder => $parameter) { |
|
277 | + $placeholders[] = '{' . $placeholder . '}'; |
|
278 | + if ($parameter['type'] === 'file') { |
|
279 | + $replacements[] = $parameter['path']; |
|
280 | + } else { |
|
281 | + $replacements[] = $parameter['name']; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
286 | + ->setRichSubject($subject, $parameters); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param IEvent $event |
|
291 | + * @return array |
|
292 | + * @throws \InvalidArgumentException |
|
293 | + */ |
|
294 | + protected function getParameters(IEvent $event) { |
|
295 | + $parameters = $event->getSubjectParameters(); |
|
296 | + switch ($event->getSubject()) { |
|
297 | + case 'created_self': |
|
298 | + case 'created_public': |
|
299 | + case 'changed_self': |
|
300 | + case 'deleted_self': |
|
301 | + case 'restored_self': |
|
302 | + return [ |
|
303 | + 'file' => $this->getFile($parameters[0], $event), |
|
304 | + ]; |
|
305 | + case 'created_by': |
|
306 | + case 'changed_by': |
|
307 | + case 'deleted_by': |
|
308 | + case 'restored_by': |
|
309 | + if ($parameters[1] === '') { |
|
310 | + // External user via public link share |
|
311 | + return [ |
|
312 | + 'file' => $this->getFile($parameters[0], $event), |
|
313 | + ]; |
|
314 | + } |
|
315 | + return [ |
|
316 | + 'file' => $this->getFile($parameters[0], $event), |
|
317 | + 'user' => $this->getUser($parameters[1]), |
|
318 | + ]; |
|
319 | + case 'renamed_self': |
|
320 | + case 'moved_self': |
|
321 | + return [ |
|
322 | + 'newfile' => $this->getFile($parameters[0]), |
|
323 | + 'oldfile' => $this->getFile($parameters[1]), |
|
324 | + ]; |
|
325 | + case 'renamed_by': |
|
326 | + case 'moved_by': |
|
327 | + if ($parameters[1] === '') { |
|
328 | + // External user via public link share |
|
329 | + return [ |
|
330 | + 'newfile' => $this->getFile($parameters[0]), |
|
331 | + 'oldfile' => $this->getFile($parameters[2]), |
|
332 | + ]; |
|
333 | + } |
|
334 | + return [ |
|
335 | + 'newfile' => $this->getFile($parameters[0]), |
|
336 | + 'user' => $this->getUser($parameters[1]), |
|
337 | + 'oldfile' => $this->getFile($parameters[2]), |
|
338 | + ]; |
|
339 | + } |
|
340 | + return []; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @param array|string $parameter |
|
345 | + * @param IEvent|null $event |
|
346 | + * @return array |
|
347 | + * @throws \InvalidArgumentException |
|
348 | + */ |
|
349 | + protected function getFile($parameter, IEvent $event = null) { |
|
350 | + if (is_array($parameter)) { |
|
351 | + $path = reset($parameter); |
|
352 | + $id = (string) key($parameter); |
|
353 | + } else if ($event !== null) { |
|
354 | + // Legacy from before ownCloud 8.2 |
|
355 | + $path = $parameter; |
|
356 | + $id = $event->getObjectId(); |
|
357 | + } else { |
|
358 | + throw new \InvalidArgumentException('Could not generate file parameter'); |
|
359 | + } |
|
360 | + |
|
361 | + return [ |
|
362 | + 'type' => 'file', |
|
363 | + 'id' => $id, |
|
364 | + 'name' => basename($path), |
|
365 | + 'path' => trim($path, '/'), |
|
366 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
367 | + ]; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $uid |
|
372 | + * @return array |
|
373 | + */ |
|
374 | + protected function getUser($uid) { |
|
375 | + if (!isset($this->displayNames[$uid])) { |
|
376 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
377 | + } |
|
378 | + |
|
379 | + return [ |
|
380 | + 'type' => 'user', |
|
381 | + 'id' => $uid, |
|
382 | + 'name' => $this->displayNames[$uid], |
|
383 | + ]; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $uid |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + protected function getDisplayName($uid) { |
|
391 | + $user = $this->userManager->get($uid); |
|
392 | + if ($user instanceof IUser) { |
|
393 | + return $user->getDisplayName(); |
|
394 | + } else { |
|
395 | + return $uid; |
|
396 | + } |
|
397 | + } |
|
398 | 398 | } |
@@ -31,147 +31,147 @@ |
||
31 | 31 | |
32 | 32 | class FavoriteProvider implements IProvider { |
33 | 33 | |
34 | - const SUBJECT_ADDED = 'added_favorite'; |
|
35 | - const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | - |
|
37 | - /** @var IFactory */ |
|
38 | - protected $languageFactory; |
|
39 | - |
|
40 | - /** @var IL10N */ |
|
41 | - protected $l; |
|
42 | - |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $url; |
|
45 | - |
|
46 | - /** @var IManager */ |
|
47 | - protected $activityManager; |
|
48 | - |
|
49 | - /** @var IEventMerger */ |
|
50 | - protected $eventMerger; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param IFactory $languageFactory |
|
54 | - * @param IURLGenerator $url |
|
55 | - * @param IManager $activityManager |
|
56 | - * @param IEventMerger $eventMerger |
|
57 | - */ |
|
58 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | - $this->languageFactory = $languageFactory; |
|
60 | - $this->url = $url; |
|
61 | - $this->activityManager = $activityManager; |
|
62 | - $this->eventMerger = $eventMerger; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $language |
|
67 | - * @param IEvent $event |
|
68 | - * @param IEvent|null $previousEvent |
|
69 | - * @return IEvent |
|
70 | - * @throws \InvalidArgumentException |
|
71 | - * @since 11.0.0 |
|
72 | - */ |
|
73 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | - if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | - throw new \InvalidArgumentException(); |
|
76 | - } |
|
77 | - |
|
78 | - $this->l = $this->languageFactory->get('files', $language); |
|
79 | - |
|
80 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | - try { |
|
82 | - return $this->parseShortVersion($event); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - // Ignore and simply use the long version... |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - return $this->parseLongVersion($event, $previousEvent); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IEvent $event |
|
93 | - * @return IEvent |
|
94 | - * @throws \InvalidArgumentException |
|
95 | - * @since 11.0.0 |
|
96 | - */ |
|
97 | - public function parseShortVersion(IEvent $event) { |
|
98 | - |
|
99 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | - $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | - if ($this->activityManager->getRequirePNG()) { |
|
102 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | - } else { |
|
104 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | - } |
|
106 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | - $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | - if ($this->activityManager->getRequirePNG()) { |
|
109 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | - } else { |
|
111 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | - } |
|
113 | - } else { |
|
114 | - throw new \InvalidArgumentException(); |
|
115 | - } |
|
116 | - |
|
117 | - return $event; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param IEvent $event |
|
122 | - * @param IEvent|null $previousEvent |
|
123 | - * @return IEvent |
|
124 | - * @throws \InvalidArgumentException |
|
125 | - * @since 11.0.0 |
|
126 | - */ |
|
127 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | - |
|
129 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | - $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | - if ($this->activityManager->getRequirePNG()) { |
|
132 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | - } else { |
|
134 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | - } |
|
136 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | - $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | - if ($this->activityManager->getRequirePNG()) { |
|
139 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | - } else { |
|
141 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | - } |
|
143 | - } else { |
|
144 | - throw new \InvalidArgumentException(); |
|
145 | - } |
|
146 | - |
|
147 | - $this->setSubjects($event, $subject); |
|
148 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | - return $event; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param IEvent $event |
|
154 | - * @param string $subject |
|
155 | - */ |
|
156 | - protected function setSubjects(IEvent $event, $subject) { |
|
157 | - $subjectParams = $event->getSubjectParameters(); |
|
158 | - if (empty($subjectParams)) { |
|
159 | - // Try to fall back to the old way, but this does not work for emails. |
|
160 | - // But at least old activities still work. |
|
161 | - $subjectParams = [ |
|
162 | - 'id' => $event->getObjectId(), |
|
163 | - 'path' => $event->getObjectName(), |
|
164 | - ]; |
|
165 | - } |
|
166 | - $parameter = [ |
|
167 | - 'type' => 'file', |
|
168 | - 'id' => $subjectParams['id'], |
|
169 | - 'name' => basename($subjectParams['path']), |
|
170 | - 'path' => trim($subjectParams['path'], '/'), |
|
171 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | - ]; |
|
173 | - |
|
174 | - $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | - ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | - } |
|
34 | + const SUBJECT_ADDED = 'added_favorite'; |
|
35 | + const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | + |
|
37 | + /** @var IFactory */ |
|
38 | + protected $languageFactory; |
|
39 | + |
|
40 | + /** @var IL10N */ |
|
41 | + protected $l; |
|
42 | + |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $url; |
|
45 | + |
|
46 | + /** @var IManager */ |
|
47 | + protected $activityManager; |
|
48 | + |
|
49 | + /** @var IEventMerger */ |
|
50 | + protected $eventMerger; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param IFactory $languageFactory |
|
54 | + * @param IURLGenerator $url |
|
55 | + * @param IManager $activityManager |
|
56 | + * @param IEventMerger $eventMerger |
|
57 | + */ |
|
58 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | + $this->languageFactory = $languageFactory; |
|
60 | + $this->url = $url; |
|
61 | + $this->activityManager = $activityManager; |
|
62 | + $this->eventMerger = $eventMerger; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $language |
|
67 | + * @param IEvent $event |
|
68 | + * @param IEvent|null $previousEvent |
|
69 | + * @return IEvent |
|
70 | + * @throws \InvalidArgumentException |
|
71 | + * @since 11.0.0 |
|
72 | + */ |
|
73 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | + if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | + throw new \InvalidArgumentException(); |
|
76 | + } |
|
77 | + |
|
78 | + $this->l = $this->languageFactory->get('files', $language); |
|
79 | + |
|
80 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | + try { |
|
82 | + return $this->parseShortVersion($event); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + // Ignore and simply use the long version... |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + return $this->parseLongVersion($event, $previousEvent); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IEvent $event |
|
93 | + * @return IEvent |
|
94 | + * @throws \InvalidArgumentException |
|
95 | + * @since 11.0.0 |
|
96 | + */ |
|
97 | + public function parseShortVersion(IEvent $event) { |
|
98 | + |
|
99 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | + $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | + if ($this->activityManager->getRequirePNG()) { |
|
102 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | + } else { |
|
104 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | + } |
|
106 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | + $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | + if ($this->activityManager->getRequirePNG()) { |
|
109 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | + } else { |
|
111 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | + } |
|
113 | + } else { |
|
114 | + throw new \InvalidArgumentException(); |
|
115 | + } |
|
116 | + |
|
117 | + return $event; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param IEvent $event |
|
122 | + * @param IEvent|null $previousEvent |
|
123 | + * @return IEvent |
|
124 | + * @throws \InvalidArgumentException |
|
125 | + * @since 11.0.0 |
|
126 | + */ |
|
127 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | + |
|
129 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | + $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | + if ($this->activityManager->getRequirePNG()) { |
|
132 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | + } else { |
|
134 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | + } |
|
136 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | + $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | + if ($this->activityManager->getRequirePNG()) { |
|
139 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | + } else { |
|
141 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | + } |
|
143 | + } else { |
|
144 | + throw new \InvalidArgumentException(); |
|
145 | + } |
|
146 | + |
|
147 | + $this->setSubjects($event, $subject); |
|
148 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | + return $event; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param IEvent $event |
|
154 | + * @param string $subject |
|
155 | + */ |
|
156 | + protected function setSubjects(IEvent $event, $subject) { |
|
157 | + $subjectParams = $event->getSubjectParameters(); |
|
158 | + if (empty($subjectParams)) { |
|
159 | + // Try to fall back to the old way, but this does not work for emails. |
|
160 | + // But at least old activities still work. |
|
161 | + $subjectParams = [ |
|
162 | + 'id' => $event->getObjectId(), |
|
163 | + 'path' => $event->getObjectName(), |
|
164 | + ]; |
|
165 | + } |
|
166 | + $parameter = [ |
|
167 | + 'type' => 'file', |
|
168 | + 'id' => $subjectParams['id'], |
|
169 | + 'name' => basename($subjectParams['path']), |
|
170 | + 'path' => trim($subjectParams['path'], '/'), |
|
171 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | + ]; |
|
173 | + |
|
174 | + $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | + ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | + } |
|
177 | 177 | } |
@@ -31,55 +31,55 @@ |
||
31 | 31 | |
32 | 32 | class SecurityProvider implements IProvider { |
33 | 33 | |
34 | - /** @var L10nFactory */ |
|
35 | - private $l10n; |
|
34 | + /** @var L10nFactory */ |
|
35 | + private $l10n; |
|
36 | 36 | |
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | 39 | |
40 | - /** @var IManager */ |
|
41 | - private $activityManager; |
|
40 | + /** @var IManager */ |
|
41 | + private $activityManager; |
|
42 | 42 | |
43 | - public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
44 | - $this->urlGenerator = $urlGenerator; |
|
45 | - $this->l10n = $l10n; |
|
46 | - $this->activityManager = $activityManager; |
|
47 | - } |
|
43 | + public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
44 | + $this->urlGenerator = $urlGenerator; |
|
45 | + $this->l10n = $l10n; |
|
46 | + $this->activityManager = $activityManager; |
|
47 | + } |
|
48 | 48 | |
49 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
50 | - if ($event->getType() !== 'security') { |
|
51 | - throw new InvalidArgumentException(); |
|
52 | - } |
|
49 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
50 | + if ($event->getType() !== 'security') { |
|
51 | + throw new InvalidArgumentException(); |
|
52 | + } |
|
53 | 53 | |
54 | - $l = $this->l10n->get('core', $language); |
|
54 | + $l = $this->l10n->get('core', $language); |
|
55 | 55 | |
56 | - switch ($event->getSubject()) { |
|
57 | - case 'twofactor_success': |
|
58 | - $params = $event->getSubjectParameters(); |
|
59 | - $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [ |
|
60 | - $params['provider'], |
|
61 | - ])); |
|
62 | - if ($this->activityManager->getRequirePNG()) { |
|
63 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
64 | - } else { |
|
65 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
66 | - } |
|
67 | - break; |
|
68 | - case 'twofactor_failed': |
|
69 | - $params = $event->getSubjectParameters(); |
|
70 | - $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [ |
|
71 | - $params['provider'], |
|
72 | - ])); |
|
73 | - if ($this->activityManager->getRequirePNG()) { |
|
74 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
75 | - } else { |
|
76 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
77 | - } |
|
78 | - break; |
|
79 | - default: |
|
80 | - throw new InvalidArgumentException(); |
|
81 | - } |
|
82 | - return $event; |
|
83 | - } |
|
56 | + switch ($event->getSubject()) { |
|
57 | + case 'twofactor_success': |
|
58 | + $params = $event->getSubjectParameters(); |
|
59 | + $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [ |
|
60 | + $params['provider'], |
|
61 | + ])); |
|
62 | + if ($this->activityManager->getRequirePNG()) { |
|
63 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
64 | + } else { |
|
65 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
66 | + } |
|
67 | + break; |
|
68 | + case 'twofactor_failed': |
|
69 | + $params = $event->getSubjectParameters(); |
|
70 | + $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [ |
|
71 | + $params['provider'], |
|
72 | + ])); |
|
73 | + if ($this->activityManager->getRequirePNG()) { |
|
74 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
75 | + } else { |
|
76 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
77 | + } |
|
78 | + break; |
|
79 | + default: |
|
80 | + throw new InvalidArgumentException(); |
|
81 | + } |
|
82 | + return $event; |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -32,157 +32,157 @@ |
||
32 | 32 | |
33 | 33 | class Provider implements IProvider { |
34 | 34 | |
35 | - const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | - const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | - const PASSWORD_RESET = 'password_changed'; |
|
38 | - const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | - const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | - const EMAIL_CHANGED = 'email_changed'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IManager */ |
|
55 | - private $activityManager; |
|
56 | - |
|
57 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | - protected $displayNames = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IFactory $languageFactory |
|
62 | - * @param IURLGenerator $url |
|
63 | - * @param IUserManager $userManager |
|
64 | - * @param IManager $activityManager |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->activityManager = $activityManager; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $language |
|
75 | - * @param IEvent $event |
|
76 | - * @param IEvent|null $previousEvent |
|
77 | - * @return IEvent |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @since 11.0.0 |
|
80 | - */ |
|
81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | - if ($event->getApp() !== 'settings') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('settings', $language); |
|
87 | - |
|
88 | - if ($this->activityManager->getRequirePNG()) { |
|
89 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | - } else { |
|
91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | - } |
|
93 | - |
|
94 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | - $subject = $this->l->t('{actor} changed your password'); |
|
96 | - } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | - $subject = $this->l->t('You changed your password'); |
|
98 | - } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | - |
|
101 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | - $subject = $this->l->t('{actor} changed your email address'); |
|
103 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | - $subject = $this->l->t('You changed your email address'); |
|
105 | - } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | - |
|
108 | - } else { |
|
109 | - throw new \InvalidArgumentException(); |
|
110 | - } |
|
111 | - |
|
112 | - $parsedParameters = $this->getParameters($event); |
|
113 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | - |
|
115 | - return $event; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param IEvent $event |
|
120 | - * @return array |
|
121 | - * @throws \InvalidArgumentException |
|
122 | - */ |
|
123 | - protected function getParameters(IEvent $event) { |
|
124 | - $subject = $event->getSubject(); |
|
125 | - $parameters = $event->getSubjectParameters(); |
|
126 | - |
|
127 | - switch ($subject) { |
|
128 | - case self::PASSWORD_CHANGED_SELF: |
|
129 | - case self::PASSWORD_RESET: |
|
130 | - case self::EMAIL_CHANGED_SELF: |
|
131 | - case self::EMAIL_CHANGED: |
|
132 | - return []; |
|
133 | - case self::PASSWORD_CHANGED_BY: |
|
134 | - case self::EMAIL_CHANGED_BY: |
|
135 | - return [ |
|
136 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | - ]; |
|
138 | - } |
|
139 | - |
|
140 | - throw new \InvalidArgumentException(); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IEvent $event |
|
145 | - * @param string $subject |
|
146 | - * @param array $parameters |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - */ |
|
149 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | - $placeholders = $replacements = []; |
|
151 | - foreach ($parameters as $placeholder => $parameter) { |
|
152 | - $placeholders[] = '{' . $placeholder . '}'; |
|
153 | - $replacements[] = $parameter['name']; |
|
154 | - } |
|
155 | - |
|
156 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | - ->setRichSubject($subject, $parameters); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $uid |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function generateUserParameter($uid) { |
|
165 | - if (!isset($this->displayNames[$uid])) { |
|
166 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | - } |
|
168 | - |
|
169 | - return [ |
|
170 | - 'type' => 'user', |
|
171 | - 'id' => $uid, |
|
172 | - 'name' => $this->displayNames[$uid], |
|
173 | - ]; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $uid |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - protected function getDisplayName($uid) { |
|
181 | - $user = $this->userManager->get($uid); |
|
182 | - if ($user instanceof IUser) { |
|
183 | - return $user->getDisplayName(); |
|
184 | - } |
|
185 | - |
|
186 | - return $uid; |
|
187 | - } |
|
35 | + const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | + const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | + const PASSWORD_RESET = 'password_changed'; |
|
38 | + const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | + const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | + const EMAIL_CHANGED = 'email_changed'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IManager */ |
|
55 | + private $activityManager; |
|
56 | + |
|
57 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | + protected $displayNames = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IFactory $languageFactory |
|
62 | + * @param IURLGenerator $url |
|
63 | + * @param IUserManager $userManager |
|
64 | + * @param IManager $activityManager |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->activityManager = $activityManager; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $language |
|
75 | + * @param IEvent $event |
|
76 | + * @param IEvent|null $previousEvent |
|
77 | + * @return IEvent |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @since 11.0.0 |
|
80 | + */ |
|
81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | + if ($event->getApp() !== 'settings') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('settings', $language); |
|
87 | + |
|
88 | + if ($this->activityManager->getRequirePNG()) { |
|
89 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | + } else { |
|
91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | + } |
|
93 | + |
|
94 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | + $subject = $this->l->t('{actor} changed your password'); |
|
96 | + } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | + $subject = $this->l->t('You changed your password'); |
|
98 | + } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | + |
|
101 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | + $subject = $this->l->t('{actor} changed your email address'); |
|
103 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | + $subject = $this->l->t('You changed your email address'); |
|
105 | + } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | + |
|
108 | + } else { |
|
109 | + throw new \InvalidArgumentException(); |
|
110 | + } |
|
111 | + |
|
112 | + $parsedParameters = $this->getParameters($event); |
|
113 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | + |
|
115 | + return $event; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param IEvent $event |
|
120 | + * @return array |
|
121 | + * @throws \InvalidArgumentException |
|
122 | + */ |
|
123 | + protected function getParameters(IEvent $event) { |
|
124 | + $subject = $event->getSubject(); |
|
125 | + $parameters = $event->getSubjectParameters(); |
|
126 | + |
|
127 | + switch ($subject) { |
|
128 | + case self::PASSWORD_CHANGED_SELF: |
|
129 | + case self::PASSWORD_RESET: |
|
130 | + case self::EMAIL_CHANGED_SELF: |
|
131 | + case self::EMAIL_CHANGED: |
|
132 | + return []; |
|
133 | + case self::PASSWORD_CHANGED_BY: |
|
134 | + case self::EMAIL_CHANGED_BY: |
|
135 | + return [ |
|
136 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | + ]; |
|
138 | + } |
|
139 | + |
|
140 | + throw new \InvalidArgumentException(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IEvent $event |
|
145 | + * @param string $subject |
|
146 | + * @param array $parameters |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + */ |
|
149 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | + $placeholders = $replacements = []; |
|
151 | + foreach ($parameters as $placeholder => $parameter) { |
|
152 | + $placeholders[] = '{' . $placeholder . '}'; |
|
153 | + $replacements[] = $parameter['name']; |
|
154 | + } |
|
155 | + |
|
156 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | + ->setRichSubject($subject, $parameters); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $uid |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function generateUserParameter($uid) { |
|
165 | + if (!isset($this->displayNames[$uid])) { |
|
166 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | + } |
|
168 | + |
|
169 | + return [ |
|
170 | + 'type' => 'user', |
|
171 | + 'id' => $uid, |
|
172 | + 'name' => $this->displayNames[$uid], |
|
173 | + ]; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $uid |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + protected function getDisplayName($uid) { |
|
181 | + $user = $this->userManager->get($uid); |
|
182 | + if ($user instanceof IUser) { |
|
183 | + return $user->getDisplayName(); |
|
184 | + } |
|
185 | + |
|
186 | + return $uid; |
|
187 | + } |
|
188 | 188 | } |
@@ -39,262 +39,262 @@ |
||
39 | 39 | * @since 6.0.0 |
40 | 40 | */ |
41 | 41 | interface IManager { |
42 | - /** |
|
43 | - * Generates a new IEvent object |
|
44 | - * |
|
45 | - * Make sure to call at least the following methods before sending it to the |
|
46 | - * app with via the publish() method: |
|
47 | - * - setApp() |
|
48 | - * - setType() |
|
49 | - * - setAffectedUser() |
|
50 | - * - setSubject() |
|
51 | - * |
|
52 | - * @return IEvent |
|
53 | - * @since 8.2.0 |
|
54 | - */ |
|
55 | - public function generateEvent(); |
|
56 | - |
|
57 | - /** |
|
58 | - * Publish an event to the activity consumers |
|
59 | - * |
|
60 | - * Make sure to call at least the following methods before sending an Event: |
|
61 | - * - setApp() |
|
62 | - * - setType() |
|
63 | - * - setAffectedUser() |
|
64 | - * - setSubject() |
|
65 | - * |
|
66 | - * @param IEvent $event |
|
67 | - * @throws \BadMethodCallException if required values have not been set |
|
68 | - * @since 8.2.0 |
|
69 | - */ |
|
70 | - public function publish(IEvent $event); |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $app The app where this event is associated with |
|
74 | - * @param string $subject A short description of the event |
|
75 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | - * @param string $message A longer description of the event |
|
77 | - * @param array $messageParams Array with parameters that are filled in the message |
|
78 | - * @param string $file The file including path where this event is associated with |
|
79 | - * @param string $link A link where this event is associated with |
|
80 | - * @param string $affectedUser Recipient of the activity |
|
81 | - * @param string $type Type of the notification |
|
82 | - * @param int $priority Priority of the notification |
|
83 | - * @since 6.0.0 |
|
84 | - * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
85 | - */ |
|
86 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
87 | - |
|
88 | - /** |
|
89 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
90 | - * activity consumers are actually requested |
|
91 | - * |
|
92 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
93 | - * |
|
94 | - * @param \Closure $callable |
|
95 | - * @return void |
|
96 | - * @since 6.0.0 |
|
97 | - */ |
|
98 | - public function registerConsumer(\Closure $callable); |
|
99 | - |
|
100 | - /** |
|
101 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
102 | - * activity consumers are actually requested |
|
103 | - * |
|
104 | - * $callable has to return an instance of \OCP\Activity\IExtension |
|
105 | - * |
|
106 | - * @param \Closure $callable |
|
107 | - * @return void |
|
108 | - * @since 8.0.0 |
|
109 | - */ |
|
110 | - public function registerExtension(\Closure $callable); |
|
111 | - |
|
112 | - /** |
|
113 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
114 | - * @return void |
|
115 | - * @since 11.0.0 |
|
116 | - */ |
|
117 | - public function registerFilter($filter); |
|
118 | - |
|
119 | - /** |
|
120 | - * @return IFilter[] |
|
121 | - * @since 11.0.0 |
|
122 | - */ |
|
123 | - public function getFilters(); |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $id |
|
127 | - * @return IFilter |
|
128 | - * @throws \InvalidArgumentException when the filter was not found |
|
129 | - * @since 11.0.0 |
|
130 | - */ |
|
131 | - public function getFilterById($id); |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
135 | - * @return void |
|
136 | - * @since 11.0.0 |
|
137 | - */ |
|
138 | - public function registerSetting($setting); |
|
139 | - |
|
140 | - /** |
|
141 | - * @return ISetting[] |
|
142 | - * @since 11.0.0 |
|
143 | - */ |
|
144 | - public function getSettings(); |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
148 | - * @return void |
|
149 | - * @since 11.0.0 |
|
150 | - */ |
|
151 | - public function registerProvider($provider); |
|
152 | - |
|
153 | - /** |
|
154 | - * @return IProvider[] |
|
155 | - * @since 11.0.0 |
|
156 | - */ |
|
157 | - public function getProviders(); |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $id |
|
161 | - * @return ISetting |
|
162 | - * @throws \InvalidArgumentException when the setting was not found |
|
163 | - * @since 11.0.0 |
|
164 | - */ |
|
165 | - public function getSettingById($id); |
|
166 | - |
|
167 | - /** |
|
168 | - * Will return additional notification types as specified by other apps |
|
169 | - * |
|
170 | - * @param string $languageCode |
|
171 | - * @return array Array "stringID of the type" => "translated string description for the setting" |
|
172 | - * or Array "stringID of the type" => [ |
|
173 | - * 'desc' => "translated string description for the setting" |
|
174 | - * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
175 | - * ] |
|
176 | - * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
177 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
178 | - */ |
|
179 | - public function getNotificationTypes($languageCode); |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $method |
|
183 | - * @return array |
|
184 | - * @since 8.0.0 |
|
185 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
186 | - */ |
|
187 | - public function getDefaultTypes($method); |
|
188 | - |
|
189 | - /** |
|
190 | - * @param string $type |
|
191 | - * @return string |
|
192 | - * @since 8.0.0 |
|
193 | - */ |
|
194 | - public function getTypeIcon($type); |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $type |
|
198 | - * @param int $id |
|
199 | - * @since 8.2.0 |
|
200 | - */ |
|
201 | - public function setFormattingObject($type, $id); |
|
202 | - |
|
203 | - /** |
|
204 | - * @return bool |
|
205 | - * @since 8.2.0 |
|
206 | - */ |
|
207 | - public function isFormattingFilteredObject(); |
|
208 | - |
|
209 | - /** |
|
210 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
211 | - * @since 12.0.1 |
|
212 | - */ |
|
213 | - public function setRequirePNG($status); |
|
214 | - |
|
215 | - /** |
|
216 | - * @return bool |
|
217 | - * @since 12.0.1 |
|
218 | - */ |
|
219 | - public function getRequirePNG(); |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $app |
|
223 | - * @param string $text |
|
224 | - * @param array $params |
|
225 | - * @param boolean $stripPath |
|
226 | - * @param boolean $highlightParams |
|
227 | - * @param string $languageCode |
|
228 | - * @return string|false |
|
229 | - * @since 8.0.0 |
|
230 | - */ |
|
231 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $app |
|
235 | - * @param string $text |
|
236 | - * @return array|false |
|
237 | - * @since 8.0.0 |
|
238 | - */ |
|
239 | - public function getSpecialParameterList($app, $text); |
|
240 | - |
|
241 | - /** |
|
242 | - * @param array $activity |
|
243 | - * @return integer|false |
|
244 | - * @since 8.0.0 |
|
245 | - */ |
|
246 | - public function getGroupParameter($activity); |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Set the user we need to use |
|
251 | - * |
|
252 | - * @param string|null $currentUserId |
|
253 | - * @throws \UnexpectedValueException If the user is invalid |
|
254 | - * @since 9.0.1 |
|
255 | - */ |
|
256 | - public function setCurrentUserId($currentUserId); |
|
257 | - |
|
258 | - /** |
|
259 | - * Get the user we need to use |
|
260 | - * |
|
261 | - * Either the user is logged in, or we try to get it from the token |
|
262 | - * |
|
263 | - * @return string |
|
264 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
265 | - * @since 8.1.0 |
|
266 | - */ |
|
267 | - public function getCurrentUserId(); |
|
268 | - |
|
269 | - /** |
|
270 | - * @return array |
|
271 | - * @since 8.0.0 |
|
272 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
273 | - */ |
|
274 | - public function getNavigation(); |
|
275 | - |
|
276 | - /** |
|
277 | - * @param string $filterValue |
|
278 | - * @return boolean |
|
279 | - * @since 8.0.0 |
|
280 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
281 | - */ |
|
282 | - public function isFilterValid($filterValue); |
|
283 | - |
|
284 | - /** |
|
285 | - * @param array $types |
|
286 | - * @param string $filter |
|
287 | - * @return array |
|
288 | - * @since 8.0.0 |
|
289 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
290 | - */ |
|
291 | - public function filterNotificationTypes($types, $filter); |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $filter |
|
295 | - * @return array |
|
296 | - * @since 8.0.0 |
|
297 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
298 | - */ |
|
299 | - public function getQueryForFilter($filter); |
|
42 | + /** |
|
43 | + * Generates a new IEvent object |
|
44 | + * |
|
45 | + * Make sure to call at least the following methods before sending it to the |
|
46 | + * app with via the publish() method: |
|
47 | + * - setApp() |
|
48 | + * - setType() |
|
49 | + * - setAffectedUser() |
|
50 | + * - setSubject() |
|
51 | + * |
|
52 | + * @return IEvent |
|
53 | + * @since 8.2.0 |
|
54 | + */ |
|
55 | + public function generateEvent(); |
|
56 | + |
|
57 | + /** |
|
58 | + * Publish an event to the activity consumers |
|
59 | + * |
|
60 | + * Make sure to call at least the following methods before sending an Event: |
|
61 | + * - setApp() |
|
62 | + * - setType() |
|
63 | + * - setAffectedUser() |
|
64 | + * - setSubject() |
|
65 | + * |
|
66 | + * @param IEvent $event |
|
67 | + * @throws \BadMethodCallException if required values have not been set |
|
68 | + * @since 8.2.0 |
|
69 | + */ |
|
70 | + public function publish(IEvent $event); |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $app The app where this event is associated with |
|
74 | + * @param string $subject A short description of the event |
|
75 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | + * @param string $message A longer description of the event |
|
77 | + * @param array $messageParams Array with parameters that are filled in the message |
|
78 | + * @param string $file The file including path where this event is associated with |
|
79 | + * @param string $link A link where this event is associated with |
|
80 | + * @param string $affectedUser Recipient of the activity |
|
81 | + * @param string $type Type of the notification |
|
82 | + * @param int $priority Priority of the notification |
|
83 | + * @since 6.0.0 |
|
84 | + * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
85 | + */ |
|
86 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
87 | + |
|
88 | + /** |
|
89 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
90 | + * activity consumers are actually requested |
|
91 | + * |
|
92 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
93 | + * |
|
94 | + * @param \Closure $callable |
|
95 | + * @return void |
|
96 | + * @since 6.0.0 |
|
97 | + */ |
|
98 | + public function registerConsumer(\Closure $callable); |
|
99 | + |
|
100 | + /** |
|
101 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
102 | + * activity consumers are actually requested |
|
103 | + * |
|
104 | + * $callable has to return an instance of \OCP\Activity\IExtension |
|
105 | + * |
|
106 | + * @param \Closure $callable |
|
107 | + * @return void |
|
108 | + * @since 8.0.0 |
|
109 | + */ |
|
110 | + public function registerExtension(\Closure $callable); |
|
111 | + |
|
112 | + /** |
|
113 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
114 | + * @return void |
|
115 | + * @since 11.0.0 |
|
116 | + */ |
|
117 | + public function registerFilter($filter); |
|
118 | + |
|
119 | + /** |
|
120 | + * @return IFilter[] |
|
121 | + * @since 11.0.0 |
|
122 | + */ |
|
123 | + public function getFilters(); |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $id |
|
127 | + * @return IFilter |
|
128 | + * @throws \InvalidArgumentException when the filter was not found |
|
129 | + * @since 11.0.0 |
|
130 | + */ |
|
131 | + public function getFilterById($id); |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
135 | + * @return void |
|
136 | + * @since 11.0.0 |
|
137 | + */ |
|
138 | + public function registerSetting($setting); |
|
139 | + |
|
140 | + /** |
|
141 | + * @return ISetting[] |
|
142 | + * @since 11.0.0 |
|
143 | + */ |
|
144 | + public function getSettings(); |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
148 | + * @return void |
|
149 | + * @since 11.0.0 |
|
150 | + */ |
|
151 | + public function registerProvider($provider); |
|
152 | + |
|
153 | + /** |
|
154 | + * @return IProvider[] |
|
155 | + * @since 11.0.0 |
|
156 | + */ |
|
157 | + public function getProviders(); |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $id |
|
161 | + * @return ISetting |
|
162 | + * @throws \InvalidArgumentException when the setting was not found |
|
163 | + * @since 11.0.0 |
|
164 | + */ |
|
165 | + public function getSettingById($id); |
|
166 | + |
|
167 | + /** |
|
168 | + * Will return additional notification types as specified by other apps |
|
169 | + * |
|
170 | + * @param string $languageCode |
|
171 | + * @return array Array "stringID of the type" => "translated string description for the setting" |
|
172 | + * or Array "stringID of the type" => [ |
|
173 | + * 'desc' => "translated string description for the setting" |
|
174 | + * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
175 | + * ] |
|
176 | + * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
177 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
178 | + */ |
|
179 | + public function getNotificationTypes($languageCode); |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $method |
|
183 | + * @return array |
|
184 | + * @since 8.0.0 |
|
185 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
186 | + */ |
|
187 | + public function getDefaultTypes($method); |
|
188 | + |
|
189 | + /** |
|
190 | + * @param string $type |
|
191 | + * @return string |
|
192 | + * @since 8.0.0 |
|
193 | + */ |
|
194 | + public function getTypeIcon($type); |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $type |
|
198 | + * @param int $id |
|
199 | + * @since 8.2.0 |
|
200 | + */ |
|
201 | + public function setFormattingObject($type, $id); |
|
202 | + |
|
203 | + /** |
|
204 | + * @return bool |
|
205 | + * @since 8.2.0 |
|
206 | + */ |
|
207 | + public function isFormattingFilteredObject(); |
|
208 | + |
|
209 | + /** |
|
210 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
211 | + * @since 12.0.1 |
|
212 | + */ |
|
213 | + public function setRequirePNG($status); |
|
214 | + |
|
215 | + /** |
|
216 | + * @return bool |
|
217 | + * @since 12.0.1 |
|
218 | + */ |
|
219 | + public function getRequirePNG(); |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $app |
|
223 | + * @param string $text |
|
224 | + * @param array $params |
|
225 | + * @param boolean $stripPath |
|
226 | + * @param boolean $highlightParams |
|
227 | + * @param string $languageCode |
|
228 | + * @return string|false |
|
229 | + * @since 8.0.0 |
|
230 | + */ |
|
231 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $app |
|
235 | + * @param string $text |
|
236 | + * @return array|false |
|
237 | + * @since 8.0.0 |
|
238 | + */ |
|
239 | + public function getSpecialParameterList($app, $text); |
|
240 | + |
|
241 | + /** |
|
242 | + * @param array $activity |
|
243 | + * @return integer|false |
|
244 | + * @since 8.0.0 |
|
245 | + */ |
|
246 | + public function getGroupParameter($activity); |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Set the user we need to use |
|
251 | + * |
|
252 | + * @param string|null $currentUserId |
|
253 | + * @throws \UnexpectedValueException If the user is invalid |
|
254 | + * @since 9.0.1 |
|
255 | + */ |
|
256 | + public function setCurrentUserId($currentUserId); |
|
257 | + |
|
258 | + /** |
|
259 | + * Get the user we need to use |
|
260 | + * |
|
261 | + * Either the user is logged in, or we try to get it from the token |
|
262 | + * |
|
263 | + * @return string |
|
264 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
265 | + * @since 8.1.0 |
|
266 | + */ |
|
267 | + public function getCurrentUserId(); |
|
268 | + |
|
269 | + /** |
|
270 | + * @return array |
|
271 | + * @since 8.0.0 |
|
272 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
273 | + */ |
|
274 | + public function getNavigation(); |
|
275 | + |
|
276 | + /** |
|
277 | + * @param string $filterValue |
|
278 | + * @return boolean |
|
279 | + * @since 8.0.0 |
|
280 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
281 | + */ |
|
282 | + public function isFilterValid($filterValue); |
|
283 | + |
|
284 | + /** |
|
285 | + * @param array $types |
|
286 | + * @param string $filter |
|
287 | + * @return array |
|
288 | + * @since 8.0.0 |
|
289 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
290 | + */ |
|
291 | + public function filterNotificationTypes($types, $filter); |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $filter |
|
295 | + * @return array |
|
296 | + * @since 8.0.0 |
|
297 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
298 | + */ |
|
299 | + public function getQueryForFilter($filter); |
|
300 | 300 | } |
@@ -39,688 +39,688 @@ |
||
39 | 39 | use OCP\RichObjectStrings\IValidator; |
40 | 40 | |
41 | 41 | class Manager implements IManager { |
42 | - /** @var IRequest */ |
|
43 | - protected $request; |
|
44 | - |
|
45 | - /** @var IUserSession */ |
|
46 | - protected $session; |
|
47 | - |
|
48 | - /** @var IConfig */ |
|
49 | - protected $config; |
|
50 | - |
|
51 | - /** @var IValidator */ |
|
52 | - protected $validator; |
|
53 | - |
|
54 | - /** @var string */ |
|
55 | - protected $formattingObjectType; |
|
56 | - |
|
57 | - /** @var int */ |
|
58 | - protected $formattingObjectId; |
|
59 | - |
|
60 | - /** @var bool */ |
|
61 | - protected $requirePNG; |
|
62 | - |
|
63 | - /** @var string */ |
|
64 | - protected $currentUserId; |
|
65 | - |
|
66 | - /** |
|
67 | - * constructor of the controller |
|
68 | - * |
|
69 | - * @param IRequest $request |
|
70 | - * @param IUserSession $session |
|
71 | - * @param IConfig $config |
|
72 | - * @param IValidator $validator |
|
73 | - */ |
|
74 | - public function __construct(IRequest $request, |
|
75 | - IUserSession $session, |
|
76 | - IConfig $config, |
|
77 | - IValidator $validator) { |
|
78 | - $this->request = $request; |
|
79 | - $this->session = $session; |
|
80 | - $this->config = $config; |
|
81 | - $this->validator = $validator; |
|
82 | - } |
|
83 | - |
|
84 | - /** @var \Closure[] */ |
|
85 | - private $consumersClosures = array(); |
|
86 | - |
|
87 | - /** @var IConsumer[] */ |
|
88 | - private $consumers = array(); |
|
89 | - |
|
90 | - /** @var \Closure[] */ |
|
91 | - private $extensionsClosures = array(); |
|
92 | - |
|
93 | - /** @var IExtension[] */ |
|
94 | - private $extensions = array(); |
|
95 | - |
|
96 | - /** @var array list of filters "name" => "is valid" */ |
|
97 | - protected $validFilters = array( |
|
98 | - 'all' => true, |
|
99 | - 'by' => true, |
|
100 | - 'self' => true, |
|
101 | - ); |
|
102 | - |
|
103 | - /** @var array list of type icons "type" => "css class" */ |
|
104 | - protected $typeIcons = array(); |
|
105 | - |
|
106 | - /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
107 | - protected $specialParameters = array(); |
|
108 | - |
|
109 | - /** |
|
110 | - * @return \OCP\Activity\IConsumer[] |
|
111 | - */ |
|
112 | - protected function getConsumers() { |
|
113 | - if (!empty($this->consumers)) { |
|
114 | - return $this->consumers; |
|
115 | - } |
|
116 | - |
|
117 | - $this->consumers = []; |
|
118 | - foreach($this->consumersClosures as $consumer) { |
|
119 | - $c = $consumer(); |
|
120 | - if ($c instanceof IConsumer) { |
|
121 | - $this->consumers[] = $c; |
|
122 | - } else { |
|
123 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - return $this->consumers; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return \OCP\Activity\IExtension[] |
|
132 | - */ |
|
133 | - protected function getExtensions() { |
|
134 | - if (!empty($this->extensions)) { |
|
135 | - return $this->extensions; |
|
136 | - } |
|
137 | - |
|
138 | - $this->extensions = []; |
|
139 | - foreach($this->extensionsClosures as $extension) { |
|
140 | - $e = $extension(); |
|
141 | - if ($e instanceof IExtension) { |
|
142 | - $this->extensions[] = $e; |
|
143 | - } else { |
|
144 | - throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return $this->extensions; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Generates a new IEvent object |
|
153 | - * |
|
154 | - * Make sure to call at least the following methods before sending it to the |
|
155 | - * app with via the publish() method: |
|
156 | - * - setApp() |
|
157 | - * - setType() |
|
158 | - * - setAffectedUser() |
|
159 | - * - setSubject() |
|
160 | - * |
|
161 | - * @return IEvent |
|
162 | - */ |
|
163 | - public function generateEvent() { |
|
164 | - return new Event($this->validator); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Publish an event to the activity consumers |
|
169 | - * |
|
170 | - * Make sure to call at least the following methods before sending an Event: |
|
171 | - * - setApp() |
|
172 | - * - setType() |
|
173 | - * - setAffectedUser() |
|
174 | - * - setSubject() |
|
175 | - * |
|
176 | - * @param IEvent $event |
|
177 | - * @throws \BadMethodCallException if required values have not been set |
|
178 | - */ |
|
179 | - public function publish(IEvent $event) { |
|
180 | - if ($event->getAuthor() === '') { |
|
181 | - if ($this->session->getUser() instanceof IUser) { |
|
182 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - if (!$event->getTimestamp()) { |
|
187 | - $event->setTimestamp(time()); |
|
188 | - } |
|
189 | - |
|
190 | - if (!$event->isValid()) { |
|
191 | - throw new \BadMethodCallException('The given event is invalid'); |
|
192 | - } |
|
193 | - |
|
194 | - foreach ($this->getConsumers() as $c) { |
|
195 | - $c->receive($event); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $app The app where this event is associated with |
|
201 | - * @param string $subject A short description of the event |
|
202 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
203 | - * @param string $message A longer description of the event |
|
204 | - * @param array $messageParams Array with parameters that are filled in the message |
|
205 | - * @param string $file The file including path where this event is associated with |
|
206 | - * @param string $link A link where this event is associated with |
|
207 | - * @param string $affectedUser Recipient of the activity |
|
208 | - * @param string $type Type of the notification |
|
209 | - * @param int $priority Priority of the notification |
|
210 | - */ |
|
211 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
212 | - $event = $this->generateEvent(); |
|
213 | - $event->setApp($app) |
|
214 | - ->setType($type) |
|
215 | - ->setAffectedUser($affectedUser) |
|
216 | - ->setSubject($subject, $subjectParams) |
|
217 | - ->setMessage($message, $messageParams) |
|
218 | - ->setObject('', 0, $file) |
|
219 | - ->setLink($link); |
|
220 | - |
|
221 | - $this->publish($event); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
226 | - * activity consumers are actually requested |
|
227 | - * |
|
228 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
229 | - * |
|
230 | - * @param \Closure $callable |
|
231 | - */ |
|
232 | - public function registerConsumer(\Closure $callable) { |
|
233 | - array_push($this->consumersClosures, $callable); |
|
234 | - $this->consumers = []; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
239 | - * activity consumers are actually requested |
|
240 | - * |
|
241 | - * $callable has to return an instance of OCA\Activity\IExtension |
|
242 | - * |
|
243 | - * @param \Closure $callable |
|
244 | - */ |
|
245 | - public function registerExtension(\Closure $callable) { |
|
246 | - array_push($this->extensionsClosures, $callable); |
|
247 | - $this->extensions = []; |
|
248 | - } |
|
249 | - |
|
250 | - /** @var string[] */ |
|
251 | - protected $filterClasses = []; |
|
252 | - |
|
253 | - /** @var IFilter[] */ |
|
254 | - protected $filters = []; |
|
255 | - |
|
256 | - /** @var bool */ |
|
257 | - protected $loadedLegacyFilters = false; |
|
258 | - |
|
259 | - /** |
|
260 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function registerFilter($filter) { |
|
264 | - $this->filterClasses[$filter] = false; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return IFilter[] |
|
269 | - * @throws \InvalidArgumentException |
|
270 | - */ |
|
271 | - public function getFilters() { |
|
272 | - if (!$this->loadedLegacyFilters) { |
|
273 | - $legacyFilters = $this->getNavigation(); |
|
274 | - |
|
275 | - foreach ($legacyFilters['top'] as $filter => $data) { |
|
276 | - $this->filters[$filter] = new LegacyFilter( |
|
277 | - $this, $filter, $data['name'], true |
|
278 | - ); |
|
279 | - } |
|
280 | - |
|
281 | - foreach ($legacyFilters['apps'] as $filter => $data) { |
|
282 | - $this->filters[$filter] = new LegacyFilter( |
|
283 | - $this, $filter, $data['name'], false |
|
284 | - ); |
|
285 | - } |
|
286 | - $this->loadedLegacyFilters = true; |
|
287 | - } |
|
288 | - |
|
289 | - foreach ($this->filterClasses as $class => $false) { |
|
290 | - /** @var IFilter $filter */ |
|
291 | - $filter = \OC::$server->query($class); |
|
292 | - |
|
293 | - if (!$filter instanceof IFilter) { |
|
294 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
295 | - } |
|
296 | - |
|
297 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
298 | - |
|
299 | - unset($this->filterClasses[$class]); |
|
300 | - } |
|
301 | - return $this->filters; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param string $id |
|
306 | - * @return IFilter |
|
307 | - * @throws \InvalidArgumentException when the filter was not found |
|
308 | - * @since 11.0.0 |
|
309 | - */ |
|
310 | - public function getFilterById($id) { |
|
311 | - $filters = $this->getFilters(); |
|
312 | - |
|
313 | - if (isset($filters[$id])) { |
|
314 | - return $filters[$id]; |
|
315 | - } |
|
316 | - |
|
317 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
318 | - } |
|
319 | - |
|
320 | - /** @var string[] */ |
|
321 | - protected $providerClasses = []; |
|
322 | - |
|
323 | - /** @var IProvider[] */ |
|
324 | - protected $providers = []; |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
328 | - * @return void |
|
329 | - */ |
|
330 | - public function registerProvider($provider) { |
|
331 | - $this->providerClasses[$provider] = false; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * @return IProvider[] |
|
336 | - * @throws \InvalidArgumentException |
|
337 | - */ |
|
338 | - public function getProviders() { |
|
339 | - foreach ($this->providerClasses as $class => $false) { |
|
340 | - /** @var IProvider $provider */ |
|
341 | - $provider = \OC::$server->query($class); |
|
342 | - |
|
343 | - if (!$provider instanceof IProvider) { |
|
344 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
345 | - } |
|
346 | - |
|
347 | - $this->providers[] = $provider; |
|
348 | - |
|
349 | - unset($this->providerClasses[$class]); |
|
350 | - } |
|
351 | - return $this->providers; |
|
352 | - } |
|
353 | - |
|
354 | - /** @var string[] */ |
|
355 | - protected $settingsClasses = []; |
|
356 | - |
|
357 | - /** @var ISetting[] */ |
|
358 | - protected $settings = []; |
|
359 | - |
|
360 | - /** @var bool */ |
|
361 | - protected $loadedLegacyTypes = false; |
|
362 | - |
|
363 | - /** |
|
364 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function registerSetting($setting) { |
|
368 | - $this->settingsClasses[$setting] = false; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * @return ISetting[] |
|
373 | - * @throws \InvalidArgumentException |
|
374 | - */ |
|
375 | - public function getSettings() { |
|
376 | - if (!$this->loadedLegacyTypes) { |
|
377 | - $l = \OC::$server->getL10N('core'); |
|
378 | - $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
379 | - $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
380 | - $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
381 | - foreach ($legacyTypes as $type => $data) { |
|
382 | - if (is_string($data)) { |
|
383 | - $desc = $data; |
|
384 | - $canChangeStream = true; |
|
385 | - $canChangeMail = true; |
|
386 | - } else { |
|
387 | - $desc = $data['desc']; |
|
388 | - $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
389 | - $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
390 | - } |
|
391 | - |
|
392 | - $this->settings[$type] = new LegacySetting( |
|
393 | - $type, $desc, |
|
394 | - $canChangeStream, in_array($type, $streamTypes), |
|
395 | - $canChangeMail, in_array($type, $mailTypes) |
|
396 | - ); |
|
397 | - } |
|
398 | - $this->loadedLegacyTypes = true; |
|
399 | - } |
|
400 | - |
|
401 | - foreach ($this->settingsClasses as $class => $false) { |
|
402 | - /** @var ISetting $setting */ |
|
403 | - $setting = \OC::$server->query($class); |
|
404 | - |
|
405 | - if (!$setting instanceof ISetting) { |
|
406 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
407 | - } |
|
408 | - |
|
409 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
410 | - |
|
411 | - unset($this->settingsClasses[$class]); |
|
412 | - } |
|
413 | - return $this->settings; |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $id |
|
418 | - * @return ISetting |
|
419 | - * @throws \InvalidArgumentException when the setting was not found |
|
420 | - * @since 11.0.0 |
|
421 | - */ |
|
422 | - public function getSettingById($id) { |
|
423 | - $settings = $this->getSettings(); |
|
424 | - |
|
425 | - if (isset($settings[$id])) { |
|
426 | - return $settings[$id]; |
|
427 | - } |
|
428 | - |
|
429 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * @param string $type |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - public function getTypeIcon($type) { |
|
437 | - if (isset($this->typeIcons[$type])) { |
|
438 | - return $this->typeIcons[$type]; |
|
439 | - } |
|
440 | - |
|
441 | - foreach ($this->getExtensions() as $c) { |
|
442 | - $icon = $c->getTypeIcon($type); |
|
443 | - if (is_string($icon)) { |
|
444 | - $this->typeIcons[$type] = $icon; |
|
445 | - return $icon; |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - $this->typeIcons[$type] = ''; |
|
450 | - return ''; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @param string $type |
|
455 | - * @param string $id |
|
456 | - */ |
|
457 | - public function setFormattingObject($type, $id) { |
|
458 | - $this->formattingObjectType = $type; |
|
459 | - $this->formattingObjectId = (string) $id; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * @return bool |
|
464 | - */ |
|
465 | - public function isFormattingFilteredObject() { |
|
466 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
467 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
468 | - && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
473 | - */ |
|
474 | - public function setRequirePNG($status) { |
|
475 | - $this->requirePNG = $status; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * @return bool |
|
480 | - */ |
|
481 | - public function getRequirePNG() { |
|
482 | - return $this->requirePNG; |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * @param string $app |
|
487 | - * @param string $text |
|
488 | - * @param array $params |
|
489 | - * @param boolean $stripPath |
|
490 | - * @param boolean $highlightParams |
|
491 | - * @param string $languageCode |
|
492 | - * @return string|false |
|
493 | - */ |
|
494 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
495 | - foreach ($this->getExtensions() as $c) { |
|
496 | - $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
497 | - if (is_string($translation)) { |
|
498 | - return $translation; |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - return false; |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * @param string $app |
|
507 | - * @param string $text |
|
508 | - * @return array|false |
|
509 | - */ |
|
510 | - public function getSpecialParameterList($app, $text) { |
|
511 | - if (isset($this->specialParameters[$app][$text])) { |
|
512 | - return $this->specialParameters[$app][$text]; |
|
513 | - } |
|
514 | - |
|
515 | - if (!isset($this->specialParameters[$app])) { |
|
516 | - $this->specialParameters[$app] = array(); |
|
517 | - } |
|
518 | - |
|
519 | - foreach ($this->getExtensions() as $c) { |
|
520 | - $specialParameter = $c->getSpecialParameterList($app, $text); |
|
521 | - if (is_array($specialParameter)) { |
|
522 | - $this->specialParameters[$app][$text] = $specialParameter; |
|
523 | - return $specialParameter; |
|
524 | - } |
|
525 | - } |
|
526 | - |
|
527 | - $this->specialParameters[$app][$text] = false; |
|
528 | - return false; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * @param array $activity |
|
533 | - * @return integer|false |
|
534 | - */ |
|
535 | - public function getGroupParameter($activity) { |
|
536 | - foreach ($this->getExtensions() as $c) { |
|
537 | - $parameter = $c->getGroupParameter($activity); |
|
538 | - if ($parameter !== false) { |
|
539 | - return $parameter; |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - return false; |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Set the user we need to use |
|
548 | - * |
|
549 | - * @param string|null $currentUserId |
|
550 | - * @throws \UnexpectedValueException If the user is invalid |
|
551 | - */ |
|
552 | - public function setCurrentUserId($currentUserId) { |
|
553 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
554 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
555 | - } |
|
556 | - $this->currentUserId = $currentUserId; |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Get the user we need to use |
|
561 | - * |
|
562 | - * Either the user is logged in, or we try to get it from the token |
|
563 | - * |
|
564 | - * @return string |
|
565 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
566 | - */ |
|
567 | - public function getCurrentUserId() { |
|
568 | - if ($this->currentUserId !== null) { |
|
569 | - return $this->currentUserId; |
|
570 | - } else if (!$this->session->isLoggedIn()) { |
|
571 | - return $this->getUserFromToken(); |
|
572 | - } else { |
|
573 | - return $this->session->getUser()->getUID(); |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Get the user for the token |
|
579 | - * |
|
580 | - * @return string |
|
581 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
582 | - */ |
|
583 | - protected function getUserFromToken() { |
|
584 | - $token = (string) $this->request->getParam('token', ''); |
|
585 | - if (strlen($token) !== 30) { |
|
586 | - throw new \UnexpectedValueException('The token is invalid'); |
|
587 | - } |
|
588 | - |
|
589 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
590 | - |
|
591 | - if (sizeof($users) !== 1) { |
|
592 | - // No unique user found |
|
593 | - throw new \UnexpectedValueException('The token is invalid'); |
|
594 | - } |
|
595 | - |
|
596 | - // Token found login as that user |
|
597 | - return array_shift($users); |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * @return array |
|
602 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
603 | - */ |
|
604 | - public function getNavigation() { |
|
605 | - $entries = array( |
|
606 | - 'apps' => array(), |
|
607 | - 'top' => array(), |
|
608 | - ); |
|
609 | - foreach ($this->getExtensions() as $c) { |
|
610 | - $additionalEntries = $c->getNavigation(); |
|
611 | - if (is_array($additionalEntries)) { |
|
612 | - $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
613 | - $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - return $entries; |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * @param string $filterValue |
|
622 | - * @return boolean |
|
623 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
624 | - */ |
|
625 | - public function isFilterValid($filterValue) { |
|
626 | - if (isset($this->validFilters[$filterValue])) { |
|
627 | - return $this->validFilters[$filterValue]; |
|
628 | - } |
|
629 | - |
|
630 | - foreach ($this->getExtensions() as $c) { |
|
631 | - if ($c->isFilterValid($filterValue) === true) { |
|
632 | - $this->validFilters[$filterValue] = true; |
|
633 | - return true; |
|
634 | - } |
|
635 | - } |
|
636 | - |
|
637 | - $this->validFilters[$filterValue] = false; |
|
638 | - return false; |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * @param array $types |
|
643 | - * @param string $filter |
|
644 | - * @return array |
|
645 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
646 | - */ |
|
647 | - public function filterNotificationTypes($types, $filter) { |
|
648 | - if (!$this->isFilterValid($filter)) { |
|
649 | - return $types; |
|
650 | - } |
|
651 | - |
|
652 | - foreach ($this->getExtensions() as $c) { |
|
653 | - $result = $c->filterNotificationTypes($types, $filter); |
|
654 | - if (is_array($result)) { |
|
655 | - $types = $result; |
|
656 | - } |
|
657 | - } |
|
658 | - return $types; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * @param string $filter |
|
663 | - * @return array |
|
664 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
665 | - */ |
|
666 | - public function getQueryForFilter($filter) { |
|
667 | - if (!$this->isFilterValid($filter)) { |
|
668 | - return [null, null]; |
|
669 | - } |
|
670 | - |
|
671 | - $conditions = array(); |
|
672 | - $parameters = array(); |
|
673 | - |
|
674 | - foreach ($this->getExtensions() as $c) { |
|
675 | - $result = $c->getQueryForFilter($filter); |
|
676 | - if (is_array($result)) { |
|
677 | - list($condition, $parameter) = $result; |
|
678 | - if ($condition && is_array($parameter)) { |
|
679 | - $conditions[] = $condition; |
|
680 | - $parameters = array_merge($parameters, $parameter); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - |
|
685 | - if (empty($conditions)) { |
|
686 | - return array(null, null); |
|
687 | - } |
|
688 | - |
|
689 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
690 | - } |
|
691 | - |
|
692 | - /** |
|
693 | - * Will return additional notification types as specified by other apps |
|
694 | - * |
|
695 | - * @param string $languageCode |
|
696 | - * @return array |
|
697 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
698 | - */ |
|
699 | - public function getNotificationTypes($languageCode) { |
|
700 | - $notificationTypes = $sharingNotificationTypes = []; |
|
701 | - foreach ($this->getExtensions() as $c) { |
|
702 | - $result = $c->getNotificationTypes($languageCode); |
|
703 | - if (is_array($result)) { |
|
704 | - $notificationTypes = array_merge($notificationTypes, $result); |
|
705 | - } |
|
706 | - } |
|
707 | - |
|
708 | - return array_merge($sharingNotificationTypes, $notificationTypes); |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * @param string $method |
|
713 | - * @return array |
|
714 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
715 | - */ |
|
716 | - public function getDefaultTypes($method) { |
|
717 | - $defaultTypes = array(); |
|
718 | - foreach ($this->getExtensions() as $c) { |
|
719 | - $types = $c->getDefaultTypes($method); |
|
720 | - if (is_array($types)) { |
|
721 | - $defaultTypes = array_merge($types, $defaultTypes); |
|
722 | - } |
|
723 | - } |
|
724 | - return $defaultTypes; |
|
725 | - } |
|
42 | + /** @var IRequest */ |
|
43 | + protected $request; |
|
44 | + |
|
45 | + /** @var IUserSession */ |
|
46 | + protected $session; |
|
47 | + |
|
48 | + /** @var IConfig */ |
|
49 | + protected $config; |
|
50 | + |
|
51 | + /** @var IValidator */ |
|
52 | + protected $validator; |
|
53 | + |
|
54 | + /** @var string */ |
|
55 | + protected $formattingObjectType; |
|
56 | + |
|
57 | + /** @var int */ |
|
58 | + protected $formattingObjectId; |
|
59 | + |
|
60 | + /** @var bool */ |
|
61 | + protected $requirePNG; |
|
62 | + |
|
63 | + /** @var string */ |
|
64 | + protected $currentUserId; |
|
65 | + |
|
66 | + /** |
|
67 | + * constructor of the controller |
|
68 | + * |
|
69 | + * @param IRequest $request |
|
70 | + * @param IUserSession $session |
|
71 | + * @param IConfig $config |
|
72 | + * @param IValidator $validator |
|
73 | + */ |
|
74 | + public function __construct(IRequest $request, |
|
75 | + IUserSession $session, |
|
76 | + IConfig $config, |
|
77 | + IValidator $validator) { |
|
78 | + $this->request = $request; |
|
79 | + $this->session = $session; |
|
80 | + $this->config = $config; |
|
81 | + $this->validator = $validator; |
|
82 | + } |
|
83 | + |
|
84 | + /** @var \Closure[] */ |
|
85 | + private $consumersClosures = array(); |
|
86 | + |
|
87 | + /** @var IConsumer[] */ |
|
88 | + private $consumers = array(); |
|
89 | + |
|
90 | + /** @var \Closure[] */ |
|
91 | + private $extensionsClosures = array(); |
|
92 | + |
|
93 | + /** @var IExtension[] */ |
|
94 | + private $extensions = array(); |
|
95 | + |
|
96 | + /** @var array list of filters "name" => "is valid" */ |
|
97 | + protected $validFilters = array( |
|
98 | + 'all' => true, |
|
99 | + 'by' => true, |
|
100 | + 'self' => true, |
|
101 | + ); |
|
102 | + |
|
103 | + /** @var array list of type icons "type" => "css class" */ |
|
104 | + protected $typeIcons = array(); |
|
105 | + |
|
106 | + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
107 | + protected $specialParameters = array(); |
|
108 | + |
|
109 | + /** |
|
110 | + * @return \OCP\Activity\IConsumer[] |
|
111 | + */ |
|
112 | + protected function getConsumers() { |
|
113 | + if (!empty($this->consumers)) { |
|
114 | + return $this->consumers; |
|
115 | + } |
|
116 | + |
|
117 | + $this->consumers = []; |
|
118 | + foreach($this->consumersClosures as $consumer) { |
|
119 | + $c = $consumer(); |
|
120 | + if ($c instanceof IConsumer) { |
|
121 | + $this->consumers[] = $c; |
|
122 | + } else { |
|
123 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + return $this->consumers; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return \OCP\Activity\IExtension[] |
|
132 | + */ |
|
133 | + protected function getExtensions() { |
|
134 | + if (!empty($this->extensions)) { |
|
135 | + return $this->extensions; |
|
136 | + } |
|
137 | + |
|
138 | + $this->extensions = []; |
|
139 | + foreach($this->extensionsClosures as $extension) { |
|
140 | + $e = $extension(); |
|
141 | + if ($e instanceof IExtension) { |
|
142 | + $this->extensions[] = $e; |
|
143 | + } else { |
|
144 | + throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return $this->extensions; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Generates a new IEvent object |
|
153 | + * |
|
154 | + * Make sure to call at least the following methods before sending it to the |
|
155 | + * app with via the publish() method: |
|
156 | + * - setApp() |
|
157 | + * - setType() |
|
158 | + * - setAffectedUser() |
|
159 | + * - setSubject() |
|
160 | + * |
|
161 | + * @return IEvent |
|
162 | + */ |
|
163 | + public function generateEvent() { |
|
164 | + return new Event($this->validator); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Publish an event to the activity consumers |
|
169 | + * |
|
170 | + * Make sure to call at least the following methods before sending an Event: |
|
171 | + * - setApp() |
|
172 | + * - setType() |
|
173 | + * - setAffectedUser() |
|
174 | + * - setSubject() |
|
175 | + * |
|
176 | + * @param IEvent $event |
|
177 | + * @throws \BadMethodCallException if required values have not been set |
|
178 | + */ |
|
179 | + public function publish(IEvent $event) { |
|
180 | + if ($event->getAuthor() === '') { |
|
181 | + if ($this->session->getUser() instanceof IUser) { |
|
182 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + if (!$event->getTimestamp()) { |
|
187 | + $event->setTimestamp(time()); |
|
188 | + } |
|
189 | + |
|
190 | + if (!$event->isValid()) { |
|
191 | + throw new \BadMethodCallException('The given event is invalid'); |
|
192 | + } |
|
193 | + |
|
194 | + foreach ($this->getConsumers() as $c) { |
|
195 | + $c->receive($event); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $app The app where this event is associated with |
|
201 | + * @param string $subject A short description of the event |
|
202 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
203 | + * @param string $message A longer description of the event |
|
204 | + * @param array $messageParams Array with parameters that are filled in the message |
|
205 | + * @param string $file The file including path where this event is associated with |
|
206 | + * @param string $link A link where this event is associated with |
|
207 | + * @param string $affectedUser Recipient of the activity |
|
208 | + * @param string $type Type of the notification |
|
209 | + * @param int $priority Priority of the notification |
|
210 | + */ |
|
211 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
212 | + $event = $this->generateEvent(); |
|
213 | + $event->setApp($app) |
|
214 | + ->setType($type) |
|
215 | + ->setAffectedUser($affectedUser) |
|
216 | + ->setSubject($subject, $subjectParams) |
|
217 | + ->setMessage($message, $messageParams) |
|
218 | + ->setObject('', 0, $file) |
|
219 | + ->setLink($link); |
|
220 | + |
|
221 | + $this->publish($event); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
226 | + * activity consumers are actually requested |
|
227 | + * |
|
228 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
229 | + * |
|
230 | + * @param \Closure $callable |
|
231 | + */ |
|
232 | + public function registerConsumer(\Closure $callable) { |
|
233 | + array_push($this->consumersClosures, $callable); |
|
234 | + $this->consumers = []; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
239 | + * activity consumers are actually requested |
|
240 | + * |
|
241 | + * $callable has to return an instance of OCA\Activity\IExtension |
|
242 | + * |
|
243 | + * @param \Closure $callable |
|
244 | + */ |
|
245 | + public function registerExtension(\Closure $callable) { |
|
246 | + array_push($this->extensionsClosures, $callable); |
|
247 | + $this->extensions = []; |
|
248 | + } |
|
249 | + |
|
250 | + /** @var string[] */ |
|
251 | + protected $filterClasses = []; |
|
252 | + |
|
253 | + /** @var IFilter[] */ |
|
254 | + protected $filters = []; |
|
255 | + |
|
256 | + /** @var bool */ |
|
257 | + protected $loadedLegacyFilters = false; |
|
258 | + |
|
259 | + /** |
|
260 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function registerFilter($filter) { |
|
264 | + $this->filterClasses[$filter] = false; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return IFilter[] |
|
269 | + * @throws \InvalidArgumentException |
|
270 | + */ |
|
271 | + public function getFilters() { |
|
272 | + if (!$this->loadedLegacyFilters) { |
|
273 | + $legacyFilters = $this->getNavigation(); |
|
274 | + |
|
275 | + foreach ($legacyFilters['top'] as $filter => $data) { |
|
276 | + $this->filters[$filter] = new LegacyFilter( |
|
277 | + $this, $filter, $data['name'], true |
|
278 | + ); |
|
279 | + } |
|
280 | + |
|
281 | + foreach ($legacyFilters['apps'] as $filter => $data) { |
|
282 | + $this->filters[$filter] = new LegacyFilter( |
|
283 | + $this, $filter, $data['name'], false |
|
284 | + ); |
|
285 | + } |
|
286 | + $this->loadedLegacyFilters = true; |
|
287 | + } |
|
288 | + |
|
289 | + foreach ($this->filterClasses as $class => $false) { |
|
290 | + /** @var IFilter $filter */ |
|
291 | + $filter = \OC::$server->query($class); |
|
292 | + |
|
293 | + if (!$filter instanceof IFilter) { |
|
294 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
295 | + } |
|
296 | + |
|
297 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
298 | + |
|
299 | + unset($this->filterClasses[$class]); |
|
300 | + } |
|
301 | + return $this->filters; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param string $id |
|
306 | + * @return IFilter |
|
307 | + * @throws \InvalidArgumentException when the filter was not found |
|
308 | + * @since 11.0.0 |
|
309 | + */ |
|
310 | + public function getFilterById($id) { |
|
311 | + $filters = $this->getFilters(); |
|
312 | + |
|
313 | + if (isset($filters[$id])) { |
|
314 | + return $filters[$id]; |
|
315 | + } |
|
316 | + |
|
317 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
318 | + } |
|
319 | + |
|
320 | + /** @var string[] */ |
|
321 | + protected $providerClasses = []; |
|
322 | + |
|
323 | + /** @var IProvider[] */ |
|
324 | + protected $providers = []; |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
328 | + * @return void |
|
329 | + */ |
|
330 | + public function registerProvider($provider) { |
|
331 | + $this->providerClasses[$provider] = false; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * @return IProvider[] |
|
336 | + * @throws \InvalidArgumentException |
|
337 | + */ |
|
338 | + public function getProviders() { |
|
339 | + foreach ($this->providerClasses as $class => $false) { |
|
340 | + /** @var IProvider $provider */ |
|
341 | + $provider = \OC::$server->query($class); |
|
342 | + |
|
343 | + if (!$provider instanceof IProvider) { |
|
344 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
345 | + } |
|
346 | + |
|
347 | + $this->providers[] = $provider; |
|
348 | + |
|
349 | + unset($this->providerClasses[$class]); |
|
350 | + } |
|
351 | + return $this->providers; |
|
352 | + } |
|
353 | + |
|
354 | + /** @var string[] */ |
|
355 | + protected $settingsClasses = []; |
|
356 | + |
|
357 | + /** @var ISetting[] */ |
|
358 | + protected $settings = []; |
|
359 | + |
|
360 | + /** @var bool */ |
|
361 | + protected $loadedLegacyTypes = false; |
|
362 | + |
|
363 | + /** |
|
364 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function registerSetting($setting) { |
|
368 | + $this->settingsClasses[$setting] = false; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * @return ISetting[] |
|
373 | + * @throws \InvalidArgumentException |
|
374 | + */ |
|
375 | + public function getSettings() { |
|
376 | + if (!$this->loadedLegacyTypes) { |
|
377 | + $l = \OC::$server->getL10N('core'); |
|
378 | + $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
379 | + $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
380 | + $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
381 | + foreach ($legacyTypes as $type => $data) { |
|
382 | + if (is_string($data)) { |
|
383 | + $desc = $data; |
|
384 | + $canChangeStream = true; |
|
385 | + $canChangeMail = true; |
|
386 | + } else { |
|
387 | + $desc = $data['desc']; |
|
388 | + $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
389 | + $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
390 | + } |
|
391 | + |
|
392 | + $this->settings[$type] = new LegacySetting( |
|
393 | + $type, $desc, |
|
394 | + $canChangeStream, in_array($type, $streamTypes), |
|
395 | + $canChangeMail, in_array($type, $mailTypes) |
|
396 | + ); |
|
397 | + } |
|
398 | + $this->loadedLegacyTypes = true; |
|
399 | + } |
|
400 | + |
|
401 | + foreach ($this->settingsClasses as $class => $false) { |
|
402 | + /** @var ISetting $setting */ |
|
403 | + $setting = \OC::$server->query($class); |
|
404 | + |
|
405 | + if (!$setting instanceof ISetting) { |
|
406 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
407 | + } |
|
408 | + |
|
409 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
410 | + |
|
411 | + unset($this->settingsClasses[$class]); |
|
412 | + } |
|
413 | + return $this->settings; |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $id |
|
418 | + * @return ISetting |
|
419 | + * @throws \InvalidArgumentException when the setting was not found |
|
420 | + * @since 11.0.0 |
|
421 | + */ |
|
422 | + public function getSettingById($id) { |
|
423 | + $settings = $this->getSettings(); |
|
424 | + |
|
425 | + if (isset($settings[$id])) { |
|
426 | + return $settings[$id]; |
|
427 | + } |
|
428 | + |
|
429 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * @param string $type |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + public function getTypeIcon($type) { |
|
437 | + if (isset($this->typeIcons[$type])) { |
|
438 | + return $this->typeIcons[$type]; |
|
439 | + } |
|
440 | + |
|
441 | + foreach ($this->getExtensions() as $c) { |
|
442 | + $icon = $c->getTypeIcon($type); |
|
443 | + if (is_string($icon)) { |
|
444 | + $this->typeIcons[$type] = $icon; |
|
445 | + return $icon; |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + $this->typeIcons[$type] = ''; |
|
450 | + return ''; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @param string $type |
|
455 | + * @param string $id |
|
456 | + */ |
|
457 | + public function setFormattingObject($type, $id) { |
|
458 | + $this->formattingObjectType = $type; |
|
459 | + $this->formattingObjectId = (string) $id; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * @return bool |
|
464 | + */ |
|
465 | + public function isFormattingFilteredObject() { |
|
466 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
467 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
468 | + && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
473 | + */ |
|
474 | + public function setRequirePNG($status) { |
|
475 | + $this->requirePNG = $status; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * @return bool |
|
480 | + */ |
|
481 | + public function getRequirePNG() { |
|
482 | + return $this->requirePNG; |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * @param string $app |
|
487 | + * @param string $text |
|
488 | + * @param array $params |
|
489 | + * @param boolean $stripPath |
|
490 | + * @param boolean $highlightParams |
|
491 | + * @param string $languageCode |
|
492 | + * @return string|false |
|
493 | + */ |
|
494 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
495 | + foreach ($this->getExtensions() as $c) { |
|
496 | + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
497 | + if (is_string($translation)) { |
|
498 | + return $translation; |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + return false; |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * @param string $app |
|
507 | + * @param string $text |
|
508 | + * @return array|false |
|
509 | + */ |
|
510 | + public function getSpecialParameterList($app, $text) { |
|
511 | + if (isset($this->specialParameters[$app][$text])) { |
|
512 | + return $this->specialParameters[$app][$text]; |
|
513 | + } |
|
514 | + |
|
515 | + if (!isset($this->specialParameters[$app])) { |
|
516 | + $this->specialParameters[$app] = array(); |
|
517 | + } |
|
518 | + |
|
519 | + foreach ($this->getExtensions() as $c) { |
|
520 | + $specialParameter = $c->getSpecialParameterList($app, $text); |
|
521 | + if (is_array($specialParameter)) { |
|
522 | + $this->specialParameters[$app][$text] = $specialParameter; |
|
523 | + return $specialParameter; |
|
524 | + } |
|
525 | + } |
|
526 | + |
|
527 | + $this->specialParameters[$app][$text] = false; |
|
528 | + return false; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * @param array $activity |
|
533 | + * @return integer|false |
|
534 | + */ |
|
535 | + public function getGroupParameter($activity) { |
|
536 | + foreach ($this->getExtensions() as $c) { |
|
537 | + $parameter = $c->getGroupParameter($activity); |
|
538 | + if ($parameter !== false) { |
|
539 | + return $parameter; |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + return false; |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Set the user we need to use |
|
548 | + * |
|
549 | + * @param string|null $currentUserId |
|
550 | + * @throws \UnexpectedValueException If the user is invalid |
|
551 | + */ |
|
552 | + public function setCurrentUserId($currentUserId) { |
|
553 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
554 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
555 | + } |
|
556 | + $this->currentUserId = $currentUserId; |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Get the user we need to use |
|
561 | + * |
|
562 | + * Either the user is logged in, or we try to get it from the token |
|
563 | + * |
|
564 | + * @return string |
|
565 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
566 | + */ |
|
567 | + public function getCurrentUserId() { |
|
568 | + if ($this->currentUserId !== null) { |
|
569 | + return $this->currentUserId; |
|
570 | + } else if (!$this->session->isLoggedIn()) { |
|
571 | + return $this->getUserFromToken(); |
|
572 | + } else { |
|
573 | + return $this->session->getUser()->getUID(); |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Get the user for the token |
|
579 | + * |
|
580 | + * @return string |
|
581 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
582 | + */ |
|
583 | + protected function getUserFromToken() { |
|
584 | + $token = (string) $this->request->getParam('token', ''); |
|
585 | + if (strlen($token) !== 30) { |
|
586 | + throw new \UnexpectedValueException('The token is invalid'); |
|
587 | + } |
|
588 | + |
|
589 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
590 | + |
|
591 | + if (sizeof($users) !== 1) { |
|
592 | + // No unique user found |
|
593 | + throw new \UnexpectedValueException('The token is invalid'); |
|
594 | + } |
|
595 | + |
|
596 | + // Token found login as that user |
|
597 | + return array_shift($users); |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * @return array |
|
602 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
603 | + */ |
|
604 | + public function getNavigation() { |
|
605 | + $entries = array( |
|
606 | + 'apps' => array(), |
|
607 | + 'top' => array(), |
|
608 | + ); |
|
609 | + foreach ($this->getExtensions() as $c) { |
|
610 | + $additionalEntries = $c->getNavigation(); |
|
611 | + if (is_array($additionalEntries)) { |
|
612 | + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
613 | + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + return $entries; |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * @param string $filterValue |
|
622 | + * @return boolean |
|
623 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
624 | + */ |
|
625 | + public function isFilterValid($filterValue) { |
|
626 | + if (isset($this->validFilters[$filterValue])) { |
|
627 | + return $this->validFilters[$filterValue]; |
|
628 | + } |
|
629 | + |
|
630 | + foreach ($this->getExtensions() as $c) { |
|
631 | + if ($c->isFilterValid($filterValue) === true) { |
|
632 | + $this->validFilters[$filterValue] = true; |
|
633 | + return true; |
|
634 | + } |
|
635 | + } |
|
636 | + |
|
637 | + $this->validFilters[$filterValue] = false; |
|
638 | + return false; |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * @param array $types |
|
643 | + * @param string $filter |
|
644 | + * @return array |
|
645 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
646 | + */ |
|
647 | + public function filterNotificationTypes($types, $filter) { |
|
648 | + if (!$this->isFilterValid($filter)) { |
|
649 | + return $types; |
|
650 | + } |
|
651 | + |
|
652 | + foreach ($this->getExtensions() as $c) { |
|
653 | + $result = $c->filterNotificationTypes($types, $filter); |
|
654 | + if (is_array($result)) { |
|
655 | + $types = $result; |
|
656 | + } |
|
657 | + } |
|
658 | + return $types; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * @param string $filter |
|
663 | + * @return array |
|
664 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
665 | + */ |
|
666 | + public function getQueryForFilter($filter) { |
|
667 | + if (!$this->isFilterValid($filter)) { |
|
668 | + return [null, null]; |
|
669 | + } |
|
670 | + |
|
671 | + $conditions = array(); |
|
672 | + $parameters = array(); |
|
673 | + |
|
674 | + foreach ($this->getExtensions() as $c) { |
|
675 | + $result = $c->getQueryForFilter($filter); |
|
676 | + if (is_array($result)) { |
|
677 | + list($condition, $parameter) = $result; |
|
678 | + if ($condition && is_array($parameter)) { |
|
679 | + $conditions[] = $condition; |
|
680 | + $parameters = array_merge($parameters, $parameter); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + |
|
685 | + if (empty($conditions)) { |
|
686 | + return array(null, null); |
|
687 | + } |
|
688 | + |
|
689 | + return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
690 | + } |
|
691 | + |
|
692 | + /** |
|
693 | + * Will return additional notification types as specified by other apps |
|
694 | + * |
|
695 | + * @param string $languageCode |
|
696 | + * @return array |
|
697 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
698 | + */ |
|
699 | + public function getNotificationTypes($languageCode) { |
|
700 | + $notificationTypes = $sharingNotificationTypes = []; |
|
701 | + foreach ($this->getExtensions() as $c) { |
|
702 | + $result = $c->getNotificationTypes($languageCode); |
|
703 | + if (is_array($result)) { |
|
704 | + $notificationTypes = array_merge($notificationTypes, $result); |
|
705 | + } |
|
706 | + } |
|
707 | + |
|
708 | + return array_merge($sharingNotificationTypes, $notificationTypes); |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * @param string $method |
|
713 | + * @return array |
|
714 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
715 | + */ |
|
716 | + public function getDefaultTypes($method) { |
|
717 | + $defaultTypes = array(); |
|
718 | + foreach ($this->getExtensions() as $c) { |
|
719 | + $types = $c->getDefaultTypes($method); |
|
720 | + if (is_array($types)) { |
|
721 | + $defaultTypes = array_merge($types, $defaultTypes); |
|
722 | + } |
|
723 | + } |
|
724 | + return $defaultTypes; |
|
725 | + } |
|
726 | 726 | } |