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. if($_REQUEST['search-loc']) {
  56. $searchParams['where'] = $_REQUEST['search-loc'];
  57. }
  58. if($_REQUEST['search-name']) {
  59. $searchParams['what'] = $_REQUEST['search-name'];
  60. }
  61. if($_REQUEST['search-datestart']) {
  62. $dateStart = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-datestart']);
  63. $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
  64. }
  65. if($_REQUEST['search-dateend']) {
  66. $dateEnd = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-dateend']);
  67. $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
  68. }
  69. $events = $this->eventRepository->searchBy($organizationId, $searchParams);
  70. $variables = [$as => $events];
  71. return $this->renderChildrenWithVariables($variables);
  72. }
  73. /**
  74. * @param \Opentalent\OtTemplating\Domain\Repository\EventRepository $eventRepository
  75. */
  76. public function injectEventRepository(EventRepository $eventRepository)
  77. {
  78. $this->eventRepository = $eventRepository;
  79. }
  80. }