Controller/WikiTagController.php
changeset 68 e7384fb35f7a
parent 67 989d9e117586
child 74 901463f9b11c
child 76 bb7808e180c3
equal deleted inserted replaced
67:989d9e117586 68:e7384fb35f7a
   199             if($found==true){
   199             if($found==true){
   200                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   200                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   201             }
   201             }
   202             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   202             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   203             try {
   203             try {
   204                 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'));
   204                 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger'));
   205             }
   205             }
   206             catch (\Exception $e){
   206             catch (\Exception $e){
   207                 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
   207                 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
   208             }
   208             }
   209             $tag = $ar[0];
   209             $tag = $ar[0];
   250         
   250         
   251         $doc = $res->findOneByExternalId($id_doc);
   251         $doc = $res->findOneByExternalId($id_doc);
   252         $doc->setManualOrder(false);
   252         $doc->setManualOrder(false);
   253         $this->getDoctrine()->getEntityManager()->persist($doc);
   253         $this->getDoctrine()->getEntityManager()->persist($doc);
   254         
   254         
   255         $search_service = $this->get('wiki_tag.search');
   255         $doc_service = $this->get('wiki_tag.document')->reorderTags($doc);
   256         
       
   257         $search_service->reorderTagsForDocument($doc);
       
   258         
   256         
   259         $this->getDoctrine()->getEntityManager()->flush();
   257         $this->getDoctrine()->getEntityManager()->flush();
   260 
   258 
   261         return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
   259         return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
   262     }
   260     }
   561     private function updateTagWithNewLabel($tag, $label)
   559     private function updateTagWithNewLabel($tag, $label)
   562     {
   560     {
   563         if($tag!=null && $label!=null){
   561         if($tag!=null && $label!=null){
   564             // We get the Wikipedia informations for the sent label
   562             // We get the Wikipedia informations for the sent label
   565             $tag_label_normalized = WikiTagUtils::normalizeTag($label);
   563             $tag_label_normalized = WikiTagUtils::normalizeTag($label);
   566             $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized, null, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'));
   564             $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized, null, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger'));
   567             $tag->setWikipediaInfo($wp_response);
   565             $tag->setWikipediaInfo($wp_response);
   568             // Save datas.
   566             // Save datas.
   569             $em = $this->getDoctrine()->getEntityManager();
   567             $em = $this->getDoctrine()->getEntityManager();
   570             $em->persist($tag);
   568             $em->persist($tag);
   571             $em->flush();
   569             $em->flush();