GetAllViewHelper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }
  51. /**
  52. * -- This method is expected by Fluid --
  53. * Renders the content as html
  54. *
  55. * @return string
  56. * @throws ApiRequestException
  57. */
  58. public function render()
  59. {
  60. // Get current settings
  61. $as = $this->arguments['as'];
  62. $organizationId = $this->arguments['organizationId'];
  63. $searchParams = [];
  64. if($_REQUEST['search-loc']) {
  65. $searchParams['where'] = $_REQUEST['search-loc'];
  66. }
  67. if($_REQUEST['search-name']) {
  68. $searchParams['what'] = $_REQUEST['search-name'];
  69. }
  70. if($_REQUEST['search-datestart']) {
  71. $dateStart = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-datestart']);
  72. $searchParams['datetimeStart'] = $dateStart->format('d-m-Y');
  73. }
  74. if($_REQUEST['search-dateend']) {
  75. $dateEnd = \DateTime::createFromFormat('d/m/Y', $_REQUEST['search-dateend']);
  76. $searchParams['datetimeEnd'] = $dateEnd->format('d-m-Y');
  77. }
  78. $events = $this->eventRepository->searchBy($organizationId, $searchParams);
  79. $variables = [$as => $events];
  80. return $this->renderChildrenWithVariables($variables);
  81. }
  82. /**
  83. * @param EventRepository $eventRepository
  84. */
  85. public function injectEventRepository(EventRepository $eventRepository)
  86. {
  87. $this->eventRepository = $eventRepository;
  88. }
  89. }