* {donors} * * * @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 DonorRepository * */ protected $donorRepository; /** * -- 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( 'fromParents', 'bool', 'Get donors from parents instead', false, 0 ); } /** * -- This method is expected by Fluid -- * Renders the content as html * * @return string * @throws ApiRequestException */ public function render() { // Get current settings $as = $this->arguments['as']; $organizationId = $this->arguments['organizationId']; $fromParents = $this->arguments['fromParents']; if ($fromParents) { // Get the donors of the parent structures try { $donors = $this->donorRepository->findParentsByOrganizationId($organizationId); } catch (ApiRequestException $e) { OtLogger::error(sprintf('API Error: %s', $e->getMessage())); $donors = []; } } else { // Get donors of the structure try { $donors = $this->donorRepository->findByOrganizationId($organizationId); } catch (ApiRequestException $e) { OtLogger::error(sprintf('API Error: %s', $e->getMessage())); $donors = []; } } $variables = [$as => $donors]; return $this->renderChildrenWithVariables($variables); } /** * @param DonorRepository $donorRepository */ public function injectDonorRepository(DonorRepository $donorRepository) { $this->donorRepository = $donorRepository; } }