src/Submarine/UsersBundle/Entity/Group.php line 15

Open in your IDE?
  1. <?php
  2. namespace Submarine\UsersBundle\Entity;
  3. use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. /**
  7.  * Группа пользователей
  8.  *
  9.  * @ORM\Entity()
  10.  * @ORM\Table(name="submarine_auth_groups")
  11.  */
  12. class Group implements SubmarineEntityInterface\Serializable
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\Column(type="string", length=32, unique=true, nullable=false)
  17.      */
  18.     protected $id;
  19.     /**
  20.      * @ORM\Column(name="title", type="string", length=128)
  21.      */
  22.     protected $title;
  23.     /**
  24.      * @ORM\Column(type="text", nullable=true)
  25.      */
  26.     protected $description;
  27.     /**
  28.      * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
  29.      */
  30.     protected $users;
  31.     /**
  32.      * Имя сущности
  33.      * @return string
  34.      */
  35.     static public function entityName()
  36.     {
  37.         return __CLASS__;
  38.     }
  39.     function __construct()
  40.     {
  41.         $this->users = new ArrayCollection();
  42.     }
  43.     /**
  44.      * ID группы
  45.      * @return int
  46.      *
  47.      */
  48.     public function getId()
  49.     {
  50.         return $this->id;
  51.     }
  52.     /**
  53.      * ID группы
  54.      * @param int $id
  55.      */
  56.     public function setId($id)
  57.     {
  58.         $this->id $id;
  59.     }
  60.     /**
  61.      * Заголовок
  62.      * @return string
  63.      */
  64.     public function getTitle()
  65.     {
  66.         return $this->title;
  67.     }
  68.     /**
  69.      * Заголовок
  70.      * @param string $title
  71.      */
  72.     public function setTitle($title)
  73.     {
  74.         $this->title $title;
  75.     }
  76.     /**
  77.      * Пользователи группы
  78.      * @return User[]
  79.      */
  80.     public function getUsers()
  81.     {
  82.         return $this->users;
  83.     }
  84.     /**
  85.      * Пользователи группы
  86.      * @param User[] $users
  87.      */
  88.     public function setUsers($users)
  89.     {
  90.         $this->users $users;
  91.     }
  92.     /**
  93.      * Роль
  94.      * @return string
  95.      */
  96.     public function getRole()
  97.     {
  98.         return $this->getId();
  99.     }
  100.     /**
  101.      * Роль
  102.      * @param string $role
  103.      */
  104.     public function setRole($role)
  105.     {
  106.         $this->setId($role);
  107.     }
  108.     /**
  109.      * Описание
  110.      * @return string
  111.      */
  112.     public function getDescription()
  113.     {
  114.         return $this->description;
  115.     }
  116.     /**
  117.      * Описание
  118.      * @param string $description
  119.      */
  120.     public function setDescription($description)
  121.     {
  122.         $this->description $description;
  123.     }
  124.     //--------- Serialize --------
  125.     
  126.     /**
  127.      * (PHP 5 &gt;= 5.1.0)<br/>
  128.      * String representation of object
  129.      * @link http://php.net/manual/en/serializable.serialize.php
  130.      * @return string the string representation of the object or null
  131.      */
  132.     public function serialize()
  133.     {
  134.         return serialize([
  135.             'id' => $this->id,
  136.             'title' => $this->title,
  137.             'description' => $this->description
  138.         ]);
  139.     }
  140.     /**
  141.      * (PHP 5 &gt;= 5.1.0)<br/>
  142.      * Constructs the object
  143.      * @link http://php.net/manual/en/serializable.unserialize.php
  144.      * @param string $serialized <p>
  145.      * The string representation of the object.
  146.      * </p>
  147.      * @return void
  148.      */
  149.     public function unserialize($serialized)
  150.     {
  151.         $data unserialize($serialized);
  152.         $this->id $data['id'];
  153.         $this->title $data['title'];
  154.         $this->description $data['description'];
  155.     }
  156. }