| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace Opentalent\OtTemplating\Controller;
- use Opentalent\OtTemplating\Domain\Repository\EventRepository;
- use Opentalent\OtTemplating\Domain\Repository\OrganizationRepository;
- class EventController extends OtController
- {
- /**
- * @var \Opentalent\OtTemplating\Domain\Repository\EventRepository
- *
- */
- protected $eventRepository;
- /**
- * @var \Opentalent\OtTemplating\Domain\Repository\OrganizationRepository
- *
- */
- protected $organizationRepository;
- /** @noinspection PhpUnused */
- /**
- * action nextEventsAction
- *
- * @return void
- * @throws \Exception
- */
- public function indexAction(array $options = []) {
- $args = $this->request->getArguments();
- $organizationId = (int) $this->settings['organizationId'];
- $searchParams = [];
- if($args['search-loc']) {https://www.qwant.com/?client=brz-moz&q=opentalent
- $searchParams['where'] = $args['search-loc'];
- }
- if($args['search-name']) {
- $searchParams['what'] = $args['search-name'];
- }
- if($args['search-datestart']) {
- $dateStart = \DateTime::createFromFormat('d/m/Y', $args['search-datestart']);
- $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
- }
- if($args['search-dateend']) {
- $dateEnd = \DateTime::createFromFormat('d/m/Y', $args['search-dateend']);
- $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
- }
- $allEvents = $this->eventRepository->searchBy($organizationId, $searchParams);
- if (empty($searchParams) && empty($allEvents)) {
- $this->forward('noEvents');
- }
- $this->view->assign('allEvents', $allEvents);
- $this->view->assign('args', $args);
- $this->setTemplate('Index');
- }
- /** @noinspection PhpUnused */
- /**
- * action nextEventsAction
- *
- * @param int $eventId
- * @return void
- * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
- */
- public function showAction($eventId, array $options = []) {
- $event = $this->eventRepository->findById($eventId);
- if ($event == null | $event->getOrganizationId() != $this->settings['organizationId']) {
- // The requested event does not exist, or is not an event of this organization
- unset($eventId);
- $this->forward('index');
- }
- $this->view->assign('event', $event);
- $this->setTemplate('Show');
- }
- /** @noinspection PhpUnused */
- /**
- * action noEventsAction
- * Triggered if there are no events to show
- *
- * @return void
- * @throws \Exception
- */
- public function noEventsAction(array $options = []) {
- $this->setTemplate('NoEvents');
- }
- /** @noinspection PhpUnused */
- /**
- * action nextEventsAction
- *
- * @param array $options
- * @return void
- * @throws \Exception
- */
- public function previewAction(array $options = [])
- {
- // Get current settings
- $organizationId = (int) $this->settings['organizationId'];
- if (!$organizationId) {
- return;
- }
- // Parse options
- $limit = (int) ($options['eventsLimit'] ?? 5);
- $period = (int) ($options['eventsPeriod'] ?? 8);
- $fromDate = new \DateTime();
- $toDate = null;
- if ($period > 0) {
- $nbDays = 7 * $period;
- $toDate = new \DateTime();
- $interval = new \DateInterval('P' . $nbDays . 'D');
- $toDate->add($interval);
- }
- if ($limit < 1) {
- $limit = 1; // $limit can not be lesser than 1
- }
- if ($limit > 24) {
- $limit = 24; // $limit can not be higher than 24
- }
- // Get next events of the structure
- $nextEvents = $this->eventRepository->findByOrganizationId($organizationId, $fromDate, $toDate, $limit);
- $this->view->assign('events', $nextEvents);
- if ((int) $this->settings['organizationIsNetwork'] == 1) {
- // Network: Get the next events of the parent structures
- $structuresEvents = $this->eventRepository->findChildrenByOrganizationId($organizationId, $fromDate, $toDate, $limit);
- $this->view->assign('structuresEvents', $structuresEvents);
- } else {
- // Simple structure: Get the next events of the parent structures
- $networkEvents = $this->eventRepository->findParentsByOrganizationId($organizationId, $fromDate, $toDate, $limit);
- $this->view->assign('networkEvents', $networkEvents);
- }
- $this->setTemplate('Preview');
- }
- /**
- * @param \Opentalent\OtTemplating\Domain\Repository\EventRepository $eventRepository
- */
- public function injectEventRepository(EventRepository $eventRepository)
- {
- $this->eventRepository = $eventRepository;
- }
- /**
- * @param \Opentalent\OtTemplating\Domain\Repository\OrganizationRepository $organizationRepository
- */
- public function injectOrganizationRepository(OrganizationRepository $organizationRepository)
- {
- $this->organizationRepository = $organizationRepository;
- }
- }
|