GetAllViewHelper.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Events;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtTemplating\Domain\Repository\EventRepository;
  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 containing all the upcoming events of the structure
  10. *
  11. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  12. *
  13. * <ot:events.getAll as="events"
  14. * organizationId="{settings.organizationId}">
  15. * <f:debug>{events}</f:debug>
  16. * </ot:events.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 EventRepository
  29. *
  30. */
  31. protected $eventRepository;
  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. 'fromChildren',
  52. 'bool',
  53. 'Get events from children 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. $fromChildren = $this->arguments['fromChildren'];
  71. $searchParams = [];
  72. if($_REQUEST['search-loc']) {
  73. $searchParams['where'] = $_REQUEST['search-loc'];
  74. }
  75. if($_REQUEST['search-name']) {
  76. $searchParams['what'] = $_REQUEST['search-name'];
  77. }
  78. if($_REQUEST['search-datestart']) {
  79. $dateStart = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-datestart']);
  80. $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
  81. }
  82. if($_REQUEST['search-dateend']) {
  83. $dateEnd = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-dateend']);
  84. $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
  85. }
  86. if ($fromChildren) {
  87. $searchParams['children'] = '1';
  88. }
  89. $events = $this->eventRepository->searchBy($organizationId, $searchParams);
  90. $variables = [$as => $events];
  91. return $this->renderChildrenWithVariables($variables);
  92. }
  93. /**
  94. * @param EventRepository $eventRepository
  95. */
  96. public function injectEventRepository(EventRepository $eventRepository)
  97. {
  98. $this->eventRepository = $eventRepository;
  99. }
  100. }