Passed
Pull Request — master (#177)
by
unknown
08:34
created

FrontendUser::setNotifyFulltextPublished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
namespace EWW\Dpf\Domain\Model;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use EWW\Dpf\Security\Security;
18
19
/**
20
* Frontend user
21
*/
22
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
23
{
24
    /**
25
     * storedSearches
26
     *
27
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\StoredSearch>
28
     * @cascade remove
29
     */
30
    protected $storedSearches = null;
31
32
    /**
33
     * frontendUserGroupRepository
34
     *
35
     * @var \EWW\Dpf\Domain\Repository\FrontendUserGroupRepository
36
     * @inject
37
     */
38
    protected $frontendUserGroupRepository = null;
39
    
40
    /**
41
     * @var boolean
42
     */
43
    protected $notifyPersonalLink = 0;
44
    
45
    /**
46
     * @var boolean
47
     */
48
    protected $notifyStatusChange = 0;
49
    
50
    /**
51
     * @var boolean
52
     */
53
    protected $notifyFulltextPublished = 0;
54
    
55
    /**
56
     * @var boolean
57
     */
58
    protected $notifyNewPublicationMypublication = 0;
59
60
    /**
61
     * __construct
62
     */
63
    public function __construct()
64
    {
65
        parent::__construct();
66
67
        //Do not remove the next line: It would break the functionality
68
        $this->initStorageObjects();
69
    }
70
71
    /**
72
     * Initializes all ObjectStorage properties
73
     *
74
     * @return void
75
     */
76
    protected function initStorageObjects()
77
    {
78
        $this->storedSearches = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
79
    }
80
81
82
    /**
83
     * Returns the storedSearches
84
     *
85
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\StoredSearch>
86
     */
87
    public function getStoredSearches()
88
    {
89
        return $this->storedSearches;
90
    }
91
92
    /**
93
     * Sets the storedSearches
94
     *
95
     * @param  \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\StoredSearch> $storedSearches
96
     * @return void
97
     */
98
    public function setStoredSearches(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $storedSearches)
99
    {
100
        $this->storedSearches = $storedSearches;
101
    }
102
103
    /**
104
     * @param \EWW\Dpf\Domain\Model\StoredSearch $storedSearch
105
     */
106
    public function addStoredSearch(\EWW\Dpf\Domain\Model\StoredSearch $storedSearch)
107
    {
108
        $this->storedSearches->attach($storedSearch);
109
    }
110
111
    /**
112
     * Get the role the user has in the current client
113
     *
114
     * @return string
115
     */
116
    public function getUserRole()
117
    {
118
        // Get frontend user groups of the client.
119
        $clientFrontendGroups = array();
120
        foreach ($this->frontendUserGroupRepository->findAll() as $clientGroup) {
121
            if ($clientGroup->getKitodoRole()) {
122
                $clientFrontendGroups[$clientGroup->getUid()] = $clientGroup;
123
            }
124
        }
125
126
        // Get frontend user groups of the user.
127
        $frontendUserGroups = array();
128
        foreach ($this->getUsergroup() as $userGroup) {
129
            // Because getUsergroup() does not return objects of the class
130
            // \EWW\Dpf\Domain\Model\FrontendUserRepository
131
            $userGroup = $this->frontendUserGroupRepository->findByUid($userGroup->getUid());
132
            $frontendUserGroups[$userGroup->getUid()] = $userGroup;
133
        }
134
135
        // Get the roles the user has in the current client.
136
        $roles = array();
137
        foreach ($frontendUserGroups as $uid => $group) {
138
            if (array_key_exists($uid, $clientFrontendGroups)) {
139
                $roles[$uid] = $group->getKitodoRole();
140
            }
141
        }
142
143
        if (in_array(Security::ROLE_LIBRARIAN, $roles)) {
144
            return Security::ROLE_LIBRARIAN;
145
        }
146
147
        if (in_array(Security::ROLE_RESEARCHER, $roles)) {
148
            return Security::ROLE_RESEARCHER;
149
        }
150
151
        return "";
152
    }
153
154
    /**
155
     * @return bool
156
     */
157
    public function isNotifyPersonalLink(): bool
158
    {
159
        return $this->notifyPersonalLink;
160
    }
161
162
    /**
163
     * @param bool $notifyPersonalLink
164
     */
165
    public function setNotifyPersonalLink(bool $notifyPersonalLink)
166
    {
167
        $this->notifyPersonalLink = $notifyPersonalLink;
168
    }
169
170
    /**
171
     * @return bool
172
     */
173
    public function isNotifyStatusChange(): bool
174
    {
175
        return $this->notifyStatusChange;
176
    }
177
178
    /**
179
     * @param bool $notifyStatusChange
180
     */
181
    public function setNotifyStatusChange(bool $notifyStatusChange)
182
    {
183
        $this->notifyStatusChange = $notifyStatusChange;
184
    }
185
186
    /**
187
     * @return bool
188
     */
189
    public function isNotifyFulltextPublished(): bool
190
    {
191
        return $this->notifyFulltextPublished;
192
    }
193
194
    /**
195
     * @param bool $notifyFulltextPublished
196
     */
197
    public function setNotifyFulltextPublished(bool $notifyFulltextPublished)
198
    {
199
        $this->notifyFulltextPublished = $notifyFulltextPublished;
200
    }
201
202
    /**
203
     * @return bool
204
     */
205
    public function isNotifyNewPublicationMypublication(): bool
206
    {
207
        return $this->notifyNewPublicationMypublication;
208
    }
209
210
    /**
211
     * @param bool $notifyNewPublicationMypublication
212
     */
213
    public function setNotifyNewPublicationMypublication(bool $notifyNewPublicationMypublication)
214
    {
215
        $this->notifyNewPublicationMypublication = $notifyNewPublicationMypublication;
216
    }
217
218
219
}