本文整理汇总了PHP中AppBundle\Entity\User::addGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP User::addGroup方法的具体用法?PHP User::addGroup怎么用?PHP User::addGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::addGroup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEntity
private function createEntity($username, $password, $email)
{
$securityEncodeFactory = $this->getContainer()->get('security.encoder_factory');
$em = $this->getContainer()->get('doctrine')->getEntityManager();
$groupRepo = $em->getRepository('AppBundle\\Entity\\Group');
$roleAdminGroup = $groupRepo->findOneByRole('ROLE_ADMIN');
$user = new User();
$user->setUsername($username);
$user->setPassword($password);
$user->setEmail($email);
$user->addGroup($roleAdminGroup);
$user->setIsActive(true);
$encoder = $securityEncodeFactory->getEncoder($user);
$password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($password);
return $user;
}
示例2: processGroupUpdates
public function processGroupUpdates(UserEntity $user, $data)
{
$allGroups = $this->groupManager->findGroups();
$allGroupNames = [];
foreach ($allGroups as $g) {
$allGroupNames[] = $g->getName();
}
foreach ($allGroupNames as $groupName) {
$g = $this->groupManager->findGroupByName($groupName);
if (!in_array($g->getId(), $data['groups'])) {
$user->removeGroup($g);
} else {
if (!$user->hasGroup($g)) {
$user->addGroup($g);
}
}
}
}
示例3: addGroup
/**
* {@inheritDoc}
*/
public function addGroup(\FOS\UserBundle\Model\GroupInterface $group)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'addGroup', [$group]);
return parent::addGroup($group);
}
示例4: addUser
/**
* Add user
*
* @param \AppBundle\Entity\User $user
*
* @return Group
*/
public function addUser(\AppBundle\Entity\User $user)
{
$this->user[] = $user;
$user->addGroup($this);
return $this;
}
示例5: basename
<?php
require_once __DIR__ . '/../../config/bootstrap.php';
use AppBundle\Entity\User;
//Check usage
if ($argc !== 6) {
echo "Usage:\n php ", basename($argv[0]), ' username email password roles groupID' . PHP_EOL;
exit;
}
//Create User
$user = new User($argv[1], $argv[2], $argv[3], explode(" ", $argv[4]));
//Get group (object)
$entityManager = GetEntityManager();
$groupsRepository = $entityManager->getRepository('AppBundle\\Entity\\Group');
$group = $groupsRepository->find(intval($argv[5]));
//Add user to group (many to many)
$user->addGroup($group);
//Add user to BBDD
$entityManager->persist($user);
$entityManager->flush();