1
0

EventHandler.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Comments;
  25. use OCA\Comments\Activity\Listener as ActivityListener;
  26. use OCA\Comments\Notification\Listener as NotificationListener;
  27. use OCP\Comments\CommentsEvent;
  28. use OCP\Comments\ICommentsEventHandler;
  29. /**
  30. * Class EventHandler
  31. *
  32. * @package OCA\Comments
  33. */
  34. class EventHandler implements ICommentsEventHandler {
  35. /** @var ActivityListener */
  36. private $activityListener;
  37. /** @var NotificationListener */
  38. private $notificationListener;
  39. public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) {
  40. $this->activityListener = $activityListener;
  41. $this->notificationListener = $notificationListener;
  42. }
  43. /**
  44. * @param CommentsEvent $event
  45. */
  46. public function handle(CommentsEvent $event) {
  47. if ($event->getComment()->getObjectType() !== 'files') {
  48. // this is a 'files'-specific Handler
  49. return;
  50. }
  51. $eventType = $event->getEvent();
  52. if ($eventType === CommentsEvent::EVENT_ADD
  53. ) {
  54. $this->notificationHandler($event);
  55. $this->activityHandler($event);
  56. return;
  57. }
  58. $applicableEvents = [
  59. CommentsEvent::EVENT_PRE_UPDATE,
  60. CommentsEvent::EVENT_UPDATE,
  61. CommentsEvent::EVENT_DELETE,
  62. ];
  63. if (in_array($eventType, $applicableEvents)) {
  64. $this->notificationHandler($event);
  65. return;
  66. }
  67. }
  68. /**
  69. * @param CommentsEvent $event
  70. */
  71. private function activityHandler(CommentsEvent $event) {
  72. $this->activityListener->commentEvent($event);
  73. }
  74. /**
  75. * @param CommentsEvent $event
  76. */
  77. private function notificationHandler(CommentsEvent $event) {
  78. $this->notificationListener->evaluate($event);
  79. }
  80. }