Example #1
0
 public function __construct(Post $entity)
 {
     $this->name = $entity->getName();
     $this->image = $entity->getImage();
     $this->intro = $entity->getIntro();
     $this->content = $entity->getContent();
     $this->status = $entity->getStatus();
     $this->tags = $entity->getTags();
 }
Example #2
0
 /**
  * @param Post $post
  * @param int  $limit
  * @return mixed
  */
 public function related(Post $post, $limit = 3)
 {
     /** @var \Doctrine\ORM\QueryBuilder $qb */
     $qb = $this->manager->getRepository('BlogBundle:Post')->createQueryBuilder('p');
     $qb->innerJoin('p.tags', 't');
     $tags = array();
     foreach ($post->getTags() as $tag) {
         $tags[] = $tag->getId();
     }
     if (!count($tags)) {
         return array();
     }
     $qb->where('p.status = 1');
     $qb->andWhere($qb->expr()->neq('p.id', $post->getId()));
     $qb->andWhere($qb->expr()->in('t.id', ':tags'));
     $qb->setParameter('tags', $tags);
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $this->items = $qb->getQuery()->getResult();
 }