| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\Donors;
- use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
- use Opentalent\OtCore\Domain\Repository\DonorRepository;
- use Opentalent\OtCore\Exception\ApiRequestException;
- use Opentalent\OtCore\Logging\OtLogger;
- use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
- /**
- * This view helper give access to an ApiPagedCollection named according to the 'as' variable
- * and which contains all the donors of the given structure
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * <ot:donors.getAll as="donors"
- * organizationId="{settings.organizationId}">
- * <f:debug>{donors}</f:debug>
- * </ot:donors.getAll>
- *
- * @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;
- }
- }
|