GetAllViewHelper.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Donors;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtTemplating\Domain\Repository\DonorRepository;
  5. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  6. /**
  7. * This view helper provides an array named according to the 'as' variable
  8. * and which contains all the donors of the structure
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * <ot:donors.getAll as="donors"
  13. * organizationId="{settings.organizationId}">
  14. * <f:debug>{donors}</f:debug>
  15. * </ot:donors.getAll>
  16. *
  17. * @package Opentalent\OtTemplating\ViewHelpers
  18. */
  19. class GetAllViewHelper 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 \Opentalent\OtTemplating\Domain\Repository\DonorRepository
  28. *
  29. */
  30. protected $donorRepository;
  31. public function initializeArguments()
  32. {
  33. $this->registerArgument(
  34. 'as',
  35. 'string',
  36. 'Name of the returned array',
  37. true
  38. );
  39. $this->registerArgument(
  40. 'organizationId',
  41. 'integer',
  42. 'Id of the current structure',
  43. true
  44. );
  45. $this->registerArgument(
  46. 'fromParents',
  47. 'bool',
  48. 'Get donors from parents instead',
  49. false,
  50. 0
  51. );
  52. }
  53. /**
  54. * @return string
  55. */
  56. public function render()
  57. {
  58. // Get current settings
  59. $as = $this->arguments['as'];
  60. $organizationId = $this->arguments['organizationId'];
  61. $fromParents = $this->arguments['fromParents'];
  62. if ($fromParents) {
  63. // Get the donors of the parent structures
  64. $networkDonors = $this->donorRepository->findParentsByOrganizationId($organizationId);
  65. } else {
  66. // Get donors of the structure
  67. $donors = $this->donorRepository->findByOrganizationId($organizationId);
  68. }
  69. $variables = [$as => $donors];
  70. return $this->renderChildrenWithVariables($variables);
  71. }
  72. /**
  73. * @param \Opentalent\OtTemplating\Domain\Repository\DonorRepository $donorRepository
  74. */
  75. public function injectDonorRepository(DonorRepository $donorRepository)
  76. {
  77. $this->donorRepository = $donorRepository;
  78. }
  79. }