| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\Donors;
- use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
- use Opentalent\OtTemplating\Domain\Repository\DonorRepository;
- use Opentalent\OtTemplating\Exception\ApiRequestException;
- use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
- /**
- * This view helper give access to an array 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 AbstractViewHelper {
- 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
- $donors = $this->donorRepository->findParentsByOrganizationId($organizationId);
- } else {
- // Get donors of the structure
- $donors = $this->donorRepository->findByOrganizationId($organizationId);
- }
- $variables = [$as => $donors];
- return $this->renderChildrenWithVariables($variables);
- }
- /**
- * @param DonorRepository $donorRepository
- */
- public function injectDonorRepository(DonorRepository $donorRepository)
- {
- $this->donorRepository = $donorRepository;
- }
- }
|