GetAllViewHelper.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Donors;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtTemplating\Domain\Repository\DonorRepository;
  5. use Opentalent\OtTemplating\Exception\ApiRequestException;
  6. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  7. /**
  8. * This view helper give access to an array named according to the 'as' variable
  9. * and which contains all the donors of the given structure
  10. *
  11. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  12. *
  13. * <ot:donors.getAll as="donors"
  14. * organizationId="{settings.organizationId}">
  15. * <f:debug>{donors}</f:debug>
  16. * </ot:donors.getAll>
  17. *
  18. * @package Opentalent\OtTemplating\ViewHelpers
  19. */
  20. class GetAllViewHelper extends AbstractViewHelper {
  21. use TemplateVariableViewHelperTrait;
  22. /**
  23. * >> Required to prevent typo3 to escape the html output
  24. * @var boolean
  25. */
  26. protected $escapeOutput = false;
  27. /**
  28. * @var DonorRepository
  29. *
  30. */
  31. protected $donorRepository;
  32. /**
  33. * -- This method is expected by Fluid --
  34. * Declares the viewhelper's parameters
  35. */
  36. public function initializeArguments()
  37. {
  38. $this->registerArgument(
  39. 'as',
  40. 'string',
  41. 'Name of the returned array',
  42. true
  43. );
  44. $this->registerArgument(
  45. 'organizationId',
  46. 'integer',
  47. 'Id of the current structure',
  48. true
  49. );
  50. $this->registerArgument(
  51. 'fromParents',
  52. 'bool',
  53. 'Get donors from parents instead',
  54. false,
  55. 0
  56. );
  57. }
  58. /**
  59. * -- This method is expected by Fluid --
  60. * Renders the content as html
  61. *
  62. * @return string
  63. * @throws ApiRequestException
  64. */
  65. public function render()
  66. {
  67. // Get current settings
  68. $as = $this->arguments['as'];
  69. $organizationId = $this->arguments['organizationId'];
  70. $fromParents = $this->arguments['fromParents'];
  71. if ($fromParents) {
  72. // Get the donors of the parent structures
  73. $donors = $this->donorRepository->findParentsByOrganizationId($organizationId);
  74. } else {
  75. // Get donors of the structure
  76. $donors = $this->donorRepository->findByOrganizationId($organizationId);
  77. }
  78. $variables = [$as => $donors];
  79. return $this->renderChildrenWithVariables($variables);
  80. }
  81. /**
  82. * @param DonorRepository $donorRepository
  83. */
  84. public function injectDonorRepository(DonorRepository $donorRepository)
  85. {
  86. $this->donorRepository = $donorRepository;
  87. }
  88. }