blob: e7ab462025d4be120a542dbaedd91221a2d56edb [file] [log] [blame]
BacLuc955e1262020-03-15 11:13:38 +01001<?php
2
3
4namespace BaclucEventPackage\NextEvent;
5
6
BacLuc955e1262020-03-15 11:13:38 +01007use BaclucC5Crud\Controller\Renderer;
8use BaclucC5Crud\Controller\VariableSetter;
9use BaclucC5Crud\TableViewService;
BacLucb665bb52020-03-21 17:01:32 +010010use BaclucC5Crud\View\ViewActionRegistry;
BacLucae20eda2020-03-17 22:00:44 +010011use BaclucEventPackage\EventActionRegistryFactory;
BacLuca1254772020-03-29 12:34:34 +020012use BaclucEventPackage\NoEditIdFallbackActionProcessor;
BacLuc955e1262020-03-15 11:13:38 +010013use function BaclucC5Crud\Lib\collect as collect;
14
BacLuca1254772020-03-29 12:34:34 +020015class ShowNextEvent implements NoEditIdFallbackActionProcessor
BacLuc955e1262020-03-15 11:13:38 +010016{
BacLuc955e1262020-03-15 11:13:38 +010017 /**
18 * @var TableViewService
19 */
20 private $tableViewService;
21 /**
22 * @var VariableSetter
23 */
24 private $variableSetter;
25 /**
26 * @var Renderer
27 */
28 private $renderer;
BacLucb665bb52020-03-21 17:01:32 +010029 /**
30 * @var ViewActionRegistry
31 */
32 private $viewActionRegistry;
BacLuc955e1262020-03-15 11:13:38 +010033
34 /**
35 * ShowFormActionProcessor constructor.
36 * @param TableViewService $tableViewService
37 * @param VariableSetter $variableSetter
38 * @param Renderer $renderer
39 */
BacLucb665bb52020-03-21 17:01:32 +010040 public function __construct(
41 TableViewService $tableViewService,
42 VariableSetter $variableSetter,
43 Renderer $renderer,
44 ViewActionRegistry $viewActionRegistry
45 ) {
BacLuc955e1262020-03-15 11:13:38 +010046 $this->tableViewService = $tableViewService;
47 $this->variableSetter = $variableSetter;
48 $this->renderer = $renderer;
BacLucb665bb52020-03-21 17:01:32 +010049 $this->viewActionRegistry = $viewActionRegistry;
BacLuc955e1262020-03-15 11:13:38 +010050 }
51
52
53 function getName(): string
54 {
BacLucae20eda2020-03-17 22:00:44 +010055 return EventActionRegistryFactory::SHOW_NEXT_EVENT;
BacLuc955e1262020-03-15 11:13:38 +010056 }
57
58 function process(array $get, array $post, ...$additionalParameters)
59 {
60 $tableView = $this->tableViewService->getTableView();
61
BacLucb665bb52020-03-21 17:01:32 +010062 $rows = $tableView->getRows();
63 if (sizeof($rows) >= 1) {
64 $detailEntry = collect($rows)->first();
BacLuc89e7c462020-03-15 17:43:38 +010065 $eventfound = true;
BacLuc955e1262020-03-15 11:13:38 +010066 } else {
BacLuc89e7c462020-03-15 17:43:38 +010067 $eventfound = false;
BacLuc955e1262020-03-15 11:13:38 +010068 }
BacLuc89e7c462020-03-15 17:43:38 +010069 $this->variableSetter->set("eventfound", $eventfound);
70 if ($eventfound) {
71 foreach ($detailEntry as $key => $value) {
72 $this->variableSetter->set($key, $value);
73 }
BacLucb665bb52020-03-21 17:01:32 +010074 $this->variableSetter->set("eventId", array_keys($rows)[0]);
BacLuc89e7c462020-03-15 17:43:38 +010075 }
BacLucb665bb52020-03-21 17:01:32 +010076 $this->variableSetter->set("actions",
77 [$this->viewActionRegistry->getByName(EventActionRegistryFactory::SHOW_CANCEL_EVENT_FORM)]);
BacLuc89e7c462020-03-15 17:43:38 +010078 $this->renderer->render("view/nextevent");
BacLuc955e1262020-03-15 11:13:38 +010079 }
80
81}