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