/**
  * Loads in some dummy articles with tags so we can test against it.
  *
  * Articles:
  *
  *  My 1 article => array(tag1, alltag)
  *  My 2 article => array(tag2, alltag)
  *  My 3 article => array(tag3, alltag)
  *  My 4 article => array(tag3)
  *
  *
  * @return void
  */
 private function loadFixtures()
 {
     $tagAll = $this->manager->loadOrCreateTag('alltag');
     $tags = array();
     $allArticles = array();
     for ($i = 1; $i <= 4; $i++) {
         $article = new Article();
         $article->setTitle('My ' . $i . ' article');
         $allArticles[] = $article;
         $this->em->persist($article);
         $tags[$i] = $this->manager->loadOrCreateTag('tag' . $i);
         $tags[$i]->setName('tag' . $i);
         if ($i != 4) {
             // give them their own tag and the all tag
             $this->manager->addTag($tags[$i], $article);
             $this->manager->addTag($tagAll, $article);
         } else {
             // does't get its own tag, but get's 3's tag
             $this->manager->addTag($tags[3], $article);
         }
     }
     $this->em->flush();
     // save the tagging after everything's been flushed
     foreach ($allArticles as $article) {
         $this->manager->saveTagging($article);
     }
 }
예제 #2
0
 protected function createTag($name)
 {
     $tag = parent::createTag($name);
     if (is_null($tag->getCreatedAt())) {
         $tag->setCreatedAt(new \DateTime());
     }
     if (is_null($tag->getUpdatedAt())) {
         $tag->setUpdatedAt(new \DateTime());
     }
     return $tag;
 }
예제 #3
0
 public function reverseTransform($tags)
 {
     return $this->tagManager->loadOrCreateTags($this->tagManager->splitTagNames($tags));
 }