Advertisement
Guest User

TextController

a guest
Nov 18th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Acme\AdminBundle\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Acme\EntityBundle\Entity\Text;
  7. use Acme\AdminBundle\Form\Type\TextType;
  8. use Acme\EntityBundle\Entity\Translation\TextTranslation;
  9. use Symfony\Component\HttpFoundation\Request;
  10.  
  11. class TextController extends Controller
  12. {
  13.     public function showAllAction()
  14.     {
  15.        $request = $this->getRequest();
  16.  
  17. $locale = $request->getLocale();
  18. echo $locale;
  19.  
  20.         $repository = $this->getDoctrine()
  21.         ->getRepository('AcmeEntityBundle:Text');
  22.  
  23.         $query = $repository->createQueryBuilder('m')
  24.         ->orderBy('m.id', 'DESC')
  25.         ->getQuery();
  26.  
  27.         $texts = $query->getResult();
  28.        
  29.  
  30.  
  31.         if (!$texts) {
  32.             throw $this->createNotFoundException(
  33.                 'Nebyly nalezeny žádné články'
  34.             );
  35.         }
  36.        
  37.         return $this->render('AcmeAdminBundle:Text:showAll.html.php', array('texts' => $texts));
  38.     }
  39.    
  40.    
  41.     public function addTextAction(Request $request)
  42.     {
  43.                
  44.     $text = new Text();
  45.     $text->setTitle('');
  46.     $text->setContent('');
  47.  
  48.     $form = $this->createForm(new TextType(), $text);
  49.    
  50.     $form->handleRequest($request);
  51.    
  52.     if ($form->isValid()) {
  53.    
  54.     /* nastaveni autora */
  55.     $text->setAuthor($this->getUser()->getId());    
  56.  
  57.    
  58.     $em = $this->getDoctrine()->getManager();
  59.     $em->persist($text);
  60.     $em->flush();
  61.  
  62.    
  63.               $this->get('session')->getFlashBag()->add(
  64.             'adminMessage', 'Text byl úspěšně přidán');
  65.              
  66.         return $this->redirect($this->generateUrl('acme_admin_text'));
  67.        
  68.     }
  69.    return $this->render('AcmeAdminBundle:Text:add.html.php', array(
  70.             'form' => $form->createView(),
  71.         ));
  72.    
  73.     }
  74.    
  75.     public function addTranslateAction($textId)
  76.     {
  77.        
  78.         $text = $this->getDoctrine()
  79.         ->getRepository('AcmeEntityBundle:Text')
  80.         ->find($textId);
  81.  
  82.         $text->addTranslation(new TextTranslation('lt', 'title', 'Smt title lt'));
  83.         $text->addTranslation(new TextTranslation('lt', 'content', 'Smth Content lt'));
  84.        
  85.         $em = $this->getDoctrine()->getManager();
  86.         $em->persist($text);
  87.         $em->flush();
  88.        
  89.         return $this->redirect($this->generateUrl('acme_admin_text'));
  90.        
  91.      }
  92.    
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement