--- a/Controller/WikiTagController.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Controller/WikiTagController.php Thu Dec 08 23:48:55 2011 +0100
@@ -312,17 +312,21 @@
$id_doc = $this->getRequest()->request->get('wikitag_document_id');
$id_tag = $this->getRequest()->request->get('tag_id');
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
- //return new Response(var_dump(array($tag)));
- // We search if the unsemantized version of the tag already exist.
- $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result']));
+
$em = $this->getDoctrine()->getEntityManager();
- $un_tag_created = FALSE;
+ $query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)");
+ $query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized']));
+ $un_tag = null;
+ $un_tags = $query->getResult();
+ if(count($un_tags)>0) {
+ $un_tag = $un_tags[0];
+ }
+ $un_tag_created = false;
if(!$un_tag){
// Create another tag almost identical, without the W info
$un_tag = new Tag();
$un_tag->setLabel($tag->getLabel());
$un_tag->setOriginalLabel($tag->getOriginalLabel());
- $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']);
$un_tag->setWikipediaUrl(null);
$un_tag->setWikipediaPageId(null);
$un_tag->setAlternativeWikipediaUrl(null);
@@ -332,9 +336,18 @@
$un_tag->setCategory($tag->getCategory());
$un_tag->setAlias($tag->getAlias());
$un_tag->setPopularity($tag->getPopularity());
- $em->persist($un_tag);
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
$un_tag_created = true;
+ $em->persist($un_tag);
}
+ elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result'])
+ {
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
+ $un_tag_created = true;
+ $em->persist($un_tag);
+ }
+
+
if($id_doc && $id_doc!=""){
// We associate the unsemantized tag to the DocumentTag and save datas
@@ -345,7 +358,7 @@
}
else{
// Here we are in the context of tag list.
- if($un_tag_created==TRUE){
+ 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');
@@ -533,7 +546,8 @@
$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.