* {organization} * * * @package Opentalent\OtTemplating\ViewHelpers */ class GetFederationStructuresViewHelper extends OtAbstractViewHelper { use TemplateVariableViewHelperTrait; /** * >> Required to prevent typo3 to escape the html output * @var boolean */ protected $escapeOutput = false; /** * @var FederationStructureRepository * */ protected $federationRepository; /** * -- 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( 'parentId', 'integer', 'Id of the parent organization', true ); $this->registerArgument( 'itemsPerPage', 'string', 'Number of items per page', false, 10 ); } /** * -- This method is expected by Fluid -- * Renders the content as html * * @return string */ public function render() { $as = $this->arguments['as']; $parentId = $this->arguments['parentId']; $itemsPerPage = $this->arguments['itemsPerPage']; $page = $_REQUEST['page'] ?? 1; if ($itemsPerPage == 'all') { $itemsPerPage = 99999; // the 'all' keyword raise an error during the api call $page = 1; } $searchParams = ['itemsPerPage' => $itemsPerPage]; // If a federation was selected in the filters, it is used as parent if($_REQUEST['search-federation']) { $parentId = $_REQUEST['search-federation']; } // Search structures by name if($_REQUEST['search-query']) { $searchParams['what'] = $_REQUEST['search-query']; } // Filters if($_REQUEST['search-category']) { $searchParams['category'] = $_REQUEST['search-category']; } if($_REQUEST['search-province']) { $province = ltrim($_REQUEST['search-province'], '_'); // a trailing dot may be used to avoid fluid to strip the zero from the postal code $searchParams['province'] = $province; } if($_REQUEST['search-distance-max']) { $searchParams['category'] = $_REQUEST['search-distance-max']; } $organizations = $this->federationRepository->findChildrenById($parentId, $searchParams, $page); $variables = [ $as => $organizations ]; return $this->renderChildrenWithVariables($variables); } /** * @param FederationStructureRepository $federationRepository */ public function injectFederationRepository(FederationStructureRepository $federationRepository) { $this->federationRepository = $federationRepository; } }