1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Event; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
12
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* SimultaneousRegistrations ViewHelper |
16
|
|
|
* |
17
|
|
|
* @author Torben Hansen <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class SimultaneousRegistrationsViewHelper extends AbstractViewHelper |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Initialize arguments |
23
|
|
|
*/ |
24
|
|
|
public function initializeArguments() |
25
|
|
|
{ |
26
|
|
|
parent::initializeArguments(); |
27
|
|
|
$this->registerArgument('event', 'object', 'The event', true); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns an array with the amount of possible simultaneous registrations |
32
|
|
|
* respecting the maxRegistrationsPerUser setting and also respects the amount |
33
|
|
|
* of remaining free places. |
34
|
|
|
* |
35
|
|
|
* The returned array index starts at 1 if at least one registration is possible |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
16 |
|
*/ |
39
|
|
|
public function render() |
40
|
16 |
|
{ |
41
|
16 |
|
/** @var Event $event */ |
42
|
16 |
|
$event = $this->arguments['event']; |
43
|
10 |
|
$minPossibleRegistrations = 1; |
44
|
16 |
|
if ($event->getMaxParticipants() > 0 && |
45
|
8 |
|
$event->getMaxRegistrationsPerUser() >= $event->getFreePlaces() |
46
|
8 |
|
) { |
47
|
8 |
|
if ($event->getEnableWaitlist() && $event->getFreePlaces() <= 0) { |
48
|
|
|
$maxPossibleRegistrations = $event->getMaxRegistrationsPerUser(); |
49
|
16 |
|
} else { |
50
|
16 |
|
$maxPossibleRegistrations = $event->getFreePlaces(); |
51
|
12 |
|
} |
52
|
12 |
|
} else { |
53
|
12 |
|
$maxPossibleRegistrations = $event->getMaxRegistrationsPerUser(); |
54
|
16 |
|
} |
55
|
|
|
$result = [$maxPossibleRegistrations]; |
56
|
|
|
if ($maxPossibleRegistrations >= $minPossibleRegistrations) { |
57
|
|
|
$arrayWithZeroAsIndex = range($minPossibleRegistrations, $maxPossibleRegistrations); |
58
|
|
|
$result = array_combine(range(1, count($arrayWithZeroAsIndex)), $arrayWithZeroAsIndex); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $result; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|