GetChildrenViewHelper.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Organizations;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtTemplating\Domain\Repository\OrganizationRepository;
  5. use Opentalent\OtTemplating\Exception\ApiRequestException;
  6. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  7. /**
  8. * This view helper returns the organization children structures
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * <ot:organizations.getChildren as="organization"
  13. * organizationId="1">
  14. * <f:debug>{organization}</f:debug>
  15. * </ot:organizations.getChildren>
  16. *
  17. * @package Opentalent\OtTemplating\ViewHelpers
  18. */
  19. class GetChildrenViewHelper extends AbstractViewHelper {
  20. use TemplateVariableViewHelperTrait;
  21. /**
  22. * >> Required to prevent typo3 to escape the html output
  23. * @var boolean
  24. */
  25. protected $escapeOutput = false;
  26. /**
  27. * @var OrganizationRepository
  28. *
  29. */
  30. protected $organizationRepository;
  31. /**
  32. * -- This method is expected by Fluid --
  33. * Declares the viewhelper's parameters
  34. */
  35. public function initializeArguments()
  36. {
  37. $this->registerArgument(
  38. 'as',
  39. 'string',
  40. 'Name of the returned array',
  41. true
  42. );
  43. $this->registerArgument(
  44. 'organizationId',
  45. 'integer',
  46. 'Id of the organization',
  47. true
  48. );
  49. }
  50. /**
  51. * -- This method is expected by Fluid --
  52. * Renders the content as html
  53. *
  54. * @return string
  55. * @throws ApiRequestException
  56. */
  57. public function render()
  58. {
  59. $as = $this->arguments['as'];
  60. $organizationId = $this->arguments['organizationId'];
  61. $searchParams = [];
  62. if($_REQUEST['search-loc']) {
  63. $searchParams['where'] = $_REQUEST['search-loc'];
  64. }
  65. $organization = $this->organizationRepository->findChildrenById($organizationId, $searchParams);
  66. $variables = [$as => $organization];
  67. return $this->renderChildrenWithVariables($variables);
  68. }
  69. /**
  70. * @param OrganizationRepository $organizationRepository
  71. */
  72. public function injectOrganizationRepository(OrganizationRepository $organizationRepository)
  73. {
  74. $this->organizationRepository = $organizationRepository;
  75. }
  76. }