Passed
Push — master ( be4768...895194 )
by Jan
09:55
created

Group::getUsers()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as published
9
 * by the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
declare(strict_types=1);
22
23
/**
24
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
25
 *
26
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
27
 *
28
 * This program is free software; you can redistribute it and/or
29
 * modify it under the terms of the GNU General Public License
30
 * as published by the Free Software Foundation; either version 2
31
 * of the License, or (at your option) any later version.
32
 *
33
 * This program is distributed in the hope that it will be useful,
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
 * GNU General Public License for more details.
37
 *
38
 * You should have received a copy of the GNU General Public License
39
 * along with this program; if not, write to the Free Software
40
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
41
 */
42
43
namespace App\Entity\UserSystem;
44
45
use App\Entity\Attachments\GroupAttachment;
46
use App\Entity\Base\AbstractStructuralDBElement;
47
use App\Entity\Parameters\GroupParameter;
48
use App\Security\Interfaces\HasPermissionsInterface;
49
use App\Validator\Constraints\ValidPermission;
50
use Doctrine\Common\Collections\ArrayCollection;
51
use Doctrine\Common\Collections\Collection;
52
use Doctrine\ORM\Mapping as ORM;
53
use Symfony\Component\Validator\Constraints as Assert;
54
55
/**
56
 * This entity represents an user group.
57
 *
58
 * @ORM\Entity()
59
 * @ORM\Table("`groups`")
60
 */
61
class Group extends AbstractStructuralDBElement implements HasPermissionsInterface
62
{
63
    /**
64
     * @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
65
     * @ORM\OrderBy({"name" = "ASC"})
66
     */
67
    protected $children;
68
69
    /**
70
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="children")
71
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
72
     */
73
    protected $parent;
74
75
    /**
76
     * @ORM\OneToMany(targetEntity="User", mappedBy="group")
77
     */
78
    protected $users;
79
80
    /**
81
     * @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication
82
     * @ORM\Column(type="boolean", name="enforce_2fa")
83
     */
84
    protected $enforce2FA = false;
85
    /**
86
     * @var Collection<int, GroupAttachment>
87
     * @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
88
     * @ORM\OrderBy({"name" = "ASC"})
89
     * @Assert\Valid()
90
     */
91
    protected $attachments;
92
93
    /** @var PermissionsEmbed
94
     * @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_")
95
     * @ValidPermission()
96
     */
97
    protected $permissions;
98
99
    /** @var Collection<int, GroupParameter>
100
     * @ORM\OneToMany(targetEntity="App\Entity\Parameters\GroupParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
101
     * @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
102
     * @Assert\Valid()
103
     */
104
    protected $parameters;
105
106
107
    public function __construct()
108
    {
109
        parent::__construct();
110
        $this->permissions = new PermissionsEmbed();
111
        $this->users = new ArrayCollection();
112
    }
113
114
    /**
115
     * Check if the users of this group are enforced to have two factor authentification (2FA) enabled.
116
     *
117
     * @return bool
118
     */
119
    public function isEnforce2FA(): bool
120
    {
121
        return $this->enforce2FA;
122
    }
123
124
    /**
125
     * Sets if the user of this group are enforced to have two factor authentification enabled.
126
     *
127
     * @param bool $enforce2FA True, if the users of this group are enforced to have 2FA enabled.
128
     *
129
     * @return $this
130
     */
131
    public function setEnforce2FA(bool $enforce2FA): self
132
    {
133
        $this->enforce2FA = $enforce2FA;
134
135
        return $this;
136
    }
137
138
    public function getPermissions(): PermissionsEmbed
139
    {
140
        return $this->permissions;
141
    }
142
143
    public function getUsers(): Collection
144
    {
145
        return $this->users;
146
    }
147
}
148