Ejemplo n.º 1
0
 /**
  * @param Post $post
  */
 public function publish(Post $post)
 {
     $post->setStatus(PostStatus::PUBLISHED);
     $post->setPublishedAt(new DateTime());
     $this->em->persist($post);
     $this->em->flush();
 }
Ejemplo n.º 2
0
 /**
  *
  * @param Post $post
  * @param int  $limit
  * @param  int $limit
  * @return array
  */
 public function related(Post $post, $limit = 3)
 {
     $this->sphinx->SetMatchMode(SPH_MATCH_ANY);
     $this->sphinx->SetLimits(0, $limit);
     $ids = $this->sphinxSearch($post->getTagsAsString());
     if (!$ids) {
         return array();
     }
     $items = $this->em->getRepository('BlogBundle:Post')->getByIds($ids);
     $this->items = $this->orderResults($ids, $items);
     return $this->items;
 }
Ejemplo n.º 3
0
 protected function createPost()
 {
     $date = new \DateTime();
     $post = new Post();
     $name = $this->faker->name;
     $post->setName($name);
     $post->setSlug(md5($name));
     $post->setIntro($this->faker->text);
     $post->setContent($this->faker->text);
     $post->setStatus(PostStatus::PUBLISHED);
     $post->setCreatedAt($date);
     $post->setUpdatedAt($date);
     return $post;
 }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 /**
  * Add posts
  *
  * @param  Desarrolla2\Bundle\BlogBundle\Entity\Post $post
  * @return Tag
  */
 public function addPost(\Desarrolla2\Bundle\BlogBundle\Entity\Post $post)
 {
     $post->addTag($this);
     $this->posts[] = $posts;
 }
Ejemplo n.º 7
0
 /**
  * Set post
  *
  * @param  \Desarrolla2\Bundle\BlogBundle\Entity\Post $post
  * @return PostHistory
  */
 public function setPost(\Desarrolla2\Bundle\BlogBundle\Entity\Post $post = null)
 {
     $this->post = $post;
     $this->setName($post->getName());
     $this->setIntro($post->getIntro());
     $this->setContent($post->getContent());
     return $this;
 }