diff -r 780ef37e63b9 -r 99c15cfe420b Controller/WikiTagController.php --- 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(); }