Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
--- a/Controller/WikiTagController.php Thu Oct 27 22:22:36 2011 +0200
+++ b/Controller/WikiTagController.php Fri Oct 28 14:57:11 2011 +0200
@@ -47,7 +47,7 @@
* Renders the little html to add the javascript
* TODO: review why this injection in javascript, t10n?
*/
- public function addJavascriptAction()
+ public function addJavascriptAction($tags_list=FALSE)
{
$cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories();
// $cats is {"Label":"Créateur"},{"Label":"Datation"},...
@@ -59,7 +59,7 @@
}
// ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
$categories = json_encode($ar);
- return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories));
+ return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories,'tags_list' => $tags_list));
}
/**
@@ -133,8 +133,8 @@
}
/**
- *
- * TODO: Enter description here ...
+ * Modify the tag in the context of a tag list for one document
+ *
*/
public function modifyDocumentTagAction()
{
@@ -165,6 +165,7 @@
$tag = $ar[0];
$revision_id = $ar[1];
$created = $ar[2];
+
// We get the DocumentTag and change its tag
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag));
$dt->setTag($tag);
@@ -176,13 +177,15 @@
//if len(results) > 0:
// ts.index_note = results[0].score
//
+ // We set ManualOrder = true for the current document
+ $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('externalId' => $id_doc));
+ $doc->setManualOrder(true);
// We save the datas
- $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('id' => $id_doc));
- $doc->setManualOrder(true);
$em->flush();
+ // We render the document's tags
+ return $this->renderDocTags($id_doc);
}
- return $this->renderDocTags($id_doc);
}
/**
@@ -355,17 +358,6 @@
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc));
}
-
- /**
- *
- * TODO: Enter description here ...
- * TODO : implement
- */
- public function resetWpInfoAction()
- {
- $id_doc = $this->getRequest()->request->get('wikitag_document_id');
- return $this->renderDocTags($id_doc);
- }
/**
@@ -468,6 +460,80 @@
'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
}
+ /**
+ * Modify the tag in the context of all tags list.
+ */
+ public function modifyTagAction()
+ {
+ $tag_label = $this->getRequest()->request->get('value');
+ $id_moved_tag = $this->getRequest()->request->get('id');
+ $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
+ // We update the tag label and its wikipedia info with the new label.
+ $this->updateTagWithNewLabel($moved_tag, $tag_label);
+
+ // 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);
+ }
+
+ /**
+ *
+ * Resemantize the tag with its original label. Kind of undo if we changed the tag's label.
+ *
+ */
+ public function resetWpInfoAction()
+ {
+ $id_moved_tag = $this->getRequest()->request->get('tag_id');
+ $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
+ // We update the tag label and its wikipedia info with the original label.
+ $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
+
+ // 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);
+ }
+
+
+ /**
+ * Generic render partial template for tag list
+ */
+ 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);
+ $new_label = $wp_response['new_label'];
+ $status = $wp_response['status'];
+ $url = $wp_response['wikipedia_url'];
+ $pageid = $wp_response['pageid'];
+ $dbpedia_uri = $wp_response["dbpedia_uri"];
+ $wikipedia_revision_id = $wp_response['revision_id'];
+ // We save the datas : we DO NOT create a new tag, we change the current tag's informations
+ if($new_label!=null){
+ $tag->setLabel($new_label);
+ }
+ if($status!=null){
+ $tag->setUrlStatus($status);
+ }
+ $tag->setWikipediaUrl($url);
+ $tag->setWikipediaPageId($pageid);
+ $tag->setDbpediaUri($dbpedia_uri);
+ // Save datas.
+ $em = $this->getDoctrine()->getEntityManager();
+ $em->persist($tag);
+ $em->flush();
+ }
+ }
+ }
+
/**
* Generic render partial template for tag list
@@ -486,7 +552,7 @@
return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig',
array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page,
- 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => WikiTagController::$ROUTE_FOR_DOCUMENTS_BY_TAG));
+ 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
return $this->getAllTags();
}
--- a/Resources/config/routing.yml Thu Oct 27 22:22:36 2011 +0200
+++ b/Resources/config/routing.yml Fri Oct 28 14:57:11 2011 +0200
@@ -16,6 +16,9 @@
wikitag_modify_documenttag:
pattern: /wtmdt
defaults: { _controller: WikiTagBundle:WikiTag:modifyDocumentTag }
+wikitag_modify_tag_in_list:
+ pattern: /wtmtl
+ defaults: { _controller: WikiTagBundle:WikiTag:modifyTag }
wikitag_reset_wp_info:
pattern: /wtrwi
defaults: { _controller: WikiTagBundle:WikiTag:resetWpInfo }
--- a/Resources/views/WikiTag/javascript.html.twig Thu Oct 27 22:22:36 2011 +0200
+++ b/Resources/views/WikiTag/javascript.html.twig Fri Oct 28 14:57:11 2011 +0200
@@ -13,7 +13,11 @@
var static_url = "{{ asset('bundles/wikitag/') }}";
var tag_up_down_url = "{{ url('wikitag_tag_up_down') }}";
var remove_tag_from_list_url = "{{ url('wikitag_remove_tag_from_list') }}";
+ {% if tags_list==true %}
+ var modify_tag_url = "{{ url('wikitag_modify_tag_in_list') }}";
+ {% else %}
var modify_tag_url = "{{ url('wikitag_modify_documenttag') }}";
+ {% endif %}
var reset_wp_info_url = "{{ url('wikitag_reset_wp_info') }}";
var reorder_tag_datasheet_url = "{{ url('wikitag_reorder_tag_document') }}";
var add_tag_url = "{{ url('wikitag_add_tag') }}";
--- a/Utils/WikiTagUtils.php Thu Oct 27 22:22:36 2011 +0200
+++ b/Utils/WikiTagUtils.php Fri Oct 28 14:57:11 2011 +0200
@@ -112,7 +112,7 @@
* @param unknown_type $page_id
* @return multitype:NULL unknown |multitype:Ambigous <NULL, unknown> multitype:number mixed Ambigous <NULL, string> Ambigous <unknown, mixed>
*/
- private static function getWikipediaInfo($tag_label_normalized, $page_id=null)
+ public static function getWikipediaInfo($tag_label_normalized, $page_id=null)
{
$params = array('action'=>'query', 'prop'=>'info|categories|langlinks', 'inprop'=>'url', 'lllimit'=>'500', 'cllimit'=>'500', 'rvprop'=>'ids', 'format'=>'json');
if($tag_label_normalized!=null){