EventController.php 4.9 KB

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