當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::addGroup方法代碼示例

本文整理匯總了PHP中Oro\Bundle\UserBundle\Entity\User::addGroup方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::addGroup方法的具體用法?PHP User::addGroup怎麽用?PHP User::addGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Oro\Bundle\UserBundle\Entity\User的用法示例。


在下文中一共展示了User::addGroup方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var UserManager $userManager */
     $userManager = $this->container->get('oro_user.manager');
     $role = $manager->getRepository('OroUserBundle:Role')->findOneByRole('ROLE_ADMINISTRATOR');
     $group = $manager->getRepository('OroUserBundle:Group')->findOneByName('Administrators');
     $unit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneByName('Main');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $user = new User();
     $user->setUsername('owner_User');
     $user->addGroup($group);
     $user->addRole($role);
     $user->addBusinessUnit($unit);
     $user->setFirstname('Test Owner  FirstName');
     $user->setLastname('Test Owner LastName');
     $user->setEmail('owner@example.com');
     $user->setOwner($unit);
     $user->addGroup($group);
     $user->setPlainPassword('test password');
     $user->setSalt(md5(mt_rand(1, 222)));
     $user->setOrganization($organization);
     $userManager->updateUser($user);
     $this->setReference('owner_user', $user);
     $manager->flush();
 }
開發者ID:antrampa,項目名稱:crm,代碼行數:28,代碼來源:LoadOwnerUser.php

示例2: addDefaultGroup

 /**
  * Add the default group to the user.
  *
  * @param User $user
  *
  * @throws \RuntimeException
  */
 protected function addDefaultGroup(User $user)
 {
     if (!$user->hasGroup(User::GROUP_DEFAULT)) {
         $group = $this->manager->getStorageManager()->getRepository('OroUserBundle:Group')->getDefaultUserGroup();
         if (!$group) {
             throw new \RuntimeException('Default user group not found');
         }
         $user->addGroup($group);
     }
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:17,代碼來源:UserHandler.php

示例3: testGroups

 public function testGroups()
 {
     $user = new User();
     $role = new Role('ROLE_FOO');
     $group = new Group('Users');
     $group->addRole($role);
     $this->assertNotContains($role, $user->getRoles());
     $user->addGroup($group);
     $this->assertContains($group, $user->getGroups());
     $this->assertContains('Users', $user->getGroupNames());
     $this->assertTrue($user->hasRole($role));
     $this->assertTrue($user->hasGroup('Users'));
     $user->removeGroup($group);
     $this->assertFalse($user->hasRole($role));
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:15,代碼來源:UserTest.php


注:本文中的Oro\Bundle\UserBundle\Entity\User::addGroup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。