本文整理汇总了PHP中Doctrine\Tests\Models\CMS\CmsUser::addGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP CmsUser::addGroup方法的具体用法?PHP CmsUser::addGroup怎么用?PHP CmsUser::addGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Tests\Models\CMS\CmsUser
的用法示例。
在下文中一共展示了CmsUser::addGroup方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testManyToManyAddRemove
public function testManyToManyAddRemove()
{
// Set up user with 2 groups
$user = new CmsUser();
$user->username = 'romanb';
$user->status = 'dev';
$user->name = 'Roman B.';
$group1 = new CmsGroup();
$group1->name = 'Developers';
$group2 = new CmsGroup();
$group2->name = 'Humans';
$user->addGroup($group1);
$user->addGroup($group2);
$this->_em->persist($user);
// cascades to groups
$this->_em->flush();
$this->_em->clear();
$uRep = $this->_em->getRepository(get_class($user));
// Get user
$user = $uRep->findOneById($user->getId());
$this->assertFalse($user->getGroups()->isInitialized());
// Check groups
$this->assertEquals(2, $user->getGroups()->count());
$this->assertTrue($user->getGroups()->isInitialized());
// Remove first group
unset($user->groups[0]);
//$user->getGroups()->remove(0);
$this->_em->flush();
$this->_em->clear();
// Reload same user
$user2 = $uRep->findOneById($user->getId());
// Check groups
$this->assertEquals(1, $user2->getGroups()->count());
}
示例2: setUp
public function setUp()
{
$this->useModelSet('cms');
parent::setUp();
$user1 = new CmsUser();
$user1->username = "beberlei";
$user1->name = "Benjamin";
$user1->status = "active";
$group1 = new CmsGroup();
$group1->name = "test";
$group2 = new CmsGroup();
$group2->name = "test";
$user1->addGroup($group1);
$user1->addGroup($group2);
$user2 = new CmsUser();
$user2->username = "romanb";
$user2->name = "Roman";
$user2->status = "active";
$this->_em->persist($user1);
$this->_em->persist($user2);
$this->_em->persist($group1);
$this->_em->persist($group2);
$this->_em->flush();
$this->_em->clear();
$this->user1 = $this->_em->find(get_class($user1), $user1->id);
$this->user2 = $this->_em->find(get_class($user1), $user2->id);
}
示例3: createNewValidUser
/**
* @return CmsUser
*/
private function createNewValidUser()
{
$user = new CmsUser();
$user->username = 'fran6co';
$user->name = 'Francisco Facioni';
$group = new CmsGroup();
$group->name = "users";
$user->addGroup($group);
return $user;
}
示例4: testCollectionChangesInsideTransaction
/**
* @group DDC-767
*/
public function testCollectionChangesInsideTransaction()
{
$user = new CmsUser();
$user->name = "beberlei";
$user->status = "active";
$user->username = "beberlei";
$group1 = new CmsGroup();
$group1->name = "foo";
$group2 = new CmsGroup();
$group2->name = "bar";
$group3 = new CmsGroup();
$group3->name = "baz";
$user->addGroup($group1);
$user->addGroup($group2);
$this->_em->persist($user);
$this->_em->persist($group1);
$this->_em->persist($group2);
$this->_em->persist($group3);
$this->_em->flush();
$this->_em->clear();
/* @var $pUser CmsUser */
$pUser = $this->_em->find(get_class($user), $user->id);
$this->assertNotNull($pUser, "User not retrieved from database.");
$groups = array($group2->id, $group3->id);
try {
$this->_em->beginTransaction();
$pUser->groups->clear();
$this->_em->flush();
// Add new
foreach ($groups as $groupId) {
$pUser->addGroup($this->_em->find(get_class($group1), $groupId));
}
$this->_em->flush();
$this->_em->commit();
} catch (\Exception $e) {
$this->_em->rollback();
}
}
示例5: benchPersistMany
public function benchPersistMany()
{
$parent1 = new ParentTestObj();
$parent1->nodename = "root1";
$parent1->name = "root1";
$parent1->setParentDocument($this->root);
$parent2 = new ParentTestObj();
$parent2->name = "/root2";
$parent2->nodename = "root2";
$parent2->setParentDocument($this->root);
$child = new ParentNoNodeNameTestObj();
$child->setParentDocument($parent1);
$child->name = "child";
$c1 = new Comment();
$c1->name = 'c1';
$c1->parent = $this->root;
$c1->setText('deutsch');
$group1 = new \Doctrine\Tests\Models\CMS\CmsGroup();
$group1->name = "Test!";
$group1->id = '/functional/group1';
$group2 = new \Doctrine\Tests\Models\CMS\CmsGroup();
$group2->name = "Test!";
$group2->id = '/functional/group2';
$user = new \Doctrine\Tests\Models\CMS\CmsUser();
$user->username = "beberlei";
$user->name = "Benjamin";
$user->addGroup($group1);
$user->addGroup($group2);
$this->documentManager->persist($parent1);
$this->documentManager->persist($parent2);
$this->documentManager->persist($child);
$this->documentManager->persist($c1);
$this->documentManager->persist($user);
$this->documentManager->persist($group1);
$this->documentManager->persist($group2);
$this->documentManager->flush();
}
示例6: createAndPersistUser
protected function createAndPersistUser()
{
$user = new CmsUser();
$user->name = 'Luka';
$user->username = 'lukacho';
$user->status = 'developer';
foreach (array(1111, 2222, 3333, 4444) as $number) {
$phone = new CmsPhonenumber();
$phone->phonenumber = $number;
$user->addPhonenumber($phone);
}
foreach (array('Moshers', 'Headbangers') as $groupName) {
$group = new CmsGroup();
$group->setName($groupName);
$user->addGroup($group);
}
$this->_em->persist($user);
return $user;
}
示例7: loadFixtureData
private function loadFixtureData()
{
$user = new CmsUser();
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'developer';
$address = new CmsAddress();
$address->country = 'Germany';
$address->city = 'Berlin';
$address->zip = '12345';
$user->address = $address;
// inverse side
$address->user = $user;
// owning side!
$group = new CmsGroup();
$group->name = 'foo_group';
$user->addGroup($group);
$article1 = new CmsArticle();
$article1->topic = "Test1";
$article1->text = "Test";
$article1->setAuthor($user);
$article2 = new CmsArticle();
$article2->topic = "Test2";
$article2->text = "Test";
$article2->setAuthor($user);
$this->_em->persist($article1);
$this->_em->persist($article2);
$this->_em->persist($user);
$user2 = new CmsUser();
$user2->name = 'Guilherme';
$user2->username = 'gblanco';
$user2->status = 'developer';
$address2 = new CmsAddress();
$address2->country = 'France';
$address2->city = 'Paris';
$address2->zip = '12345';
$user->address = $address2;
// inverse side
$address2->user = $user2;
// owning side!
$user2->addGroup($group);
$group2 = new CmsGroup();
$group2->name = 'bar_group';
$user2->addGroup($group2);
$this->_em->persist($user2);
$this->_em->flush();
$this->_em->clear();
$this->userId = $user->getId();
$this->userId2 = $user2->getId();
$this->articleId = $article1->id;
$this->articleId2 = $article2->id;
$this->groupId = $group->id;
$this->groupId2 = $group2->id;
}
示例8: addCmsUserGblancoWithGroups
/**
* @param int $groupCount
* @return CmsUser
*/
public function addCmsUserGblancoWithGroups($groupCount = 1)
{
$user = new CmsUser();
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
for ($i = 0; $i < $groupCount; ++$i) {
$group = new CmsGroup();
$group->name = 'Developers_' . $i;
$user->addGroup($group);
}
$this->_em->persist($user);
$this->_em->flush();
$this->assertNotNull($user->getId(), "User 'gblanco' should have an ID assigned after the persist()/flush() operation.");
return $user;
}
示例9: testManyToManyMergeAssociationRemoves
/**
* Test that changing associations on detached entities and then cascade merging them causes the
* database to be updated with the new associations.
*/
public function testManyToManyMergeAssociationRemoves()
{
$this->setCascadeMergeFor('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$this->setCascadeMergeFor('Doctrine\\Tests\\Models\\CMS\\CmsGroup');
$cmsUser = new CmsUser();
$cmsUser->username = "dave";
$cmsUser->name = "Dave Keen";
$cmsUser->status = "testing";
$group1 = new CmsGroup();
$group1->name = "Group 1";
$group2 = new CmsGroup();
$group2->name = "Group 2";
$cmsUser->addGroup($group1);
$cmsUser->addGroup($group2);
$this->_em->persist($cmsUser);
$this->_em->persist($group1);
$this->_em->persist($group2);
$this->_em->flush();
$cmsUserId = $cmsUser->id;
$group1Id = $group1->id;
$group2Id = $group2->id;
$this->_em->clear();
// Now create detached versions of the entities with NO associations.
$cmsUser = new CmsUser();
$cmsUser->id = $cmsUserId;
$cmsUser->username = "dave";
$cmsUser->name = "Dave Keen";
$cmsUser->status = "testing";
$cmsUser->groups = new ArrayCollection();
$group1 = new CmsGroup();
$group1->id = $group1Id;
$group1->name = "Group 1";
$group1->users = new ArrayCollection();
$group2 = new CmsGroup();
$group2->id = $group2Id;
$group2->name = "Group 2";
$group2->users = new ArrayCollection();
// Cascade merge of cmsUser followed by a flush should result in the association array collection being empty
$this->_em->merge($cmsUser);
$this->_em->flush();
$this->_em->clear();
$cmsUsers = $this->_em->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findAll();
$cmsGroups = $this->_em->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsGroup')->findAll();
// Check the entities are in the database
$this->assertEquals(1, sizeof($cmsUsers));
$this->assertEquals(2, sizeof($cmsGroups));
// Check the associations between the entities are now in the database
$this->assertEquals(0, sizeof($cmsUsers[0]->groups));
$this->assertEquals(0, sizeof($cmsGroups[0]->users));
$this->assertEquals(0, sizeof($cmsGroups[1]->users));
}
示例10: testBasicManyToManyJoin
public function testBasicManyToManyJoin()
{
$user = new CmsUser();
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$group1 = new CmsGroup();
$group1->setName('Doctrine Developers');
$user->addGroup($group1);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(0, $this->_em->getUnitOfWork()->size());
$query = $this->_em->createQuery("select u, g from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.groups g");
$result = $query->getResult();
$this->assertEquals(2, $this->_em->getUnitOfWork()->size());
$this->assertTrue($result[0] instanceof CmsUser);
$this->assertEquals('Guilherme', $result[0]->name);
$this->assertEquals(1, $result[0]->getGroups()->count());
$groups = $result[0]->getGroups();
$this->assertEquals('Doctrine Developers', $groups[0]->getName());
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($result[0]));
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($groups[0]));
$this->assertTrue($groups instanceof \Doctrine\ORM\PersistentCollection);
$this->assertTrue($groups[0]->getUsers() instanceof \Doctrine\ORM\PersistentCollection);
$groups[0]->getUsers()->clear();
$groups->clear();
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select u, g from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.groups g");
$this->assertEquals(0, count($query->getResult()));
}
示例11: populate
public function populate()
{
$groups = array();
for ($j = 0; $j < 3; $j++) {
$group = new CmsGroup();
$group->name = "group{$j}";
$groups[] = $group;
$this->_em->persist($group);
}
for ($i = 0; $i < 9; $i++) {
$user = new CmsUser();
$user->name = "Name{$i}";
$user->username = "username{$i}";
$user->status = "active";
$user->email = new CmsEmail();
$user->email->user = $user;
$user->email->email = "email{$i}";
for ($j = 0; $j < 3; $j++) {
$user->addGroup($groups[$j]);
}
$this->_em->persist($user);
for ($j = 0; $j < $i + 1; $j++) {
$article = new CmsArticle();
$article->topic = "topic{$i}{$j}";
$article->text = "text{$i}{$j}";
$article->setAuthor($user);
$article->version = 0;
$this->_em->persist($article);
}
}
for ($i = 0; $i < 9; $i++) {
$company = new Company();
$company->name = "name{$i}";
$company->logo = new Logo();
$company->logo->image = "image{$i}";
$company->logo->image_width = 100 + $i;
$company->logo->image_height = 100 + $i;
$company->logo->company = $company;
for ($j = 0; $j < 3; $j++) {
$department = new Department();
$department->name = "name{$i}{$j}";
$department->company = $company;
$company->departments[] = $department;
}
$this->_em->persist($company);
}
for ($i = 0; $i < 9; $i++) {
$user = new User1();
$user->name = "name{$i}";
$user->email = "email{$i}";
$this->_em->persist($user);
}
$manager = new CompanyManager();
$manager->setName('Roman B.');
$manager->setTitle('Foo');
$manager->setDepartment('IT');
$manager->setSalary(100000);
$this->_em->persist($manager);
$this->_em->flush();
}
示例12: testBasicManyToManyJoin
public function testBasicManyToManyJoin()
{
$user = new CmsUser();
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$group1 = new CmsGroup();
$group1->setName('Doctrine Developers');
$user->addGroup($group1);
$this->_em->save($user);
$this->_em->save($group1);
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(0, $this->_em->getUnitOfWork()->size());
$query = $this->_em->createQuery("select u, g from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.groups g");
$result = $query->getResultList();
$this->assertEquals(2, $this->_em->getUnitOfWork()->size());
$this->assertTrue($result[0] instanceof CmsUser);
$this->assertEquals('Guilherme', $result[0]->name);
$this->assertEquals(1, $result[0]->getGroups()->count());
$groups = $result[0]->getGroups();
$this->assertEquals('Doctrine Developers', $groups[0]->getName());
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($result[0]));
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($groups[0]));
$this->assertTrue($groups instanceof \Doctrine\ORM\PersistentCollection);
$this->assertTrue($groups[0]->getUsers() instanceof \Doctrine\ORM\PersistentCollection);
$groups[0]->getUsers()->clear();
$groups->clear();
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select u, g from Doctrine\\Tests\\Models\\CMS\\CmsUser u inner join u.groups g");
$this->assertEquals(0, count($query->getResultList()));
/* RB: TEST */
/*
$address = new CmsAddress;
$address->country = 'Germany';
$address->zip = '103040';
$address->city = 'Berlin';
$address->user = $user;
$this->_em->save($address);
$this->_em->clear();
$proxy = $this->_em->getProxyGenerator()->getAssociationProxy($user, $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('address'));
var_dump($proxy->getId());
//var_dump(get_class($proxy));
var_dump(get_class($proxy->user));
//var_dump($proxy);
//$proxy = $this->_em->getProxyGenerator()->getReferenceProxy('Doctrine\Tests\Models\CMS\CmsUser', 1);
//echo $proxy->getId();
//var_dump(serialize($proxy));
*/
}
示例13: testRefreshCollection
public function testRefreshCollection()
{
$user = new CmsUser();
$user->id = '/functional/Guilherme';
$user->username = 'gblanco';
// Add a group
$group1 = new CmsGroup();
$group1->name = "12345";
$group1->id = '/functional/group1';
$user->addGroup($group1);
// Add a group
$group2 = new CmsGroup();
$group2->name = "54321";
$group2->id = '/functional/group2';
$this->dm->persist($user);
$this->dm->persist($group1);
$this->dm->persist($group2);
$this->dm->flush();
$user->addGroup($group2);
$this->assertCount(2, $user->groups);
$user->groups->refresh();
$this->assertCount(1, $user->groups);
}