GetFederationStructuresViewHelper.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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\Exception\ApiRequestException;
  6. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  7. /**
  8. * This view helper returns all of the organization children structures as an ApiPagedCollection, without pagination
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * <ot:organizations.getFederationStructures as="organization"
  13. * organizationId="1">
  14. * <f:debug>{organization}</f:debug>
  15. * </ot:organizations.getFederationStructures>
  16. *
  17. * @package Opentalent\OtTemplating\ViewHelpers
  18. */
  19. class GetFederationStructuresViewHelper extends OtAbstractViewHelper {
  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 FederationStructureRepository
  28. *
  29. */
  30. protected $federationRepository;
  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. 'parentId',
  45. 'integer',
  46. 'Id of the parent organization',
  47. true
  48. );
  49. $this->registerArgument(
  50. 'itemsPerPage',
  51. 'string',
  52. 'Number of items per page',
  53. false,
  54. 10
  55. );
  56. $this->registerArgument(
  57. 'depth',
  58. 'integer',
  59. 'Max level of depth',
  60. false,
  61. 5
  62. );
  63. }
  64. /**
  65. * -- This method is expected by Fluid --
  66. * Renders the content as html
  67. *
  68. * @return string
  69. * @throws ApiRequestException
  70. */
  71. public function render()
  72. {
  73. $as = $this->arguments['as'];
  74. $parentId = $this->arguments['parentId'];
  75. $itemsPerPage = $this->arguments['itemsPerPage'];
  76. $page = $_REQUEST['page'] ?? 1;
  77. $depth = $_REQUEST['depth'] ?? 5;
  78. if ($itemsPerPage == 'all') {
  79. $itemsPerPage = 99999; // the 'all' keyword raise an error during the api call
  80. $page = 1;
  81. }
  82. $searchParams = ['itemsPerPage' => $itemsPerPage];
  83. // // If a federation was selected in the filters, it is used as parent
  84. // if($_REQUEST['search-federation']) {
  85. // $parentId = (int)$_REQUEST['search-federation'];
  86. // }
  87. //
  88. // // Search structures by name
  89. // if($_REQUEST['search-query']) {
  90. // $searchParams['what'] = $_REQUEST['search-query'];
  91. // }
  92. //
  93. // // Filters
  94. // if($_REQUEST['search-category']) {
  95. // $searchParams['category'] = $_REQUEST['search-category'];
  96. // }
  97. // if($_REQUEST['search-province']) {
  98. // // A leading '_' may have been added to prevent the '0' from being stripped by fluid
  99. // $province = ltrim($_REQUEST['search-province'], '_');
  100. // $searchParams['province'] = $province;
  101. // }
  102. // if($_REQUEST['lat']) {
  103. // $radius = (int)$_REQUEST['search-radius'] ?? 0;
  104. //
  105. // // radius is always increased of 10km to take into account the size of the city itself
  106. // $radius += 10;
  107. //
  108. // $searchParams['lat'] = $_REQUEST['lat'];
  109. // $searchParams['long'] = $_REQUEST['long'];
  110. // $searchParams['radius'] = $radius;
  111. // }
  112. $organizations = $this->federationRepository->findChildrenById($parentId, $searchParams, $page, $depth);
  113. $variables = [
  114. $as => $organizations
  115. ];
  116. return $this->renderChildrenWithVariables($variables);
  117. }
  118. /**
  119. * @param FederationStructureRepository $federationRepository
  120. */
  121. public function injectFederationRepository(FederationStructureRepository $federationRepository)
  122. {
  123. $this->federationRepository = $federationRepository;
  124. }
  125. }