src/Entity/UserGroup.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @Doctrine\ORM\Mapping\Entity
  16.  * @Doctrine\ORM\Mapping\Table(name="user_groups")
  17.  */
  18. class UserGroup implements TranslatableInterfaceBlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  19.     use BlameableTrait;
  20.     use TimestampableTrait;
  21.     use TranslatableTrait;
  22.     use SoftDeletableTrait;
  23.     /**
  24.      * @Assert\Valid
  25.      */
  26.     protected $translations;
  27.     /**
  28.      * @Doctrine\ORM\Mapping\Id
  29.      * @Doctrine\ORM\Mapping\Column(type="integer")
  30.      * @Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
  31.      */
  32.     protected $id;
  33.     /**
  34.      * @Doctrine\ORM\Mapping\OneToMany(targetEntity="UserGroupModule", mappedBy="group", cascade={"persist", "remove"})
  35.      */
  36.     protected $groupsModules;
  37.     /**
  38.      * @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\User", mappedBy="userGroup")
  39.      */
  40.     protected $users;
  41.     public function __construct()
  42.     {
  43.         $this->groupsModules = new \Doctrine\Common\Collections\ArrayCollection();
  44.         $this->users = new \Doctrine\Common\Collections\ArrayCollection();
  45.     }
  46.     public function countUsers() {
  47.         $c 0;
  48.         /** @var $user User */
  49.         foreach ($this->getUsers() as $user) {
  50.             if ($user->getDeletedBy() === null and $user->isEnabled()) {
  51.                 $c $c 1;
  52.             }
  53.         }
  54.         return $c;
  55.     }
  56.     /**
  57.      * Zwraca uprawnienia dla danego modułu
  58.      * @param string $moduleName Nazwa kodowa modułu
  59.      * @return boolean
  60.      */
  61.     public function getGroupModuleByName($moduleName)
  62.     {
  63.         foreach($this->groupsModules as $groupModule)
  64.         {
  65.             if($groupModule->getModule()->getCodeName() === $moduleName)
  66.             {
  67.                 return $groupModule;
  68.             }
  69.         }
  70.         return false;
  71.     }
  72.     /**
  73.      * Obsługa tłumaczeń
  74.      * @param $method
  75.      * @param $arguments
  76.      * @return mixed
  77.      */
  78.     public function __call($method$arguments)
  79.     {
  80.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  81.     }
  82.     public function getName(){
  83.         return $this->translate()->getName();
  84.     }
  85.     /**
  86.      * Get id
  87.      *
  88.      * @return integer
  89.      */
  90.     public function getId()
  91.     {
  92.         return $this->id;
  93.     }
  94.     /**
  95.      * Add groupsModule
  96.      *
  97.      * @param \App\Entity\UserGroupModule $groupsModule
  98.      *
  99.      * @return UserGroup
  100.      */
  101.     public function addGroupsModule(\App\Entity\UserGroupModule $groupsModule)
  102.     {
  103.         $groupsModule->setGroup($this);
  104.         $this->groupsModules[] = $groupsModule;
  105.         return $this;
  106.     }
  107.     /**
  108.      * Remove groupsModule
  109.      *
  110.      * @param \App\Entity\UserGroupModule $groupsModule
  111.      */
  112.     public function removeGroupsModule(\App\Entity\UserGroupModule $groupsModule)
  113.     {
  114.         $this->groupsModules->removeElement($groupsModule);
  115.     }
  116.     /**
  117.      * Get groupsModules
  118.      *
  119.      * @return \Doctrine\Common\Collections\Collection
  120.      */
  121.     public function getGroupsModules()
  122.     {
  123.         return $this->groupsModules;
  124.     }
  125.     /**
  126.      * Add user
  127.      *
  128.      * @param \App\Entity\User $user
  129.      *
  130.      * @return UserGroup
  131.      */
  132.     public function addUser(\App\Entity\User $user)
  133.     {
  134.         $this->users[] = $user;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Remove user
  139.      *
  140.      * @param \App\Entity\User $user
  141.      */
  142.     public function removeUser(\App\Entity\User $user)
  143.     {
  144.         $this->users->removeElement($user);
  145.     }
  146.     /**
  147.      * Get users
  148.      *
  149.      * @return \Doctrine\Common\Collections\Collection
  150.      */
  151.     public function getUsers()
  152.     {
  153.         return $this->users;
  154.     }
  155. }