Advertisement
Guest User

Untitled

a guest
Jul 19th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. /**
  5.  * @ORM\Entity
  6.  * @ORM\Table(name="xxxx_groups")
  7.  */
  8. class Group implements GroupInterface
  9. {
  10.    
  11.    
  12.  
  13.     /**
  14.     * @ORM\Id
  15.     * @ORM\Column(type="integer")
  16.     * @ORM\GeneratedValue(strategy="AUTO")
  17.     */
  18.     protected $id;
  19.    
  20.    
  21.    
  22.     /**
  23.      * @ORM\Column(type="string", length="255", unique=true, nullable=false)
  24.      * @Assert\NotBlank(message="Please enter your Group.")
  25.      * @Assert\MinLength(limit="3", message="The name is too short.")
  26.      * @Assert\MaxLength(limit="255", message="The name is too long.")
  27.      */
  28.     protected $name;
  29.    
  30.    
  31.     /**
  32.      * @ORM\ManyToMany(targetEntity="Role" ,inversedBy="groups")
  33.      * @ORM\JoinTable(name="Group_Roles",
  34.      *      joinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")},
  35.      *      inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  36.      *      )
  37.      */
  38.     protected $roles;
  39.    
  40.    
  41.     /**
  42.      * Inverse Side
  43.      *
  44.      * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
  45.      */
  46.     protected $users;
  47.    
  48.    
  49.  
  50.     public function __construct() //$name, $roles = array())
  51.     {
  52.         //$this->name = $name;
  53.         $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
  54.     }
  55.  
  56.     public function addRole($role)
  57.     {
  58.         if (!$this->hasRole($role)) {
  59.             $this->roles[] = strtoupper($role);
  60.         }
  61.     }
  62.  
  63.     public function getId()
  64.     {
  65.         return $this->id;
  66.     }
  67.  
  68.     public function getName()
  69.     {
  70.         return $this->name;
  71.     }
  72.  
  73.     public function hasRole($role)
  74.     {
  75.         return in_array(strtoupper($role), $this->roles, true);
  76.     }
  77.  
  78.     public function getRoles()
  79.     {
  80.         return $this->roles;
  81.     }
  82.  
  83.     public function removeRole($role)
  84.     {
  85.         if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
  86.             unset($this->roles[$key]);
  87.             $this->roles = array_values($this->roles);
  88.         }
  89.     }
  90.  
  91.     public function setName($name)
  92.     {
  93.         $this->name = $name;
  94.     }
  95.  
  96.     public function setRoles(array $roles)
  97.     {
  98.         $this->roles = $roles;
  99.     }
  100.  
  101.     /**
  102.      * Add users
  103.      *
  104.      * @param xxxx\UserBundle\Entity\User $users
  105.      */
  106.     public function addUser(\xxxxx\UserBundle\Entity\User $users)
  107.     {
  108.         $this->users[] = $users;
  109.     }
  110.  
  111.     /**
  112.      * Get users
  113.      *
  114.      * @return Doctrine\Common\Collections\Collection
  115.      */
  116.     public function getUsers()
  117.     {
  118.         return $this->users;
  119.     }
  120.  
  121.     /**
  122.      * Add roles
  123.      *
  124.      * @param xxxx\UserBundle\Entity\Roles $roles
  125.      */
  126.     public function addRoles(\xxxxx\UserBundle\Entity\Roles $roles)
  127.     {
  128.         $this->roles[] = $roles;
  129.     }
  130.    
  131.     /**
  132.      * Return the role field.
  133.      * @return string
  134.      */
  135.     public function __toString()
  136.     {
  137.         return (string) $this->name;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement