1<?php
2namespace TYPO3\CMS\Extbase\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
17use TYPO3\CMS\Extbase\Annotation as Extbase;
18
19/**
20 * This model represents a backend usergroup.
21 */
22class BackendUserGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
23{
24    const FILE_OPPERATIONS = 1;
25    const DIRECTORY_OPPERATIONS = 4;
26    const DIRECTORY_COPY = 8;
27    const DIRECTORY_REMOVE_RECURSIVELY = 16;
28
29    /**
30     * @var string
31     * @Extbase\Validate("NotEmpty")
32     */
33    protected $title = '';
34
35    /**
36     * @var string
37     */
38    protected $description = '';
39
40    /**
41     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
42     */
43    protected $subGroups;
44
45    /**
46     * @var string
47     */
48    protected $modules = '';
49
50    /**
51     * @var string
52     */
53    protected $tablesListening = '';
54
55    /**
56     * @var string
57     */
58    protected $tablesModify = '';
59
60    /**
61     * @var string
62     */
63    protected $pageTypes = '';
64
65    /**
66     * @var string
67     */
68    protected $allowedExcludeFields = '';
69
70    /**
71     * @var string
72     */
73    protected $explicitlyAllowAndDeny = '';
74
75    /**
76     * @var string
77     */
78    protected $allowedLanguages = '';
79
80    /**
81     * @var bool
82     */
83    protected $workspacePermission = false;
84
85    /**
86     * @var string
87     */
88    protected $databaseMounts = '';
89
90    /**
91     * @var int
92     */
93    protected $fileOperationPermissions = 0;
94
95    /**
96     * @var string
97     */
98    protected $lockToDomain = '';
99
100    /**
101     * @var string
102     */
103    protected $tsConfig = '';
104
105    /**
106     * Constructs this backend usergroup
107     */
108    public function __construct()
109    {
110        $this->subGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
111    }
112
113    /**
114     * Setter for title
115     *
116     * @param string $title
117     */
118    public function setTitle($title)
119    {
120        $this->title = $title;
121    }
122
123    /**
124     * Getter for title
125     *
126     * @return string
127     */
128    public function getTitle()
129    {
130        return $this->title;
131    }
132
133    /**
134     * Setter for description
135     *
136     * @param string $description
137     */
138    public function setDescription($description)
139    {
140        $this->description = $description;
141    }
142
143    /**
144     * Getter for description
145     *
146     * @return string
147     */
148    public function getDescription()
149    {
150        return $this->description;
151    }
152
153    /**
154     * Setter for the sub groups
155     *
156     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $subGroups
157     */
158    public function setSubGroups(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $subGroups)
159    {
160        $this->subGroups = $subGroups;
161    }
162
163    /**
164     * Adds a sub group to this backend user group
165     *
166     * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $beGroup
167     */
168    public function addSubGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $beGroup)
169    {
170        $this->subGroups->attach($beGroup);
171    }
172
173    /**
174     * Removes sub group from this backend user group
175     *
176     * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $groupToDelete
177     */
178    public function removeSubGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $groupToDelete)
179    {
180        $this->subGroups->detach($groupToDelete);
181    }
182
183    /**
184     * Remove all sub groups from this backend user group
185     */
186    public function removeAllSubGroups()
187    {
188        $subGroups = clone $this->subGroups;
189        $this->subGroups->removeAll($subGroups);
190    }
191
192    /**
193     * Getter of sub groups
194     *
195     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
196     */
197    public function getSubGroups()
198    {
199        return $this->subGroups;
200    }
201
202    /**
203     * Setter for modules
204     *
205     * @param string $modules
206     */
207    public function setModules($modules)
208    {
209        $this->modules = $modules;
210    }
211
212    /**
213     * Getter for modules
214     *
215     * @return string
216     */
217    public function getModules()
218    {
219        return $this->modules;
220    }
221
222    /**
223     * Setter for tables listening
224     *
225     * @param string $tablesListening
226     */
227    public function setTablesListening($tablesListening)
228    {
229        $this->tablesListening = $tablesListening;
230    }
231
232    /**
233     * Getter for tables listening
234     *
235     * @return string
236     */
237    public function getTablesListening()
238    {
239        return $this->tablesListening;
240    }
241
242    /**
243     * Setter for tables modify
244     *
245     * @param string $tablesModify
246     */
247    public function setTablesModify($tablesModify)
248    {
249        $this->tablesModify = $tablesModify;
250    }
251
252    /**
253     * Getter for tables modify
254     *
255     * @return string
256     */
257    public function getTablesModify()
258    {
259        return $this->tablesModify;
260    }
261
262    /**
263     * Setter for page types
264     *
265     * @param string $pageTypes
266     */
267    public function setPageTypes($pageTypes)
268    {
269        $this->pageTypes = $pageTypes;
270    }
271
272    /**
273     * Getter for page types
274     *
275     * @return string
276     */
277    public function getPageTypes()
278    {
279        return $this->pageTypes;
280    }
281
282    /**
283     * Setter for allowed exclude fields
284     *
285     * @param string $allowedExcludeFields
286     */
287    public function setAllowedExcludeFields($allowedExcludeFields)
288    {
289        $this->allowedExcludeFields = $allowedExcludeFields;
290    }
291
292    /**
293     * Getter for allowed exclude fields
294     *
295     * @return string
296     */
297    public function getAllowedExcludeFields()
298    {
299        return $this->allowedExcludeFields;
300    }
301
302    /**
303     * Setter for explicitly allow and deny
304     *
305     * @param string $explicitlyAllowAndDeny
306     */
307    public function setExplicitlyAllowAndDeny($explicitlyAllowAndDeny)
308    {
309        $this->explicitlyAllowAndDeny = $explicitlyAllowAndDeny;
310    }
311
312    /**
313     * Getter for explicitly allow and deny
314     *
315     * @return string
316     */
317    public function getExplicitlyAllowAndDeny()
318    {
319        return $this->explicitlyAllowAndDeny;
320    }
321
322    /**
323     * Setter for allowed languages
324     *
325     * @param string $allowedLanguages
326     */
327    public function setAllowedLanguages($allowedLanguages)
328    {
329        $this->allowedLanguages = $allowedLanguages;
330    }
331
332    /**
333     * Getter for allowed languages
334     *
335     * @return string
336     */
337    public function getAllowedLanguages()
338    {
339        return $this->allowedLanguages;
340    }
341
342    /**
343     * Setter for workspace permission
344     *
345     * @param bool $workspacePermission
346     */
347    public function setWorkspacePermissions($workspacePermission)
348    {
349        $this->workspacePermission = $workspacePermission;
350    }
351
352    /**
353     * Getter for workspace permission
354     *
355     * @return bool
356     */
357    public function getWorkspacePermission()
358    {
359        return $this->workspacePermission;
360    }
361
362    /**
363     * Setter for database mounts
364     *
365     * @param string $databaseMounts
366     */
367    public function setDatabaseMounts($databaseMounts)
368    {
369        $this->databaseMounts = $databaseMounts;
370    }
371
372    /**
373     * Getter for database mounts
374     *
375     * @return string
376     */
377    public function getDatabaseMounts()
378    {
379        return $this->databaseMounts;
380    }
381
382    /**
383     * Getter for file operation permissions
384     *
385     * @param int $fileOperationPermissions
386     */
387    public function setFileOperationPermissions($fileOperationPermissions)
388    {
389        $this->fileOperationPermissions = $fileOperationPermissions;
390    }
391
392    /**
393     * Getter for file operation permissions
394     *
395     * @return int
396     */
397    public function getFileOperationPermissions()
398    {
399        return $this->fileOperationPermissions;
400    }
401
402    /**
403     * Check if file operations like upload, copy, move, delete, rename, new and
404     * edit files is allowed.
405     *
406     * @return bool
407     */
408    public function isFileOperationAllowed()
409    {
410        return $this->isPermissionSet(self::FILE_OPPERATIONS);
411    }
412
413    /**
414     * Set the the bit for file operations are allowed.
415     *
416     * @param bool $value
417     */
418    public function setFileOperationAllowed($value)
419    {
420        $this->setPermission(self::FILE_OPPERATIONS, $value);
421    }
422
423    /**
424     * Check if folder operations like move, delete, rename, and new are allowed.
425     *
426     * @return bool
427     */
428    public function isDirectoryOperationAllowed()
429    {
430        return $this->isPermissionSet(self::DIRECTORY_OPPERATIONS);
431    }
432
433    /**
434     * Set the the bit for directory operations are allowed.
435     *
436     * @param bool $value
437     */
438    public function setDirectoryOperationAllowed($value)
439    {
440        $this->setPermission(self::DIRECTORY_OPPERATIONS, $value);
441    }
442
443    /**
444     * Check if it is allowed to copy folders.
445     *
446     * @return bool
447     */
448    public function isDirectoryCopyAllowed()
449    {
450        return $this->isPermissionSet(self::DIRECTORY_COPY);
451    }
452
453    /**
454     * Set the the bit for copy directories.
455     *
456     * @param bool $value
457     */
458    public function setDirectoryCopyAllowed($value)
459    {
460        $this->setPermission(self::DIRECTORY_COPY, $value);
461    }
462
463    /**
464     * Check if it is allowed to remove folders recursively.
465     *
466     * @return bool
467     */
468    public function isDirectoryRemoveRecursivelyAllowed()
469    {
470        return $this->isPermissionSet(self::DIRECTORY_REMOVE_RECURSIVELY);
471    }
472
473    /**
474     * Set the the bit for remove directories recursively.
475     *
476     * @param bool $value
477     */
478    public function setDirectoryRemoveRecursivelyAllowed($value)
479    {
480        $this->setPermission(self::DIRECTORY_REMOVE_RECURSIVELY, $value);
481    }
482
483    /**
484     * Setter for lock to domain
485     *
486     * @param string $lockToDomain
487     */
488    public function setLockToDomain($lockToDomain)
489    {
490        $this->lockToDomain = $lockToDomain;
491    }
492
493    /**
494     * Getter for lock to domain
495     *
496     * @return string
497     */
498    public function getLockToDomain()
499    {
500        return $this->lockToDomain;
501    }
502
503    /**
504     * Setter for ts config
505     *
506     * @param string $tsConfig
507     */
508    public function setTsConfig($tsConfig)
509    {
510        $this->tsConfig = $tsConfig;
511    }
512
513    /**
514     * Getter for ts config
515     *
516     * @return string
517     */
518    public function getTsConfig()
519    {
520        return $this->tsConfig;
521    }
522
523    /**
524     * Helper method for checking the permissions bitwise.
525     *
526     * @param int $permission
527     * @return bool
528     */
529    protected function isPermissionSet($permission)
530    {
531        return ($this->fileOperationPermissions & $permission) == $permission;
532    }
533
534    /**
535     * Helper method for settung permissions bitwise.
536     *
537     * @param int $permission
538     * @param bool $value
539     */
540    protected function setPermission($permission, $value)
541    {
542        if ($value) {
543            $this->fileOperationPermissions |= $permission;
544        } else {
545            $this->fileOperationPermissions &= ~$permission;
546        }
547    }
548}
549