Controller/WikiTagController.php
changeset 5 45378793512a
parent 2 13f43f53d0ba
child 7 7a877de630fd
equal deleted inserted replaced
4:e63ac93fdbde 5:45378793512a
   216     {
   216     {
   217         $id_doc = $this->getRequest()->request->get('wikitag_document_id');
   217         $id_doc = $this->getRequest()->request->get('wikitag_document_id');
   218         $tag_label = $this->getRequest()->request->get('value');
   218         $tag_label = $this->getRequest()->request->get('value');
   219         // We get the DocumentTags
   219         // We get the DocumentTags
   220         $em = $this->getDoctrine()->getEntityManager();
   220         $em = $this->getDoctrine()->getEntityManager();
   221         $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc));
   221         $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc);
   222         $nb_tags = count($tags);
   222         $nb_tags = count($tags);
   223         $found = false;
   223         $found = false;
   224         $i = 0;
   224         $i = 0;
   225         while($i<$nb_tags && $found==false){
   225         while($i<$nb_tags && $found==false){
   226             $dt = $tags[$i];
   226             $dt = $tags[$i];
   239 
   239 
   240         $tag = $ar[0];
   240         $tag = $ar[0];
   241         $revision_id = $ar[1];
   241         $revision_id = $ar[1];
   242         $created = $ar[2];
   242         $created = $ar[2];
   243 
   243 
   244         $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc, 'tag'=>$tag->getId()));
   244         $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId()));
   245         $nb_tags = count($tags);
   245         $nb_tags = count($tags);
   246 
   246 
   247         if($created==true || $nb_tags==0){
   247         if($created==true || $nb_tags==0){
   248             $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc);
   248             $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc);
   249             // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned.
   249             // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned.
   250             $a1 = reset($new_order_ar);
   250             $a1 = reset($new_order_ar);
   251             $new_order = intval(reset($a1)) + 1;
   251             $new_order = intval(reset($a1)) + 1;
   252             // TODO: use a factory that returns an DocumentTagInterface
   252             // TODO: use a factory that returns an DocumentTagInterface
   253             $new_DT = new DocumentTag();
   253             $new_DT = new DocumentTag();
   254             //return new Response(var_dump($this->getDoctrine()->getRepository('WikiTagBundle:WikiTagDocument')->findOneBy(array('id' => $idDoc))));
   254             $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc));
   255             $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('id' => $id_doc)));
       
   256             $new_DT->setTag($tag);
   255             $new_DT->setTag($tag);
   257             $new_DT->setOriginalOrder($new_order);
   256             $new_DT->setOriginalOrder($new_order);
   258             $new_DT->setTagOrder($new_order);
   257             $new_DT->setTagOrder($new_order);
   259             $new_DT->setWikipediaRevisionId($revision_id);
   258             $new_DT->setWikipediaRevisionId($revision_id);
   260             $em->persist($new_DT);
   259             $em->persist($new_DT);
   293             $un_tag->setAlias($tag->getAlias());
   292             $un_tag->setAlias($tag->getAlias());
   294             $un_tag->setPopularity($tag->getPopularity());
   293             $un_tag->setPopularity($tag->getPopularity());
   295             $em->persist($un_tag);
   294             $em->persist($un_tag);
   296         }
   295         }
   297         // We associate the unsemantized tag to the DocumentTag and save datas
   296         // We associate the unsemantized tag to the DocumentTag and save datas
   298         $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $idDoc, 'tag' => $idTag));
   297         // TODO: do the request on external id of document
       
   298         $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $idTag));
   299         $dt->setTag($un_tag);
   299         $dt->setTag($un_tag);
   300         $em->flush();
   300         $em->flush();
   301         
   301         
   302         return $this->renderDocTags($id_doc);
   302         return $this->renderDocTags($id_doc);
   303     }
   303     }
   304 
   304 
   305 
   305 
   306     /**
   306     /**
   307      *
   307      *
   308      * TODO : Enter description here ...
   308      * TODO : Enter description here ...
       
   309      * TODO : implement
   309      * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
   310      * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
   310      */
   311      */
   311     public function updateTagAliasAction()
   312     public function updateTagAliasAction()
   312     {
   313     {
   313         $id_doc = $this->getRequest()->request->get('wikitag_document_id');
   314         $id_doc = $this->getRequest()->request->get('wikitag_document_id');