Controller/WikiTagController.php
changeset 35 92ddb5488eb4
parent 34 21fab44f46fe
parent 33 6c87166b819c
child 36 540607cf3447
equal deleted inserted replaced
34:21fab44f46fe 35:92ddb5488eb4
    57             $temp = array($cats[$i]["label"] => $cats[$i]["label"]);
    57             $temp = array($cats[$i]["label"] => $cats[$i]["label"]);
    58             $ar = array_merge($ar, $temp);
    58             $ar = array_merge($ar, $temp);
    59         }
    59         }
    60         // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
    60         // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
    61         $categories = json_encode($ar);
    61         $categories = json_encode($ar);
    62         return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories,'tags_list' => $tags_list));
    62         return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list));
       
    63     }
       
    64 
       
    65     /**
       
    66      * Renders the little html to add the javascript for context search
       
    67      */
       
    68     public function addJavascriptForContextSearchAction($context_name)
       
    69     {
       
    70         // WARNING : PREREQUISITE : the request to add a tag needs the external document id,
       
    71         // which is gotten by the jQuery call $('#wikitag_document_id').val() in the page.
       
    72         // So the page holding this context search MUST have a input value with this id.
       
    73         // We add the reactive selectors
       
    74         $reactive_selectors = $this->container->getParameter("wiki_tag.reactive_selectors");
       
    75         return $this->render('WikiTagBundle:WikiTag:javascriptForContextSearch.html.twig', array('reactive_selectors' => $reactive_selectors));
    63     }
    76     }
    64 
    77 
    65     /**
    78     /**
    66      * Display a list of ordered tag for a document
    79      * Display a list of ordered tag for a document
    67      * @param integer $id_doc
    80      * @param integer $id_doc
   149             $nb_tags = count($tags);
   162             $nb_tags = count($tags);
   150             $found = false;
   163             $found = false;
   151             $i = 0;
   164             $i = 0;
   152             while($i<$nb_tags && $found==false){
   165             while($i<$nb_tags && $found==false){
   153                 $dt = $tags[$i];
   166                 $dt = $tags[$i];
   154                 if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){
   167                 if($dt->getTag()->getLabel()==$tag_label){
   155                     $found = true;
   168                     $found = true;
   156                 }
   169                 }
   157                 $i++;
   170                 $i++;
   158             }
   171             }
   159             // If the label was found, we sent a bad request
   172             // If the label was found, we sent a bad request
   160             if($found==true){
   173             if($found==true){
   161                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   174                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   162             }
   175             }
   163             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   176             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   164             $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label)
   177             $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());
   165             $tag = $ar[0];
   178             $tag = $ar[0];
   166             $revision_id = $ar[1];
   179             $revision_id = $ar[1];
   167             $created = $ar[2];
   180             $created = $ar[2];
   168             
   181             
   169             // We get the DocumentTag and change its tag
   182             // We get the DocumentTag and change its tag
   186             // We set ManualOrder = true for the current document
   199             // We set ManualOrder = true for the current document
   187             $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('externalId' => $id_doc));
   200             $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('externalId' => $id_doc));
   188             $doc->setManualOrder(true);
   201             $doc->setManualOrder(true);
   189             // We save the datas
   202             // We save the datas
   190             $em->flush();
   203             $em->flush();
   191             // We render the document's tags
   204         }
   192             return $this->renderDocTags($id_doc);
   205         // We render the document's tags
   193         }
   206         return $this->renderDocTags($id_doc);
   194 
   207 
   195     }
   208     }
   196 
   209 
   197     /**
   210     /**
   198      *
   211      *