1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace OCA\Comments;
- use OCA\Comments\Activity\Listener as ActivityListener;
- use OCA\Comments\Notification\Listener as NotificationListener;
- use OCP\Comments\CommentsEvent;
- use OCP\Comments\ICommentsEventHandler;
- class EventHandler implements ICommentsEventHandler {
-
- private $activityListener;
-
- private $notificationListener;
- public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) {
- $this->activityListener = $activityListener;
- $this->notificationListener = $notificationListener;
- }
-
- public function handle(CommentsEvent $event) {
- if ($event->getComment()->getObjectType() !== 'files') {
-
- return;
- }
- $eventType = $event->getEvent();
- if ($eventType === CommentsEvent::EVENT_ADD
- ) {
- $this->notificationHandler($event);
- $this->activityHandler($event);
- return;
- }
- $applicableEvents = [
- CommentsEvent::EVENT_PRE_UPDATE,
- CommentsEvent::EVENT_UPDATE,
- CommentsEvent::EVENT_DELETE,
- ];
- if (in_array($eventType, $applicableEvents)) {
- $this->notificationHandler($event);
- return;
- }
- }
-
- private function activityHandler(CommentsEvent $event) {
- $this->activityListener->commentEvent($event);
- }
-
- private function notificationHandler(CommentsEvent $event) {
- $this->notificationListener->evaluate($event);
- }
- }
|