Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @ORM\Entity
- * @ORM\Table(name="xxxx_groups")
- */
- class Group implements GroupInterface
- {
- /**
- * @ORM\Id
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @ORM\Column(type="string", length="255", unique=true, nullable=false)
- * @Assert\NotBlank(message="Please enter your Group.")
- * @Assert\MinLength(limit="3", message="The name is too short.")
- * @Assert\MaxLength(limit="255", message="The name is too long.")
- */
- protected $name;
- /**
- * @ORM\ManyToMany(targetEntity="Role" ,inversedBy="groups")
- * @ORM\JoinTable(name="Group_Roles",
- * joinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
- * )
- */
- protected $roles;
- /**
- * Inverse Side
- *
- * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
- */
- protected $users;
- public function __construct() //$name, $roles = array())
- {
- //$this->name = $name;
- $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
- }
- public function addRole($role)
- {
- if (!$this->hasRole($role)) {
- $this->roles[] = strtoupper($role);
- }
- }
- public function getId()
- {
- return $this->id;
- }
- public function getName()
- {
- return $this->name;
- }
- public function hasRole($role)
- {
- return in_array(strtoupper($role), $this->roles, true);
- }
- public function getRoles()
- {
- return $this->roles;
- }
- public function removeRole($role)
- {
- if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
- unset($this->roles[$key]);
- $this->roles = array_values($this->roles);
- }
- }
- public function setName($name)
- {
- $this->name = $name;
- }
- public function setRoles(array $roles)
- {
- $this->roles = $roles;
- }
- /**
- * Add users
- *
- * @param xxxx\UserBundle\Entity\User $users
- */
- public function addUser(\xxxxx\UserBundle\Entity\User $users)
- {
- $this->users[] = $users;
- }
- /**
- * Get users
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getUsers()
- {
- return $this->users;
- }
- /**
- * Add roles
- *
- * @param xxxx\UserBundle\Entity\Roles $roles
- */
- public function addRoles(\xxxxx\UserBundle\Entity\Roles $roles)
- {
- $this->roles[] = $roles;
- }
- /**
- * Return the role field.
- * @return string
- */
- public function __toString()
- {
- return (string) $this->name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement