EventController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace Opentalent\OtTemplating\Controller;
  3. use Opentalent\OtTemplating\Domain\Repository\EventRepository;
  4. use Opentalent\OtTemplating\Domain\Repository\OrganizationRepository;
  5. class EventController extends OtController
  6. {
  7. /**
  8. * @var \Opentalent\OtTemplating\Domain\Repository\EventRepository
  9. *
  10. */
  11. protected $eventRepository;
  12. /**
  13. * @var \Opentalent\OtTemplating\Domain\Repository\OrganizationRepository
  14. *
  15. */
  16. protected $organizationRepository;
  17. /** @noinspection PhpUnused */
  18. /**
  19. * action nextEventsAction
  20. *
  21. * @return void
  22. * @throws \Exception
  23. */
  24. public function indexAction(array $options = []) {
  25. $args = $this->request->getArguments();
  26. $organizationId = (int) $this->settings['organizationId'];
  27. $searchParams = [];
  28. if($args['search-loc']) {https://www.qwant.com/?client=brz-moz&q=opentalent
  29. $searchParams['where'] = $args['search-loc'];
  30. }
  31. if($args['search-name']) {
  32. $searchParams['what'] = $args['search-name'];
  33. }
  34. if($args['search-datestart']) {
  35. $dateStart = \DateTime::createFromFormat('d/m/Y', $args['search-datestart']);
  36. $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
  37. }
  38. if($args['search-dateend']) {
  39. $dateEnd = \DateTime::createFromFormat('d/m/Y', $args['search-dateend']);
  40. $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
  41. }
  42. $allEvents = $this->eventRepository->searchBy($organizationId, $searchParams);
  43. if (empty($searchParams) && empty($allEvents)) {
  44. $this->forward('noEvents');
  45. }
  46. $this->view->assign('allEvents', $allEvents);
  47. $this->view->assign('args', $args);
  48. $this->setTemplate('Index');
  49. }
  50. /** @noinspection PhpUnused */
  51. /**
  52. * action nextEventsAction
  53. *
  54. * @param int $eventId
  55. * @return void
  56. * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
  57. */
  58. public function showAction($eventId, array $options = []) {
  59. $event = $this->eventRepository->findById($eventId);
  60. if ($event == null | $event->getOrganizationId() != $this->settings['organizationId']) {
  61. // The requested event does not exist, or is not an event of this organization
  62. unset($eventId);
  63. $this->forward('index');
  64. }
  65. $this->view->assign('event', $event);
  66. $this->setTemplate('Show');
  67. }
  68. /** @noinspection PhpUnused */
  69. /**
  70. * action noEventsAction
  71. * Triggered if there are no events to show
  72. *
  73. * @return void
  74. * @throws \Exception
  75. */
  76. public function noEventsAction(array $options = []) {
  77. $this->setTemplate('NoEvents');
  78. }
  79. /** @noinspection PhpUnused */
  80. /**
  81. * action nextEventsAction
  82. *
  83. * @param array $options
  84. * @return void
  85. * @throws \Exception
  86. */
  87. public function previewAction(array $options = [])
  88. {
  89. // Get current settings
  90. $organizationId = (int) $this->settings['organizationId'];
  91. if (!$organizationId) {
  92. return;
  93. }
  94. // Parse options
  95. $limit = (int) ($options['eventsLimit'] ?? 5);
  96. $period = (int) ($options['eventsPeriod'] ?? 8);
  97. $fromDate = new \DateTime();
  98. $toDate = null;
  99. if ($period > 0) {
  100. $nbDays = 7 * $period;
  101. $toDate = new \DateTime();
  102. $interval = new \DateInterval('P' . $nbDays . 'D');
  103. $toDate->add($interval);
  104. }
  105. if ($limit < 1) {
  106. $limit = 1; // $limit can not be lesser than 1
  107. }
  108. if ($limit > 24) {
  109. $limit = 24; // $limit can not be higher than 24
  110. }
  111. // Get next events of the structure
  112. $nextEvents = $this->eventRepository->findByOrganizationId($organizationId, $fromDate, $toDate, $limit);
  113. $this->view->assign('events', $nextEvents);
  114. if ((int) $this->settings['organizationIsNetwork'] == 1) {
  115. // Network: Get the next events of the parent structures
  116. $structuresEvents = $this->eventRepository->findChildrenByOrganizationId($organizationId, $fromDate, $toDate, $limit);
  117. $this->view->assign('structuresEvents', $structuresEvents);
  118. } else {
  119. // Simple structure: Get the next events of the parent structures
  120. $networkEvents = $this->eventRepository->findParentsByOrganizationId($organizationId, $fromDate, $toDate, $limit);
  121. $this->view->assign('networkEvents', $networkEvents);
  122. }
  123. $this->setTemplate('Preview');
  124. }
  125. /**
  126. * @param \Opentalent\OtTemplating\Domain\Repository\EventRepository $eventRepository
  127. */
  128. public function injectEventRepository(EventRepository $eventRepository)
  129. {
  130. $this->eventRepository = $eventRepository;
  131. }
  132. /**
  133. * @param \Opentalent\OtTemplating\Domain\Repository\OrganizationRepository $organizationRepository
  134. */
  135. public function injectOrganizationRepository(OrganizationRepository $organizationRepository)
  136. {
  137. $this->organizationRepository = $organizationRepository;
  138. }
  139. }