| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\Organizations;
- use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
- use Opentalent\OtTemplating\Domain\Model\Organization;
- 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 return the Organization object matching the given id
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * <ot:organizations.getById as="organization"
- * organizationId="1">
- * <f:debug>{organization}</f:debug>
- * </ot:organizations.getById>
- *
- * @package Opentalent\OtTemplating\ViewHelpers
- */
- class GetByIdViewHelper 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 method is expected by Fluid --
- * Renders the content as html
- *
- * @return string
- * @throws ApiRequestException
- */
- public function render()
- {
- $as = $this->arguments['as'];
- $organizationId = $this->arguments['organizationId'];
- try {
- $organization = $this->organizationRepository->findById($organizationId);
- } catch (ApiRequestException $e) {
- $this->logger->error(sprintf('API Error: %s', $e->getMessage()));
- $organization = new Organization();
- $organization->setName("<Erreur: impossible d'afficher le résultat>");
- }
- $variables = [$as => $organization];
- return $this->renderChildrenWithVariables($variables);
- }
- /**
- * @param OrganizationRepository $organizationRepository
- */
- public function injectOrganizationRepository(OrganizationRepository $organizationRepository)
- {
- $this->organizationRepository = $organizationRepository;
- }
- }
|