--- a/Controller/WikiTagController.php Fri Dec 09 02:27:20 2011 +0100
+++ b/Controller/WikiTagController.php Fri Dec 09 04:53:56 2011 +0100
@@ -377,11 +377,7 @@
// Here we are in the context of tag list.
if($un_tag_created==true){
$em->flush();
- $num_page = $this->getRequest()->request->get('num_page');
- $nb_by_page = $this->getRequest()->request->get('nb_by_page');
- $sort = $this->getRequest()->request->get('sort');
- $searched = $this->getRequest()->request->get('searched');
- return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ return $this->renderAllTags();
}
else{
// The unsemantized version of the tag already exist, so we send an error.
@@ -417,11 +413,7 @@
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
}
else{
- $num_page = $this->getRequest()->request->get('num_page');
- $nb_by_page = $this->getRequest()->request->get('nb_by_page');
- $sort = $this->getRequest()->request->get('sort');
- $searched = $this->getRequest()->request->get('searched');
- return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ return $this->renderAllTags();
}
}
@@ -461,11 +453,7 @@
}
else{
// In case we changed the alias from the tag list.
- $num_page = $this->getRequest()->request->get('num_page');
- $nb_by_page = $this->getRequest()->request->get('nb_by_page');
- $sort = $this->getRequest()->request->get('sort');
- $searched = $this->getRequest()->request->get('searched');
- return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ return $this->renderAllTags();
}
}
@@ -555,16 +543,11 @@
return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
}
// We render the tag list.
- $num_page = $this->getRequest()->request->get('num_page');
- $nb_by_page = $this->getRequest()->request->get('nb_by_page');
- $sort = $this->getRequest()->request->get('sort');
- $searched = $this->getRequest()->request->get('searched');
- return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ return $this->renderAllTags();
}
/**
- *
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label.
*
*/
@@ -581,12 +564,29 @@
}
// We render the tag list.
- $num_page = $this->getRequest()->request->get('num_page');
- $nb_by_page = $this->getRequest()->request->get('nb_by_page');
- $sort = $this->getRequest()->request->get('sort');
- $searched = $this->getRequest()->request->get('searched');
- return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ return $this->renderAllTags();
}
+
+ /**
+ * Redo a Wikipedia search
+ * @return \Symfony\Component\HttpFoundation\Response|\Symfony\Bundle\FrameworkBundle\Controller\Response
+ */
+ public function relaunchWpSearchAction()
+ {
+ $id_tag = $this->getRequest()->request->get('tag_id');
+ $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_tag));
+ // We update the tag label and its wikipedia info with the original label.
+ try {
+ $this->updateTagWithNewLabel($tag, $tag->getLabel());
+ }
+ catch (\Exception $e){
+ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
+ }
+
+ // We render the tag list.
+ return $this->renderAllTags();
+ }
+
/**
@@ -595,16 +595,14 @@
private function updateTagWithNewLabel($tag, $label)
{
if($tag!=null && $label!=null){
- if($label!=$tag->getLabel()){
- // We get the Wikipedia informations for the sent label
- $tag_label_normalized = WikiTagUtils::normalizeTag($label);
- $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
- $tag->setWikipediaInfo($wp_response);
- // Save datas.
- $em = $this->getDoctrine()->getEntityManager();
- $em->persist($tag);
- $em->flush();
- }
+ // We get the Wikipedia informations for the sent label
+ $tag_label_normalized = WikiTagUtils::normalizeTag($label);
+ $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ $tag->setWikipediaInfo($wp_response);
+ // Save datas.
+ $em = $this->getDoctrine()->getEntityManager();
+ $em->persist($tag);
+ $em->flush();
}
}
@@ -612,9 +610,20 @@
/**
* Generic render partial template for tag list
*/
- public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL)
+ public function renderAllTags($num_page=null, $nb_by_page=null, $sort=null, $searched=null)
{
-
+ if(is_null($num_page)) {
+ $num_page = $this->getRequest()->request->get('num_page');
+ }
+ if(is_null($nb_by_page)) {
+ $nb_by_page = $this->getRequest()->request->get('nb_by_page');
+ }
+ if(is_null($sort)) {
+ $sort = $this->getRequest()->request->get('sort');
+ }
+ if(is_null($searched)) {
+ $searched = $this->getRequest()->request->get('searched');
+ }
//We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta);
$ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched);
$tags = $ar[0];
@@ -629,7 +638,6 @@
'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
}
-
/**
* Generic to get all tags with the context (pagination number, nb by page, searched string, sort)
*/