GetAllViewHelper.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Events;
  3. use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
  4. use Opentalent\OtTemplating\Domain\Repository\EventRepository;
  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 the next events of the structure
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * <ot:events.getAll as="events"
  13. * organizationId="{settings.organizationId}">
  14. * <f:debug>{events}</f:debug>
  15. * </ot:events.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\EventRepository
  28. *
  29. */
  30. protected $eventRepository;
  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. }
  46. /**
  47. * @return string
  48. */
  49. public function render()
  50. {
  51. // Get current settings
  52. $as = $this->arguments['as'];
  53. $organizationId = $this->arguments['organizationId'];
  54. $searchParams = [];
  55. // $args = $this->request->getArguments();
  56. // if($args['search-loc']) {
  57. // $searchParams['where'] = $args['search-loc'];
  58. // }
  59. // if($args['search-name']) {
  60. // $searchParams['what'] = $args['search-name'];
  61. // }
  62. // if($args['search-datestart']) {
  63. // $dateStart = \DateTime::createFromFormat('d/m/Y', $args['search-datestart']);
  64. // $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
  65. // }
  66. // if($args['search-dateend']) {
  67. // $dateEnd = \DateTime::createFromFormat('d/m/Y', $args['search-dateend']);
  68. // $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
  69. // }
  70. $events = $this->eventRepository->searchBy($organizationId, $searchParams);
  71. $variables = [$as => $events];
  72. return $this->renderChildrenWithVariables($variables);
  73. }
  74. /**
  75. * @param \Opentalent\OtTemplating\Domain\Repository\EventRepository $eventRepository
  76. */
  77. public function injectEventRepository(EventRepository $eventRepository)
  78. {
  79. $this->eventRepository = $eventRepository;
  80. }
  81. }