public function testEmbeddedTag() { $tag = new Tag(); $tag->setCod('tag'); $tag1 = new Tag(); $tag1->setCod('embeddedTag'); $this->dm->persist($tag); $this->dm->persist($tag1); $this->dm->flush(); $embeddedTag = new EmbeddedTag($tag); $embeddedTag->setCod('embeddedTag'); $this->dm->persist($embeddedTag); $this->dm->flush(); $this->assertTrue($embeddedTag->isDescendantOf($tag)); $this->assertFalse($embeddedTag->isDescendantOf($tag1)); }
/** * Contains tag * * The original string tag logic used in_array to check it. * This function uses doctrine2 arrayCollection contains function instead. * * @param Tag|EmbeddedTag $tagToCheck * @return boolean TRUE if this multimedia_object contained the specified tag, FALSE otherwise. */ public function containsTag($tagToCheck) { foreach ($this->tags as $tag) { if ($tag->getCod() == $tagToCheck->getCod()) { return true; } } return false; }
/** * Returns true if given node is descendant of tag * * @param EmbeddedTag|Tag $tag * * @return bool */ public function isDescendantOf($tag) { if ($tag->getCod() == $this->getCod()) { return false; } return substr($this->getPath(), 0, strlen($tag->getPath())) === $tag->getPath(); }