GetFederationStructuresViewHelper.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Organizations;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtCore\Domain\Repository\FederationStructureRepository;
  5. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  6. /**
  7. * This view helper returns all of the organization children structures as an ApiPagedCollection, without pagination
  8. *
  9. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  10. *
  11. * <ot:organizations.getFederationStructures as="organization"
  12. * organizationId="1">
  13. * <f:debug>{organization}</f:debug>
  14. * </ot:organizations.getFederationStructures>
  15. *
  16. * @package Opentalent\OtTemplating\ViewHelpers
  17. */
  18. class GetFederationStructuresViewHelper extends OtAbstractViewHelper {
  19. use TemplateVariableViewHelperTrait;
  20. /**
  21. * >> Required to prevent typo3 to escape the html output
  22. * @var boolean
  23. */
  24. protected $escapeOutput = false;
  25. /**
  26. * @var FederationStructureRepository
  27. *
  28. */
  29. protected $federationRepository;
  30. /**
  31. * -- This method is expected by Fluid --
  32. * Declares the viewhelper's parameters
  33. */
  34. public function initializeArguments()
  35. {
  36. $this->registerArgument(
  37. 'as',
  38. 'string',
  39. 'Name of the returned array',
  40. true
  41. );
  42. $this->registerArgument(
  43. 'parentId',
  44. 'integer',
  45. 'Id of the parent organization',
  46. true
  47. );
  48. $this->registerArgument(
  49. 'itemsPerPage',
  50. 'string',
  51. 'Number of items per page',
  52. false,
  53. 10
  54. );
  55. }
  56. /**
  57. * -- This method is expected by Fluid --
  58. * Renders the content as html
  59. *
  60. * @return string
  61. */
  62. public function render()
  63. {
  64. $as = $this->arguments['as'];
  65. $parentId = $this->arguments['parentId'];
  66. $itemsPerPage = $this->arguments['itemsPerPage'];
  67. $page = $_REQUEST['page'] ?? 1;
  68. if ($itemsPerPage == 'all') {
  69. $itemsPerPage = 99999; // the 'all' keyword raise an error during the api call
  70. $page = 1;
  71. }
  72. $searchParams = ['itemsPerPage' => $itemsPerPage];
  73. $organizations = $this->federationRepository->findChildrenById($parentId, $searchParams, $page);
  74. $variables = [
  75. $as => $organizations
  76. ];
  77. return $this->renderChildrenWithVariables($variables);
  78. }
  79. /**
  80. * @param FederationStructureRepository $federationRepository
  81. */
  82. public function injectFederationRepository(FederationStructureRepository $federationRepository)
  83. {
  84. $this->federationRepository = $federationRepository;
  85. }
  86. }