src/Platform/SecurityBundle/Entity/Access/RoleAssociation.php line 26

Open in your IDE?
  1. <?php
  2. namespace Platform\SecurityBundle\Entity\Access;
  3. use App\Entity\System\School;
  4. use Cms\ContainerBundle\Entity\Container;
  5. use Cms\TenantBundle\Entity\TenantedEntity;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Platform\SecurityBundle\Entity\Access\Role\CmsRole;
  8. use Platform\SecurityBundle\Entity\Access\Role\NotificationRole;
  9. use Products\NotificationsBundle\Entity\AbstractList;
  10. /**
  11.  * Class RoleAssociation
  12.  * @package Platform\SecurityBundle\Entity\Access
  13.  *
  14.  * @ORM\Entity(repositoryClass = "Platform\SecurityBundle\Doctrine\Access\RoleAssociationRepository")
  15.  * @ORM\InheritanceType("SINGLE_TABLE")
  16.  * @ORM\DiscriminatorColumn(name = "_discr", type = "string")
  17.  * @ORM\DiscriminatorMap({
  18.  *  "account" = "Platform\SecurityBundle\Entity\Access\RoleAssociation\AccountRoleAssociation",
  19.  *  "group" = "Platform\SecurityBundle\Entity\Access\RoleAssociation\GroupRoleAssociation"
  20.  * })
  21.  * @ORM\Table(name = "cms__security__access__role_association")
  22.  */
  23. abstract class RoleAssociation extends TenantedEntity
  24. {
  25.     public const INHERITANCES = array(
  26.         self::INHERITANCES__ME_ONLY,
  27.         //self::INHERITANCES__IMMEDIATE_DESCENDANTS_ONLY,
  28.         self::INHERITANCES__ALL_DESCENDANTS_ONLY,
  29.         //self::INHERITANCES__ME_AND_IMMEDIATE_DESCENDANTS,
  30.         self::INHERITANCES__ME_AND_ALL_DESCENDENTS,
  31.     );
  32.     public const INHERITANCES_CHOICES = array(
  33.         'Single department' => self::INHERITANCES__ME_ONLY,
  34.         //'Immediate sub-departments only' => self::INHERITANCES__IMMEDIATE_DESCENDANTS_ONLY,
  35.         'All sub-departments only' => self::INHERITANCES__ALL_DESCENDANTS_ONLY,
  36.         //'Single department and immediate sub-departments' => self::INHERITANCES__ME_AND_IMMEDIATE_DESCENDANTS,
  37.         'Single department and all sub-departments' => self::INHERITANCES__ME_AND_ALL_DESCENDENTS,
  38.     );
  39.     public const INHERITANCES__ME_ONLY null;
  40.     //const INHERITANCES__IMMEDIATE_DESCENDANTS_ONLY = 'immediate';
  41.     public const INHERITANCES__ALL_DESCENDANTS_ONLY 'all';
  42.     //const INHERITANCES__ME_AND_IMMEDIATE_DESCENDANTS = '+immediate';
  43.     public const INHERITANCES__ME_AND_ALL_DESCENDENTS '+all';
  44.     /**
  45.      * @var Role|null
  46.      *
  47.      * @ORM\ManyToOne(targetEntity = "Role", inversedBy = "associations")
  48.      * @ORM\JoinColumn(name = "role", referencedColumnName = "id", onDelete = "CASCADE")
  49.      */
  50.     protected ?Role $role null;
  51.     /**
  52.      * @var Container|null
  53.      *
  54.      * @ORM\ManyToOne(targetEntity = "Cms\ContainerBundle\Entity\Container")
  55.      * @ORM\JoinColumn(name = "container", referencedColumnName = "id", onDelete = "CASCADE")
  56.      */
  57.     protected ?Container $container null;
  58.     /**
  59.      * @var string|null
  60.      *
  61.      * @ORM\Column(
  62.      *     type = "string",
  63.      *     nullable = true,
  64.      * )
  65.      */
  66.     protected ?string $inheritance self::INHERITANCES__ME_ONLY;
  67.     /**
  68.      * @var School|null
  69.      *
  70.      * @ORM\ManyToOne(targetEntity = "App\Entity\System\School")
  71.      * @ORM\JoinColumn(name = "school", referencedColumnName = "id", onDelete = "CASCADE")
  72.      */
  73.     protected ?School $school null;
  74.     /**
  75.      * @var AbstractList|null
  76.      *
  77.      * @ORM\ManyToOne(targetEntity = "Products\NotificationsBundle\Entity\AbstractList")
  78.      * @ORM\JoinColumn(name = "list", referencedColumnName = "id", onDelete = "CASCADE")
  79.      */
  80.     protected ?AbstractList $list null;
  81.     /**
  82.      * @return Role|null
  83.      */
  84.     public function getRole(): ?Role
  85.     {
  86.         return $this->role;
  87.     }
  88.     /**
  89.      * @return Container|null
  90.      */
  91.     public function getContainer(): ?Container
  92.     {
  93.         return $this->container;
  94.     }
  95.     /**
  96.      * @return string|null
  97.      */
  98.     public function getInheritance(): ?string
  99.     {
  100.         return $this->inheritance;
  101.     }
  102.     /**
  103.      * @param Role|null $role
  104.      * @return $this
  105.      */
  106.     public function setRole(?Role $role): self
  107.     {
  108.         if ($role instanceof CmsRole && ($this->getSchool() || $this->getList())) {
  109.             throw new \LogicException('Cannot set a website role to an association using a notifications context.');
  110.         }
  111.         if ($role instanceof NotificationRole && $this->getContainer()) {
  112.             throw new \LogicException('Cannot set a notifications role to an association using a website context.');
  113.         }
  114.         $this->role $role;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @param Container|null $department
  119.      * @return $this
  120.      */
  121.     public function setContainer(?Container $department): self
  122.     {
  123.         if ($department && ($this->getList() || $this->getSchool())) {
  124.             throw new \LogicException('Cannot assign a department to an association when a list or school has already been set.');
  125.         }
  126.         if ($department && $this->getRole() instanceof NotificationRole) {
  127.             throw new \LogicException('Cannot assign a department to an association using a notifications role.');
  128.         }
  129.         $this->container $department;
  130.         return $this;
  131.     }
  132.     /**
  133.      * @param string|null $inheritance
  134.      * @return $this
  135.      */
  136.     public function setInheritance(?string $inheritance): self
  137.     {
  138.         if ( ! in_array($inheritanceself::INHERITANCEStrue)) {
  139.             throw new \LogicException();
  140.         }
  141.         $this->inheritance $inheritance;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return School|null
  146.      */
  147.     public function getSchool(): ?School
  148.     {
  149.         return $this->school;
  150.     }
  151.     /**
  152.      * @param School|null $school
  153.      * @return self
  154.      */
  155.     public function setSchool(?School $school): self
  156.     {
  157.         if ($school && ($this->getContainer() || $this->getList())) {
  158.             throw new \LogicException('Cannot assign a department to an association when a department or list has already been set.');
  159.         }
  160.         if ($school && $this->getRole() instanceof CmsRole) {
  161.             throw new \LogicException('Cannot assign a school to an association using a website role.');
  162.         }
  163.         $this->school $school;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return AbstractList|null
  168.      */
  169.     public function getList(): ?AbstractList
  170.     {
  171.         return $this->list;
  172.     }
  173.     /**
  174.      * @param AbstractList|null $list
  175.      * @return self
  176.      */
  177.     public function setList(?AbstractList $list): self
  178.     {
  179.         if ($list && ($this->getContainer() || $this->getSchool())) {
  180.             throw new \LogicException('Cannot assign a list when a department or school is already set.');
  181.         }
  182.         if ($list && $this->getRole() instanceof CmsRole) {
  183.             throw new \LogicException('Cannot assign a list to an association using a website role.');
  184.         }
  185.         $this->list $list;
  186.         return $this;
  187.     }
  188. }