Example #1
0
 /**
  *
  * @param  \Desarrolla2\Bundle\BlogBundle\Entity\Tag $tag
  * @return \Doctrine\ORM\Query
  */
 public function getQueryForGetByTag(Tag $tag)
 {
     $em = $this->getEntityManager();
     $query = $em->createQuery(' SELECT p FROM BlogBundle:Post p ' . ' JOIN p.tags t ' . ' WHERE p.status = ' . PostStatus::PUBLISHED . ' AND t.slug  = :slug ' . ' ORDER BY p.publishedAt DESC ')->setParameter('slug', $tag->getSlug());
     return $query;
 }
Example #2
0
 /**
  *
  * @param  string                                    $tagName
  * @return \Desarrolla2\Bundle\BlogBundle\Entity\Tag
  */
 public function getOrCreateByName($tagName)
 {
     $em = $this->getEntityManager();
     $tag = $this->getOneByName($tagName);
     if (!$tag) {
         $name = strtolower($tagName);
         $tag = new Tag();
         $tag->setName($name);
         $em->persist($tag);
         $em->flush();
     }
     return $tag;
 }
Example #3
0
 public function __construct(Tag $entity)
 {
     $this->name = $entity->getName();
 }