Completed
Push — development ( 6b83c1...4f1043 )
by Torben
11:42
created

SimultaneousRegistrationsViewHelper::render()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 5
nc 4
nop 1
crap 5
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 TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
12
13
/**
14
 * SimultaneousRegistrations ViewHelper
15
 *
16
 * @author Torben Hansen <[email protected]>
17
 */
18
class SimultaneousRegistrationsViewHelper extends AbstractViewHelper
19
{
20
    /**
21
     * Returns an array with the amount of possible simultaneous registrations
22
     * respecting the maxRegistrationsPerUser setting and also respects the amount
23
     * of remaining free places.
24
     *
25
     * The returned array index starts at 1 if at least one registration is possible
26
     *
27
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
28
     *
29
     * @return array
30
     */
31
    public function render($event)
32
    {
33
        $minPossibleRegistrations = 1;
34
        if ($event->getMaxParticipants() > 0 &&
35
            $event->getMaxRegistrationsPerUser() >= $event->getFreePlaces() &&
36
            !$event->getEnableWaitlist()
37
        ) {
38 8
            $maxPossibleRegistrations = $event->getFreePlaces();
39
        } else {
40 8
            $maxPossibleRegistrations = $event->getMaxRegistrationsPerUser();
41 8
        }
42 8
        $result = [$maxPossibleRegistrations];
43 5
        if ($maxPossibleRegistrations >= $minPossibleRegistrations) {
44 8
            $arrayWithZeroAsIndex = range($minPossibleRegistrations, $maxPossibleRegistrations);
45 4
            $result = array_combine(range(1, count($arrayWithZeroAsIndex)), $arrayWithZeroAsIndex);
46 4
        }
47 4
48
        return $result;
49 8
    }
50
}
51