213 // If the label was found, we sent a bad request |
213 // If the label was found, we sent a bad request |
214 if($found==true){ |
214 if($found==true){ |
215 //TODO : translation |
215 //TODO : translation |
216 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
216 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
217 } |
217 } |
218 // $tag, $revision_id, $created |
218 // returns array($tag, $revision_id, $created) |
219 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
219 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
220 |
|
221 $tag = $ar[0]; |
220 $tag = $ar[0]; |
222 $revision_id = $ar[1]; |
221 $revision_id = $ar[1]; |
223 $created = $ar[2]; |
222 $created = $ar[2]; |
224 |
223 |
225 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
224 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
226 $nb_tags = count($tags); |
225 $nb_tags = count($tags); |
227 |
226 |
228 if($created==true || $nb_tags==0){ |
227 if($created==true || $nb_tags==0){ |
229 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
228 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
274 $un_tag->setPopularity($tag->getPopularity()); |
273 $un_tag->setPopularity($tag->getPopularity()); |
275 $em->persist($un_tag); |
274 $em->persist($un_tag); |
276 } |
275 } |
277 // We associate the unsemantized tag to the DocumentTag and save datas |
276 // We associate the unsemantized tag to the DocumentTag and save datas |
278 // TODO: do the request on external id of document |
277 // TODO: do the request on external id of document |
279 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $idTag)); |
278 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag)); |
280 $dt->setTag($un_tag); |
279 $dt->setTag($un_tag); |
281 $em->flush(); |
280 $em->flush(); |
282 |
281 |
283 return $this->renderDocTags($id_doc); |
282 return $this->renderDocTags($id_doc); |
284 } |
283 } |
350 * List of all tags |
349 * List of all tags |
351 * TODO: Enter description here ... |
350 * TODO: Enter description here ... |
352 */ |
351 */ |
353 public function allTagsAction() |
352 public function allTagsAction() |
354 { |
353 { |
355 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:WikiTagTag')->findAll(); |
354 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('id' => '10')); |
356 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
355 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
357 $toto = null; |
356 $toto = null; |
358 if(array_key_exists('toto', $_GET)){ |
357 if(array_key_exists('toto', $_GET)){ |
359 $toto = $_GET['toto']; |
358 $toto = $_GET['toto']; |
360 } |
359 } |
361 return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', array('tags' => $tags, 'toto' => $toto)); |
360 $searched = "truc"; |
|
361 $search_def = array('A', 'B'); |
|
362 $nb_by_page = 50; |
|
363 $sort = "p+"; |
|
364 $current_page = NULL;// avec start_index et end_index |
|
365 $nb_total = "truc";// nb de pages |
|
366 $num_page = 2; |
|
367 $last_page = 4; |
|
368 $prev_page = 1; |
|
369 $next_page = 3; |
|
370 return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
|
371 array('tags' => $tags, 'searched' => $searched, '$search_def' => $search_def, '$nb_by_page' => $nb_by_page, '$sort' => $sort, '$current_page' => $current_page, |
|
372 '$nb_total' => $nb_total, '$num_page' => $num_page, '$last_page' => $last_page, '$prev_page' => $prev_page, '$next_page' => $next_page)); |
362 } |
373 } |
363 |
374 |
364 |
375 |
365 } |
376 } |