GetFederationStructuresViewHelper.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. $this->registerArgument(
  56. 'depth',
  57. 'integer',
  58. 'Max level of depth',
  59. false,
  60. 5
  61. );
  62. }
  63. /**
  64. * -- This method is expected by Fluid --
  65. * Renders the content as html
  66. *
  67. * @return string
  68. * @throws \Opentalent\OtCore\Exception\ApiRequestException
  69. */
  70. public function render()
  71. {
  72. $as = $this->arguments['as'];
  73. $parentId = $this->arguments['parentId'];
  74. $itemsPerPage = $this->arguments['itemsPerPage'];
  75. $page = $_REQUEST['page'] ?? 1;
  76. $depth = $_REQUEST['depth'] ?? 5;
  77. if ($itemsPerPage == 'all') {
  78. $itemsPerPage = 99999; // the 'all' keyword raise an error during the api call
  79. $page = 1;
  80. }
  81. $searchParams = ['itemsPerPage' => $itemsPerPage];
  82. // // If a federation was selected in the filters, it is used as parent
  83. // if($_REQUEST['search-federation']) {
  84. // $parentId = (int)$_REQUEST['search-federation'];
  85. // }
  86. //
  87. // // Search structures by name
  88. // if($_REQUEST['search-query']) {
  89. // $searchParams['what'] = $_REQUEST['search-query'];
  90. // }
  91. //
  92. // // Filters
  93. // if($_REQUEST['search-category']) {
  94. // $searchParams['category'] = $_REQUEST['search-category'];
  95. // }
  96. // if($_REQUEST['search-province']) {
  97. // // A leading '_' may have been added to prevent the '0' from being stripped by fluid
  98. // $province = ltrim($_REQUEST['search-province'], '_');
  99. // $searchParams['province'] = $province;
  100. // }
  101. // if($_REQUEST['lat']) {
  102. // $radius = (int)$_REQUEST['search-radius'] ?? 0;
  103. //
  104. // // radius is always increased of 10km to take into account the size of the city itself
  105. // $radius += 10;
  106. //
  107. // $searchParams['lat'] = $_REQUEST['lat'];
  108. // $searchParams['long'] = $_REQUEST['long'];
  109. // $searchParams['radius'] = $radius;
  110. // }
  111. $organizations = $this->federationRepository->findChildrenById($parentId, $searchParams, $page, $depth);
  112. $variables = [
  113. $as => $organizations
  114. ];
  115. return $this->renderChildrenWithVariables($variables);
  116. }
  117. /**
  118. * @param FederationStructureRepository $federationRepository
  119. */
  120. public function injectFederationRepository(FederationStructureRepository $federationRepository)
  121. {
  122. $this->federationRepository = $federationRepository;
  123. }
  124. }