<?php
namespace Submarine\UsersBundle\Entity;
use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Группа пользователей
*
* @ORM\Entity()
* @ORM\Table(name="submarine_auth_groups")
*/
class Group implements SubmarineEntityInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=32, unique=true, nullable=false)
*/
protected $id;
/**
* @ORM\Column(name="title", type="string", length=128)
*/
protected $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $description;
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
*/
protected $users;
/**
* Имя сущности
* @return string
*/
static public function entityName()
{
return __CLASS__;
}
function __construct()
{
$this->users = new ArrayCollection();
}
/**
* ID группы
* @return int
*
*/
public function getId()
{
return $this->id;
}
/**
* ID группы
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Заголовок
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Заголовок
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Пользователи группы
* @return User[]
*/
public function getUsers()
{
return $this->users;
}
/**
* Пользователи группы
* @param User[] $users
*/
public function setUsers($users)
{
$this->users = $users;
}
/**
* Роль
* @return string
*/
public function getRole()
{
return $this->getId();
}
/**
* Роль
* @param string $role
*/
public function setRole($role)
{
$this->setId($role);
}
/**
* Описание
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Описание
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
//--------- Serialize --------
/**
* (PHP 5 >= 5.1.0)<br/>
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
*/
public function serialize()
{
return serialize([
'id' => $this->id,
'title' => $this->title,
'description' => $this->description
]);
}
/**
* (PHP 5 >= 5.1.0)<br/>
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->id = $data['id'];
$this->title = $data['title'];
$this->description = $data['description'];
}
}