src/Daikin/BaseBundle/Entity/Role.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Daikin\BaseBundle\Entity;
  3. use \Serializable;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="role")
  9.  */
  10. class Role extends \Symfony\Component\Security\Core\Role\Role implements Serializable
  11. {
  12.     const ROLE_USER 'ROLE_USER';
  13.     const ROLE_ADMIN 'ROLE_ADMIN';
  14.     const ROLE_REFRIGERANT_COLLECT_COMPANY_USER 'ROLE_REFRIGERANT_COLLECT_COMPANY_USER';
  15.     const ROLE_REFRIGERANT_COLLECT_SHIPPER 'ROLE_REFRIGERANT_COLLECT_SHIPPER';
  16.     const ROLE_REFRIGERANT_COLLECT_SHIPPER_ADMIN 'ROLE_REFRIGERANT_COLLECT_SHIPPER_ADMIN';
  17.     const ROLE_APP_USER 'ROLE_APP_USER';
  18.     const ROLE_AHU_USER 'ROLE_AHU_USER';
  19.     const ROLE_AHU_ADMIN 'ROLE_AHU_ADMIN';
  20.     const ROLE_AR_SUPPORT 'ROLE_AR_SUPPORT';
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\Column(type="integer")
  24.      * @ORM\GeneratedValue(strategy="AUTO")
  25.      *
  26.      * @var integer $id
  27.      */
  28.     protected $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      *
  32.      * @var string $name
  33.      */
  34.     protected $name;
  35.     /**
  36.      * @ORM\Column(type="integer", name="created_at")
  37.      *
  38.      * @var integer $createdAt
  39.      */
  40.     protected $createdAt;
  41.     /**
  42.      * @ORM\Column(type="integer", options={"unsigned":true})
  43.      * @var int
  44.      */
  45.     private $sorting;
  46.     /**
  47.      * @ORM\Column(type="string", name="group_name")
  48.      * @var int
  49.      */
  50.     private $groupName;
  51.     /**
  52.      * @ORM\ManyToMany(targetEntity="User", mappedBy="userRoles")
  53.      */
  54.     protected $users;
  55.     public function __construct()
  56.     {
  57.       $this->users = new ArrayCollection();
  58.       $this->createdAt time();
  59.       $this->sorting 0;
  60.     }
  61.     public function __toString():string
  62.     {
  63.       return $this->name;
  64.     }
  65.     /**
  66.      * @see \Serializable::serialize()
  67.      */
  68.     public function serialize()
  69.     {
  70.         return \serialize(array(
  71.             $this->id
  72.         ));
  73.     }
  74.     /**
  75.      * @see \Serializable::unserialize()
  76.      */
  77.     public function unserialize($serialized)
  78.     {
  79.         list(
  80.             $this->id
  81.         ) = \unserialize($serialized);
  82.     }
  83.     /**
  84.      * get id property
  85.      *
  86.      * @return integer The id.
  87.      */
  88.     public function getId()
  89.     {
  90.         return $this->id;
  91.     }
  92.     /**
  93.      * get name property
  94.      *
  95.      * @return string The name.
  96.      */
  97.     public function getName()
  98.     {
  99.         return $this->name;
  100.     }
  101.     /**
  102.      * set name property
  103.      *
  104.      * @param string $value The name.
  105.      */
  106.     public function setName($value)
  107.     {
  108.         $this->name $value;
  109.     }
  110.     /**
  111.      * get created_at property
  112.      *
  113.      * @return integer A DateTime object.
  114.      */
  115.     public function getCreatedAt()
  116.     {
  117.         return $this->createdAt;
  118.     }
  119.     /**
  120.      * get role name
  121.      *
  122.      * @return string The role.
  123.      */
  124.     public function getRole()
  125.     {
  126.         return $this->getName();
  127.     }
  128.     /**
  129.      * Set createdAt
  130.      *
  131.      * @param integer $createdAt
  132.      */
  133.     public function setCreatedAt($createdAt)
  134.     {
  135.         $this->createdAt $createdAt;
  136.     }
  137.     public function getUsers()
  138.     {
  139.       return $this->users;
  140.     }
  141.     /**
  142.      * @return int
  143.      */
  144.     public function getSorting()
  145.     {
  146.         return $this->sorting;
  147.     }
  148.     /**
  149.      * @param int $sorting
  150.      * @return Role
  151.      */
  152.     public function setSorting($sorting)
  153.     {
  154.         $this->sorting $sorting;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return int
  159.      */
  160.     public function getGroupName()
  161.     {
  162.         return $this->groupName;
  163.     }
  164.     /**
  165.      * @param int $groupName
  166.      * @return Role
  167.      */
  168.     public function setGroupName($groupName)
  169.     {
  170.         $this->groupName $groupName;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @param Role $searchRole
  175.      * @param Role[]|[] $availRoles
  176.      * @return bool
  177.      */
  178.     public static function roleInRoles(Role $searchRole$availRoles)
  179.     {
  180.         if (!is_array($availRoles) || count($availRoles)<=|| !$searchRole instanceof Role) {
  181.             return false;
  182.         }
  183.         foreach ($availRoles as $availRole) {
  184.             if ($availRole instanceof Role && $availRole->getId() === $searchRole->getId()) {
  185.                 return true;
  186.             }
  187.         }
  188.         return false;
  189.     }
  190. }