375 } |
375 } |
376 else{ |
376 else{ |
377 // Here we are in the context of tag list. |
377 // Here we are in the context of tag list. |
378 if($un_tag_created==true){ |
378 if($un_tag_created==true){ |
379 $em->flush(); |
379 $em->flush(); |
380 $num_page = $this->getRequest()->request->get('num_page'); |
380 return $this->renderAllTags(); |
381 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
382 $sort = $this->getRequest()->request->get('sort'); |
|
383 $searched = $this->getRequest()->request->get('searched'); |
|
384 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
385 } |
381 } |
386 else{ |
382 else{ |
387 // The unsemantized version of the tag already exist, so we send an error. |
383 // The unsemantized version of the tag already exist, so we send an error. |
388 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("La version désémantisée du tag %s (%s) existe déjà.", $un_tag->getLabel(), $un_tag->getOriginalLabel()))),400); |
384 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("La version désémantisée du tag %s (%s) existe déjà.", $un_tag->getLabel(), $un_tag->getOriginalLabel()))),400); |
389 } |
385 } |
459 // In case we changed the alias from the document view |
451 // In case we changed the alias from the document view |
460 return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
452 return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
461 } |
453 } |
462 else{ |
454 else{ |
463 // In case we changed the alias from the tag list. |
455 // In case we changed the alias from the tag list. |
464 $num_page = $this->getRequest()->request->get('num_page'); |
456 return $this->renderAllTags(); |
465 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
466 $sort = $this->getRequest()->request->get('sort'); |
|
467 $searched = $this->getRequest()->request->get('searched'); |
|
468 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
469 } |
457 } |
470 } |
458 } |
471 |
459 |
472 /** |
460 /** |
473 * List all tags, with pagination and search. |
461 * List all tags, with pagination and search. |
553 } |
541 } |
554 catch (\Exception $e){ |
542 catch (\Exception $e){ |
555 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
543 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
556 } |
544 } |
557 // We render the tag list. |
545 // We render the tag list. |
558 $num_page = $this->getRequest()->request->get('num_page'); |
546 return $this->renderAllTags(); |
559 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
547 } |
560 $sort = $this->getRequest()->request->get('sort'); |
548 |
561 $searched = $this->getRequest()->request->get('searched'); |
549 |
562 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
550 /** |
563 } |
|
564 |
|
565 |
|
566 /** |
|
567 * |
|
568 * Resemantize the tag with its original label. Kind of undo if we changed the tag's label. |
551 * Resemantize the tag with its original label. Kind of undo if we changed the tag's label. |
569 * |
552 * |
570 */ |
553 */ |
571 public function resetWpInfoAction() |
554 public function resetWpInfoAction() |
572 { |
555 { |
579 catch (\Exception $e){ |
562 catch (\Exception $e){ |
580 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
563 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
581 } |
564 } |
582 |
565 |
583 // We render the tag list. |
566 // We render the tag list. |
584 $num_page = $this->getRequest()->request->get('num_page'); |
567 return $this->renderAllTags(); |
585 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
568 } |
586 $sort = $this->getRequest()->request->get('sort'); |
569 |
587 $searched = $this->getRequest()->request->get('searched'); |
570 /** |
588 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
571 * Redo a Wikipedia search |
589 } |
572 * @return \Symfony\Component\HttpFoundation\Response|\Symfony\Bundle\FrameworkBundle\Controller\Response |
|
573 */ |
|
574 public function relaunchWpSearchAction() |
|
575 { |
|
576 $id_tag = $this->getRequest()->request->get('tag_id'); |
|
577 $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_tag)); |
|
578 // We update the tag label and its wikipedia info with the original label. |
|
579 try { |
|
580 $this->updateTagWithNewLabel($tag, $tag->getLabel()); |
|
581 } |
|
582 catch (\Exception $e){ |
|
583 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
|
584 } |
|
585 |
|
586 // We render the tag list. |
|
587 return $this->renderAllTags(); |
|
588 } |
|
589 |
590 |
590 |
591 |
591 |
592 /** |
592 /** |
593 * Generic render partial template for tag list |
593 * Generic render partial template for tag list |
594 */ |
594 */ |
595 private function updateTagWithNewLabel($tag, $label) |
595 private function updateTagWithNewLabel($tag, $label) |
596 { |
596 { |
597 if($tag!=null && $label!=null){ |
597 if($tag!=null && $label!=null){ |
598 if($label!=$tag->getLabel()){ |
598 // We get the Wikipedia informations for the sent label |
599 // We get the Wikipedia informations for the sent label |
599 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
600 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
600 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
601 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
601 $tag->setWikipediaInfo($wp_response); |
602 $tag->setWikipediaInfo($wp_response); |
602 // Save datas. |
603 // Save datas. |
603 $em = $this->getDoctrine()->getEntityManager(); |
604 $em = $this->getDoctrine()->getEntityManager(); |
604 $em->persist($tag); |
605 $em->persist($tag); |
605 $em->flush(); |
606 $em->flush(); |
|
607 } |
|
608 } |
606 } |
609 } |
607 } |
610 |
608 |
611 |
609 |
612 /** |
610 /** |
613 * Generic render partial template for tag list |
611 * Generic render partial template for tag list |
614 */ |
612 */ |
615 public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
613 public function renderAllTags($num_page=null, $nb_by_page=null, $sort=null, $searched=null) |
616 { |
614 { |
617 |
615 if(is_null($num_page)) { |
|
616 $num_page = $this->getRequest()->request->get('num_page'); |
|
617 } |
|
618 if(is_null($nb_by_page)) { |
|
619 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
620 } |
|
621 if(is_null($sort)) { |
|
622 $sort = $this->getRequest()->request->get('sort'); |
|
623 } |
|
624 if(is_null($searched)) { |
|
625 $searched = $this->getRequest()->request->get('searched'); |
|
626 } |
618 //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
627 //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
619 $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
628 $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
620 $tags = $ar[0]; |
629 $tags = $ar[0]; |
621 $num_page = $ar[1]; |
630 $num_page = $ar[1]; |
622 $nb_by_page = $ar[2]; |
631 $nb_by_page = $ar[2]; |
626 |
635 |
627 return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
636 return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
628 array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, |
637 array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, |
629 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"))); |
638 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"))); |
630 } |
639 } |
631 |
|
632 |
640 |
633 /** |
641 /** |
634 * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) |
642 * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) |
635 */ |
643 */ |
636 private function getAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
644 private function getAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |