3 namespace Rapsys\BlogBundle\Controller
; 
   5 use Rapsys\BlogBundle\Entity\Article
; 
   6 use Rapsys\BlogBundle\Entity\Keyword
; 
   7 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
; 
   9 class PageController 
extends \Symfony\Bundle\FrameworkBundle\Controller\Controller 
{ 
  10         /// Localized homepage 
  11         //TODO: rewrite with canonical ? 
  12         public function indexAction($_locale) { 
  14                 $articles = $this->getDoctrine()->getRepository(Article
::class)->findArticles($_locale); 
  17                 $title = $this->get('translator')->trans($this->getParameter('blog.welcome')); 
  20                 return $this->render('RapsysBlogBundle::index.html.twig', array('title' => $title, 'articles' => $articles)); 
  23         /// Legal informations 
  24         public function aboutAction() { 
  26                 $trans = $this->get('translator'); 
  29                 $title = $trans->trans('About').' - '.$trans->trans($this->getParameter('blog.title')); 
  32                 return $this->render('RapsysBlogBundle::page/about.html.twig', array('title' => $title)); 
  36         public function contactAction($_locale, \Symfony\Component\HttpFoundation\Request 
$request) { 
  38                 $trans = $this->get('translator'); 
  41                 $title = $trans->trans('Contact').' - '.$trans->trans($this->getParameter('blog.title')); 
  43                 //Create the form according to the FormType created previously. 
  44                 //And give the proper parameters 
  45                 $form = $this->createForm('Rapsys\BlogBundle\Form\ContactType', null, array( 
  46                         // To set the action use $this->generateUrl('route_identifier') 
  47                         'action' => $this->generateUrl('contact'), 
  51                 if ($request->isMethod('POST')) { 
  52                         // Refill the fields in case the form is not valid. 
  53                         $form->handleRequest($request); 
  55                         if ($form->isValid()) { 
  56                                 $data = $form->getData(); 
  57                                 $message = \Swift_Message
::newInstance() 
  58                                         ->setSubject($data['subject']) 
  59                                         ->setFrom(array($data['email'] => $data['name'])) 
  60                                         ->setTo(array($this->getParameter('blog.contact_mail') => $this->getParameter('blog.contact_name'))) 
  61                                         ->setBody($data['message']) 
  64                                                         'RapsysBlogBundle::mail/contact.html.twig', 
  66                                                                 'blog_logo' => file_get_contents($this->getParameter('blog.logo'), false, null), 
  67                                                                 'blog_title' => $this->getParameter('blog.title'), 
  68                                                                 'blog_url' => $this->get('router')->generate('homepage', array('_locale' => $_locale), UrlGeneratorInterface
::ABSOLUTE_URL
), 
  69                                                                 'subject' => $data['subject'], 
  70                                                                 'contact_name' => $this->getParameter('blog.contact_name'), 
  71                                                                 'message' => $data['message'] 
  77                                 if ($this->get('mailer')->send($message)) { 
  78                                         //Redirect to cleanup the form 
  79                                         return $this->redirectToRoute('contact', array('sent' => 1)); 
  85                 return $this->render('RapsysBlogBundle::page/contact.html.twig', array('title' => $title, 'form' => $form->createView(), 'sent' => $request->query
->get('sent', 0))); 
  89         public function articleIndexAction($_locale) { 
  91                 $articles = $this->getDoctrine()->getRepository(Article
::class)->findArticles($_locale); 
  94                 $trans = $this->get('translator'); 
  97                 $title = $trans->trans('Articles list').' - '.$trans->trans($this->getParameter('blog.title')); 
 100                 return $this->render('RapsysBlogBundle::article/index.html.twig', array('title' => $title, 'articles' => $articles)); 
 104         public function articleReadAction($_locale, $_article) { 
 105                 //Protect article fetching 
 107                         $article = $this->getDoctrine()->getRepository(Article
::class)->findArticle($_locale, $_article); 
 108                 //Catch no article case 
 109                 } catch (\Doctrine\ORM\NoResultException 
$e) { 
 111                         throw new \Symfony\Component\HttpKernel\Exception\
NotFoundHttpException('Not found!'); 
 115                 $title = $article['title'].' - '.$this->get('translator')->trans($this->getParameter('blog.title')); 
 118                 return $this->render('RapsysBlogBundle::article/read.html.twig', array('title' => $title, 'article' => $article)); 
 122         public function keywordIndexAction($_locale) { 
 123                 //Fetch keywords list 
 124                 $keywords = $this->getDoctrine()->getRepository(Keyword
::class)->findKeywords($_locale); 
 127                 $trans = $this->get('translator'); 
 130                 $title = $trans->trans('Keywords list').' - '.$trans->trans($this->getParameter('blog.title')); 
 133                 return $this->render('RapsysBlogBundle::keyword/index.html.twig', array('title' => $title, 'keywords' => $keywords)); 
 137         function keywordReadAction($_locale, $_keyword) { 
 138                 //Protect keyword fetching 
 140                         $keyword = $this->getDoctrine()->getRepository(Keyword
::class)->findKeyword($_locale, $_keyword); 
 141                 //Catch no keyword case 
 142                 } catch (\Doctrine\ORM\NoResultException 
$e) { 
 144                         throw new \Symfony\Component\HttpKernel\Exception\
NotFoundHttpException('Not found!'); 
 148                 $title = $keyword['title'].' - '.$this->get('translator')->trans($this->getParameter('blog.title')); 
 151                 return $this->render('RapsysBlogBundle::keyword/read.html.twig', array('title' => $title, 'keyword' => $keyword));