src/Company/BaseBundle/Controller/IndexController.php
changeset 9 41a9fa70a47b
child 13 ed54c98a7fc8
equal deleted inserted replaced
8:062b0cefef7e 9:41a9fa70a47b
       
     1 <?php
       
     2 
       
     3 namespace Company\BaseBundle\Controller;
       
     4 
       
     5 use Company\BaseBundle\Entity\Document;
       
     6 use IRI\Bundle\WikiTagBundle\Entity\Document as BaseDocument;
       
     7 
       
     8 use Symfony\Component\HttpFoundation\Request;
       
     9 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
       
    10 
       
    11 
       
    12 class IndexController extends Controller
       
    13 {
       
    14     
       
    15     public function indexAction()
       
    16     {
       
    17         return $this->render('CompanyBaseBundle:Index:index.html.twig');
       
    18     }
       
    19     
       
    20     public function otherAction()
       
    21     {
       
    22         return $this->render('CompanyBaseBundle:Index:other_page.html.twig');
       
    23     }
       
    24     
       
    25     
       
    26     public function addDocumentAction(Request $request)
       
    27     {
       
    28         $doc = new Document();
       
    29         
       
    30         $form = $this->createFormBuilder($doc)
       
    31         ->add('title', 'text')
       
    32         ->add('description', 'textarea', array("required" => false,))
       
    33         ->getForm();
       
    34     
       
    35         if ($request->getMethod() == 'POST') {
       
    36             $form->bindRequest($request);
       
    37             if ($form->isValid()) {
       
    38                 $doc = $form->getData();
       
    39                 $em = $this->getDoctrine()->getEntityManager();
       
    40                 $em->persist($doc);
       
    41                 $em->flush();
       
    42                 return $this->redirect($this->generateUrl('all_documents'));
       
    43             }
       
    44         }
       
    45         else{
       
    46             return $this->render('CompanyBaseBundle:Index:add_document.html.twig', array('form' => $form->createView()));
       
    47         }
       
    48     }
       
    49     
       
    50     
       
    51     public function allDocumentsAction()
       
    52     {
       
    53         $rep_docs = $this->getDoctrine()->getRepository('CompanyBaseBundle:Document');
       
    54 	    $documents = $rep_docs->findAll();
       
    55 	    
       
    56         return $this->render('CompanyBaseBundle:Index:all_documents.html.twig', array('documents' => $documents));
       
    57     }
       
    58     
       
    59     
       
    60     public function allDocumentsPartialAction($param="")
       
    61     {
       
    62         $rep_docs = $this->getDoctrine()->getRepository('CompanyBaseBundle:Document');
       
    63 	    $documents = $rep_docs->findAll();
       
    64 	    
       
    65         return $this->render('CompanyBaseBundle:Index:all_documents_partial.html.twig', array('documents' => $documents, 'param' => $param));
       
    66     }
       
    67     
       
    68     /**
       
    69      * Template with tag management
       
    70      *
       
    71      */
       
    72     public function documentWithTagAction($idDoc)
       
    73     {
       
    74         $rep_docs = $this->getDoctrine()->getRepository('CompanyBaseBundle:Document');
       
    75     	$doc = $rep_docs->findOneById($idDoc);
       
    76         return $this->render('CompanyBaseBundle:Index:tag_embedder.html.twig', array('doc' => $doc));
       
    77     }
       
    78     
       
    79 }