| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\Organizations;
- use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
- use Opentalent\OtTemplating\Domain\Repository\OrganizationRepository;
- use Opentalent\OtTemplating\Exception\ApiRequestException;
- use Psr\Log\LoggerAwareInterface;
- use Psr\Log\LoggerAwareTrait;
- use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
- /**
- * This view helper returns the organization children structures as an ApiPagedCollection
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * <ot:organizations.getChildren as="organization"
- * organizationId="1">
- * <f:debug>{organization}</f:debug>
- * </ot:organizations.getChildren>
- *
- * @package Opentalent\OtTemplating\ViewHelpers
- */
- class GetChildrenViewHelper extends AbstractViewHelper implements LoggerAwareInterface {
- use LoggerAwareTrait;
- use TemplateVariableViewHelperTrait;
- /**
- * >> Required to prevent typo3 to escape the html output
- * @var boolean
- */
- protected $escapeOutput = false;
- /**
- * @var OrganizationRepository
- *
- */
- protected $organizationRepository;
- /**
- * -- 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 organization',
- true
- );
- $this->registerArgument(
- 'page',
- 'integer',
- 'Page number',
- false,
- 1
- );
- }
- /**
- * -- This method is expected by Fluid --
- * Renders the content as html
- *
- * @return string
- */
- public function render()
- {
- $as = $this->arguments['as'];
- $organizationId = $this->arguments['organizationId'];
- $page = $_REQUEST['page'];
- $searchParams = [];
- if($_REQUEST['search-loc']) {
- $searchParams['where'] = $_REQUEST['search-loc'];
- }
- try {
- $organizations = $this->organizationRepository->findChildrenById(
- $organizationId,
- $searchParams,
- $page
- );
- } catch (ApiRequestException $e) {
- $this->logger->error(sprintf('API Error: %s', $e->getMessage()));
- $organizations = [];
- }
- $variables = [
- $as => $organizations
- ];
- return $this->renderChildrenWithVariables($variables);
- }
- /**
- * @param OrganizationRepository $organizationRepository
- */
- public function injectOrganizationRepository(OrganizationRepository $organizationRepository)
- {
- $this->organizationRepository = $organizationRepository;
- }
- }
|