本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::setTranslationStrategy方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::setTranslationStrategy方法的具體用法?PHP DocumentManager::setTranslationStrategy怎麽用?PHP DocumentManager::setTranslationStrategy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::setTranslationStrategy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testQueryBuilder
public function testQueryBuilder()
{
$strategy = new ChildTranslationStrategy($this->dm);
$this->dm->setTranslationStrategy('children', $strategy);
$this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
// First save some translations
$data = array();
$data['topic'] = 'Some interesting subject';
$data['text'] = 'Lorem ipsum...';
$data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html');
$node = $this->getTestNode();
$node->setProperty('author', 'John Doe');
$node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle');
$strategy->saveTranslation($data, $node, $this->metadata, 'en');
// Save translation in another language
$data['topic'] = 'Un sujet intéressant';
$data['settings'] = array('is-active' => 'true', 'url' => 'super-article-en-francais.html');
$strategy->saveTranslation($data, $node, $this->metadata, 'fr');
$this->dm->flush();
$qb = $this->dm->createQueryBuilder();
$qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
$qb->where()->eq()->field('a.topic')->literal('Not Exist')->end();
$res = $qb->getQuery()->execute();
$this->assertCount(0, $res);
$qb = $this->dm->createQueryBuilder();
$qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
$qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
$res = $qb->getQuery()->execute();
$this->assertCount(0, $res);
$qb = $this->dm->createQueryBuilder();
$qb->setLocale(false);
$qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
$qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
$res = $qb->getQuery()->execute();
$this->assertCount(0, $res);
$qb = $this->dm->createQueryBuilder();
$qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
$qb->where()->eq()->field('a.topic')->literal('Some interesting subject')->end();
$res = $qb->getQuery()->execute();
$this->assertCount(1, $res);
$qb = $this->dm->createQueryBuilder();
$qb->setLocale('fr');
$qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
$qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
$res = $qb->getQuery()->execute();
$this->assertCount(1, $res);
}
示例2: testMultilangReferrers
/**
* There was a bug that documents translated fields where overwritten when they are re-created
*
* depends testCreate
*/
public function testMultilangReferrers()
{
$this->dm->setLocaleChooserStrategy(new \Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooser($this->localePrefs, 'en'));
$this->dm->setTranslationStrategy('attribute', new \Doctrine\ODM\PHPCR\Translation\TranslationStrategy\AttributeTranslationStrategy($this->dm));
$referrerTestObj = new ReferrerTestObjMultilang();
$referrerRefTestObj = new ReferrerRefTestObj();
$referrerTestObj->id = "/functional/referrerTestObj";
$referrerTestObj->name = "referrer";
$referrerRefTestObj->id = "/functional/referrerRefTestObj";
$referrerTestObj->reference = $referrerRefTestObj;
$this->dm->persist($referrerTestObj);
$this->dm->flush();
$this->dm->clear();
$referrer = $this->dm->find(null, '/functional/referrerTestObj');
$referenced = $this->dm->find(null, "/functional/referrerRefTestObj");
$referrer->name = 'changed';
$this->assertEquals('changed', $referrer->name);
$this->assertCount(1, $referenced->referrers);
$this->assertSame($referrer, $referenced->referrers->first());
$this->assertEquals('changed', $referrer->name);
}