Completed
Push — master ( 2700b4...4ccb05 )
by Torben
04:03 queued 02:37
created

initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
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
            !$event->getEnableWaitlist()
47 8
        ) {
48
            $maxPossibleRegistrations = $event->getFreePlaces();
49 16
        } else {
50 16
            $maxPossibleRegistrations = $event->getMaxRegistrationsPerUser();
51 12
        }
52 12
        $result = [$maxPossibleRegistrations];
53 12
        if ($maxPossibleRegistrations >= $minPossibleRegistrations) {
54 16
            $arrayWithZeroAsIndex = range($minPossibleRegistrations, $maxPossibleRegistrations);
55
            $result = array_combine(range(1, count($arrayWithZeroAsIndex)), $arrayWithZeroAsIndex);
56
        }
57
58
        return $result;
59
    }
60
}
61