Passed
Push — master ( 25a010...d9c103 )
by
unknown
14:59
created

ModuleData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Beuser\Domain\Model;
19
20
/**
21
 * Module data object
22
 * @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
23
 */
24
class ModuleData
25
{
26
    protected Demand $demand;
27
    protected array $compareUserList = [];
28
29
    public function __construct()
30
    {
31
        $this->demand = new Demand();
32
    }
33
34
    public static function fromUc(array $uc): self
35
    {
36
        $moduleData = new self();
37
        $moduleData->compareUserList = (array)($uc['compareUserList'] ?? []);
38
        $moduleData->demand = Demand::fromUc($uc['demand'] ?? []);
39
        return $moduleData;
40
    }
41
42
    public function forUc(): array
43
    {
44
        return [
45
            'compareUserList' => $this->compareUserList,
46
            'demand' => $this->demand->forUc(),
47
        ];
48
    }
49
50
    public function getDemand(): Demand
51
    {
52
        return $this->demand;
53
    }
54
55
    public function setDemand(Demand $demand): void
56
    {
57
        $this->demand = $demand;
58
    }
59
60
    protected function setCompareUserList(array $compareUserList): void
61
    {
62
        $this->compareUserList = $compareUserList;
63
    }
64
65
    /**
66
     * Returns the compare list as array of user uids
67
     */
68
    public function getCompareUserList(): array
69
    {
70
        return array_keys($this->compareUserList);
71
    }
72
73
    public function resetCompareUserList(): void
74
    {
75
        $this->compareUserList = [];
76
    }
77
78
    /**
79
     * Adds one backend user (by uid) to the compare user list
80
     * Cannot be ObjectStorage, must be array
81
     *
82
     * @param int $uid
83
     */
84
    public function attachUidCompareUser(int $uid): void
85
    {
86
        $this->compareUserList[$uid] = true;
87
    }
88
89
    /**
90
     * Strip one backend user from the compare user list
91
     *
92
     * @param int $uid
93
     */
94
    public function detachUidCompareUser(int $uid): void
95
    {
96
        unset($this->compareUserList[$uid]);
97
    }
98
}
99