Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2291,11 +2291,18 @@ public function getChildren($document, $filter = null, $fetchDepth = null, $igno
$node = $this->session->getNode($this->getDocumentId($document));
$this->setFetchDepth($oldFetchDepth);

$metadata = $this->dm->getClassMetadata(get_class($document));
$locale = $this->getLocale($document, $metadata);
$childrenHints = array();
if (!is_null($locale)) {
$childrenHints['locale'] = $locale;
}

$childNodes = $node->getNodes($filter);
$childDocuments = array();
foreach ($childNodes as $name => $childNode) {
try {
$childDocuments[$name] = $this->createDocument(null, $childNode);
$childDocuments[$name] = $this->createDocument(null, $childNode, $childrenHints);
} catch (MissingTranslationException $e) {
if (!$ignoreUntranslated) {
throw $e;
Expand Down
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/Models/Translation/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\Models\Translation;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\Common\Collections\ArrayCollection;

/**
* @PHPCRODM\Document(translator="attribute")
Expand Down Expand Up @@ -33,6 +34,14 @@ class Article
/** @PHPCRODM\String(translated=true) */
private $text;

/** @PHPCRODM\Children() */
protected $children;

public function __construct()
{
$this->children = new ArrayCollection();
}

public function getText()
{
return $this->text;
Expand All @@ -41,4 +50,22 @@ public function setText($text)
{
$this->text = $text;
}

/**
* @return ArrayCollection
*/
public function getChildren()
{
return $this->children;
}

/**
* Sets the children
*
* @param $children ArrayCollection
*/
public function setChildren(ArrayCollection $children)
{
$this->children = $children;
}
}
46 changes: 46 additions & 0 deletions tests/Doctrine/Tests/Models/Translation/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Doctrine\Tests\Models\Translation;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
* @PHPCRODM\Document(translator="attribute")
*/
class Comment
{
/** @PHPCRODM\Id(strategy="parent") */
public $id;

/**
* @PHPCRODM\Nodename()
*/
public $name;

/**
* @PHPCRODM\Locale
*/
public $locale = 'en';

/** @PHPCRODM\ParentDocument */
public $parent;

/** @PHPCRODM\String(translated=true) */
private $text;

/**
* @return string
*/
public function getText()
{
return $this->text;
}

/**
* @param string $text
*/
public function setText($text)
{
$this->text = $text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\ODM\PHPCR\Functional\Translation;

use Doctrine\Tests\Models\Translation\Article,
Doctrine\Tests\Models\Translation\Comment,
Doctrine\Tests\Models\Translation\InvalidMapping,
Doctrine\Tests\Models\Translation\DerivedArticle,
Doctrine\Tests\Models\CMS\CmsArticle,
Expand Down Expand Up @@ -41,6 +42,11 @@ class DocumentManagerTest extends PHPCRFunctionalTestCase
*/
protected $class = 'Doctrine\Tests\Models\Translation\Article';

/**
* @var string
*/
protected $childrenClass = 'Doctrine\Tests\Models\Translation\Comment';

public function setUp()
{
$localePrefs = array(
Expand Down Expand Up @@ -246,6 +252,54 @@ public function testFindTranslation()
$this->assertEquals('Un autre sujet', $doc->topic);
}

/**
* Test that children are retrieved in the parent locale
*/
public function testFindTranslationWithChildren()
{
$this->dm->persist($this->doc);
$this->dm->bindTranslation($this->doc, 'en');
$this->doc->topic = 'Un autre sujet';
$this->dm->bindTranslation($this->doc, 'fr');

$comment = new Comment();
$comment->name = 'new-comment';
$comment->parent = $this->doc;
$this->dm->persist($comment);

$comment->setText('This is a great article');
$this->dm->bindTranslation($comment, 'en');
$comment->setText('Très bon article');
$this->dm->bindTranslation($comment, 'fr');
$this->dm->flush();

$doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'fr');
$this->assertEquals('fr', $doc->locale);
$children = $doc->getChildren();
foreach ($children as $comment) {
$this->assertEquals('fr', $comment->locale);
$this->assertEquals('Très bon article', $comment->getText());
}
$children = $this->dm->getChildren($doc);
foreach ($children as $comment) {
$this->assertEquals('fr', $comment->locale);
$this->assertEquals('Très bon article', $comment->getText());
}

$doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'en');
$this->assertEquals('en', $doc->locale);
$children = $doc->getChildren();
foreach ($children as $comment) {
$this->assertEquals('en', $comment->locale);
$this->assertEquals('This is a great article', $comment->getText());
}
$children = $this->dm->getChildren($doc);
foreach ($children as $comment) {
$this->assertEquals('en', $comment->locale);
$this->assertEquals('This is a great article', $comment->getText());
}
}

public function testFindByUUID()
{
$this->doc->topic = 'Un autre sujet';
Expand Down