/**
  * getNext
  * Get the article just after the given one (chronologically)
  * @param \Gore\BlogBundle\Entity\Article $article
  * @return type
  */
 public function getNext(Article $article)
 {
     $qb = $this->createQueryBuilder('a')->where('a.published = true')->andWhere('a.date > :givendate')->orderBy('a.date', 'ASC')->setParameter('givendate', $article->getDate())->setFirstResult(0)->setMaxResults(1);
     return $qb->getQuery()->getOneOrNullResult();
 }
Esempio n. 2
0
 /**
  * fillPrepersistArticle
  * Fill default fields of an article like author
  * @param \Gore\BlogBundle\Entity\Article $article
  * @return \Gore\BlogBundle\Entity\Article
  */
 public function fillPrepersistArticle(Article $article)
 {
     $article->setAuthor($this->container->get('security.context')->getToken()->getUser());
     return $article;
 }
 /**
  * toggleArticleAction
  * Change the "published" attribute of the article
  * @param \Gore\BlogBundle\Entity\Article $article
  * @return type
  */
 public function toggleArticleAction(Article $article)
 {
     if ($article) {
         $em = $this->getDoctrine()->getManager();
         $newpub = $article->getPublished() == true ? false : true;
         $article->setPublished($newpub);
         $em->persist($article);
         $em->flush();
         $status = $newpub == true ? "ONLINE" : "OFFLINE";
         $message = 'The article "' . $article->getTitle() . '" has been successfully put ' . $status . '.';
         $this->get('session')->getFlashBag()->add('notice', $message);
         return $this->redirect($this->generateUrl('gore_blog_admin_manage_articles'));
     } else {
         // If article couldn't be loaded
         $this->get('session')->getFlashBag()->add('error', 'Sorry, impossible to toggle the article.');
     }
     return $this->redirect($this->generateUrl('gore_blog_admin_manage_articles'));
 }