. */ declare(strict_types=1); namespace App\Entity\UserSystem; use App\Entity\Attachments\GroupAttachment; use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Parameters\GroupParameter; use App\Security\Interfaces\HasPermissionsInterface; use App\Validator\Constraints\ValidPermission; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * This entity represents an user group. * * @ORM\Entity() * @ORM\Table("`groups`", indexes={ * @ORM\Index(name="group_idx_name", columns={"name"}), * @ORM\Index(name="group_idx_parent_name", columns={"parent_id", "name"}), * }) */ class Group extends AbstractStructuralDBElement implements HasPermissionsInterface { /** * @ORM\OneToMany(targetEntity="Group", mappedBy="parent") * @ORM\OrderBy({"name" = "ASC"}) * @var Collection */ protected $children; /** * @ORM\ManyToOne(targetEntity="Group", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") */ protected $parent; /** * @ORM\OneToMany(targetEntity="User", mappedBy="group") * @var Collection */ protected $users; /** * @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication * @ORM\Column(type="boolean", name="enforce_2fa") */ protected $enforce2FA = false; /** * @var Collection * @ORM\OneToMany(targetEntity="App\Entity\Attachments\GroupAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) * @ORM\OrderBy({"name" = "ASC"}) * @Assert\Valid() */ protected $attachments; /** * @var PermissionData|null * @ValidPermission() * @ORM\Embedded(class="PermissionData", columnPrefix="permissions_") */ protected ?PermissionData $permissions = null; /** @var Collection * @ORM\OneToMany(targetEntity="App\Entity\Parameters\GroupParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) * @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) * @Assert\Valid() */ protected $parameters; public function __construct() { parent::__construct(); $this->permissions = new PermissionData(); $this->users = new ArrayCollection(); } /** * Check if the users of this group are enforced to have two factor authentification (2FA) enabled. */ public function isEnforce2FA(): bool { return $this->enforce2FA; } /** * Sets if the user of this group are enforced to have two factor authentification enabled. * * @param bool $enforce2FA true, if the users of this group are enforced to have 2FA enabled * * @return $this */ public function setEnforce2FA(bool $enforce2FA): self { $this->enforce2FA = $enforce2FA; return $this; } public function getPermissions(): PermissionData { if ($this->permissions === null) { $this->permissions = new PermissionData(); } return $this->permissions; } public function getUsers(): Collection { return $this->users; } }