* {events} * * * @package Opentalent\OtTemplating\ViewHelpers */ class GetAllViewHelper extends OtAbstractViewHelper { use TemplateVariableViewHelperTrait; /** * >> Required to prevent typo3 to escape the html output * @var boolean */ protected $escapeOutput = false; /** * @var EventRepository * */ protected $eventRepository; /** * -- This method is expected by Fluid -- * Declares the viewhelper's parameters */ public function initializeArguments() { $this->registerArgument( 'as', 'string', 'Name of the returned array', true ); $this->registerArgument( 'organizationId', 'integer', 'Id of the current structure', true ); $this->registerArgument( 'fromChildren', 'bool', 'Get events from children instead', false, 0 ); } /** * -- This method is expected by Fluid -- * Renders the content as html * * @return string * @throws ApiRequestException|\Exception */ public function render() { // Get current settings $as = $this->arguments['as']; $organizationId = $this->arguments['organizationId']; $fromChildren = $this->arguments['fromChildren']; $searchParams = []; if($_REQUEST['search-loc']) { $searchParams['where'] = $_REQUEST['search-loc']; } if($_REQUEST['search-name']) { $searchParams['what'] = $_REQUEST['search-name']; } if($_REQUEST['search-datestart']) { $dateStart = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-datestart']); $searchParams['datetimeStart'] = $dateStart->format('d-m-Y'); } if($_REQUEST['search-dateend']) { $dateEnd = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-dateend']); $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y'); } if ($fromChildren) { $searchParams['children'] = '1'; } if ($_REQUEST['page']) { $searchParams['page'] = $_REQUEST['page']; } try { $events = $this->eventRepository->searchBy($organizationId, $searchParams); } catch (ApiRequestException $e) { var_dump($e);die; $this->logger->error(sprintf('API Error: %s', $e->getMessage())); $events = new ApiPagedCollection(0, 0, 1, []); } $variables = [$as => $events]; return $this->renderChildrenWithVariables($variables); } /** * @param EventRepository $eventRepository */ public function injectEventRepository(EventRepository $eventRepository) { $this->eventRepository = $eventRepository; } }