/** * @return array */ public function getRoles() { $rolesEntities = $this->roles->toArray(); $roles = []; foreach ($rolesEntities as $role) { $roles[$role->getId()] = $role->getName(); } return $roles; }
/** * {@inheritdoc} */ public function getRoles() { $roles = $this->roles->toArray(); /** @var Group $group */ foreach ($this->groups as $group) { $roles = array_merge($roles, $group->getRoles()); } return array_values(array_unique($roles)); }
public function __toString() { if ($this->children->count()) { $childNameList = array(); foreach ($this->children as $child) { $childNameList[] = $child->getName(); } return sprintf('%s [%s]', $this->name, implode(', ', $childNameList)); } return sprintf('%s', $this->name); }
/** * Pass an array or Collection of Role objects and re-set roles collection with new Roles. * Type hinted array due to interface. * * @param array|Collection $roles Array of Role objects * * @return User * @throws \InvalidArgumentException */ public function setRoles($roles) { if (!$roles instanceof Collection && !is_array($roles)) { throw new \InvalidArgumentException('$roles must be an instance of Doctrine\\Common\\Collections\\Collection or an array'); } $this->roles->clear(); foreach ($roles as $role) { $this->addRole($role); } return $this; }
/** * @param Role $role * * @return $this */ public function removeAuthorizedRole(Role $role) { $this->authorizedRoles->removeElement($role); return $this; }
public function removeRole(Role $role) { $this->roles->removeElement($role); }
/** * @return Role[] * * @note Every user must *at least* have ROLE_USER as a role */ public function getRoles() { return array_unique(array_merge($this->roles->toArray(), ['ROLE_USER'])); }
/** * Replace the old platform roles of a user by a new array. * * @param $platformRoles */ public function setPlatformRoles($platformRoles) { $roles = $this->getEntityRoles(); $removedRoles = array(); foreach ($roles as $role) { if ($role->getType() != Role::WS_ROLE) { $removedRoles[] = $role; } } foreach ($removedRoles as $removedRole) { $this->roles->removeElement($removedRole); } foreach ($platformRoles as $platformRole) { $this->roles->add($platformRole); } }
/** * @param Role $role */ public function addRole(Role $role) { if (!$this->roles->contains($role)) { $this->roles->add($role); } }
/** * Remove children * * @param \Bigfish\Bundle\UserBundle\Entity\Role $children */ public function removeChild(\Bigfish\Bundle\UserBundle\Entity\Role $children) { $this->children->removeElement($children); }
/** * {@inheritdoc} */ public function hasAuthorizationRole(RoleInterface $role) { return $this->authorizationRoles->contains($role); }
/** * Remove role * * @param \AppBundle\Entity\Role $role */ public function removeRole(\AppBundle\Entity\Role $role) { $this->roles->removeElement($role); }
/** * Remove child * * @param \Fp\UserBundle\Entity\Role $child */ public function removeChild(\Fp\UserBundle\Entity\Role $child) { $this->children->removeElement($child); }
/** * (PHP 5 >= 5.1.0)<br/> * Returns if an iterator can be created for the current entry. * @link http://php.net/manual/en/recursiveiterator.haschildren.php * @return bool true if the current entry can be iterated over, otherwise returns false. */ public function hasChildren() { return $this->children->count() > 0; }
public function addRole(Movie $movie, $roles = null) { $roles = is_array($roles) ? $roles : []; $this->roles->add(new Role($this, $movie, $roles)); }
/** * @return Role[] */ public function getAuthorizedRoles() { return $this->authorizedRoles->toArray(); }