310 public function removeWpLinkAction() |
310 public function removeWpLinkAction() |
311 { |
311 { |
312 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
312 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
313 $id_tag = $this->getRequest()->request->get('tag_id'); |
313 $id_tag = $this->getRequest()->request->get('tag_id'); |
314 $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
314 $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
315 //return new Response(var_dump(array($tag))); |
315 |
316 // We search if the unsemantized version of the tag already exist. |
|
317 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
|
318 $em = $this->getDoctrine()->getEntityManager(); |
316 $em = $this->getDoctrine()->getEntityManager(); |
319 $un_tag_created = FALSE; |
317 $query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)"); |
|
318 $query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized'])); |
|
319 $un_tag = null; |
|
320 $un_tags = $query->getResult(); |
|
321 if(count($un_tags)>0) { |
|
322 $un_tag = $un_tags[0]; |
|
323 } |
|
324 $un_tag_created = false; |
320 if(!$un_tag){ |
325 if(!$un_tag){ |
321 // Create another tag almost identical, without the W info |
326 // Create another tag almost identical, without the W info |
322 $un_tag = new Tag(); |
327 $un_tag = new Tag(); |
323 $un_tag->setLabel($tag->getLabel()); |
328 $un_tag->setLabel($tag->getLabel()); |
324 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
329 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
325 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
|
326 $un_tag->setWikipediaUrl(null); |
330 $un_tag->setWikipediaUrl(null); |
327 $un_tag->setWikipediaPageId(null); |
331 $un_tag->setWikipediaPageId(null); |
328 $un_tag->setAlternativeWikipediaUrl(null); |
332 $un_tag->setAlternativeWikipediaUrl(null); |
329 $un_tag->setAlternativeWikipediaPageId(null); |
333 $un_tag->setAlternativeWikipediaPageId(null); |
330 $un_tag->setAlternativeLabel(null); |
334 $un_tag->setAlternativeLabel(null); |
331 $un_tag->setDbpediaUri(null); |
335 $un_tag->setDbpediaUri(null); |
332 $un_tag->setCategory($tag->getCategory()); |
336 $un_tag->setCategory($tag->getCategory()); |
333 $un_tag->setAlias($tag->getAlias()); |
337 $un_tag->setAlias($tag->getAlias()); |
334 $un_tag->setPopularity($tag->getPopularity()); |
338 $un_tag->setPopularity($tag->getPopularity()); |
|
339 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']); |
|
340 $un_tag_created = true; |
335 $em->persist($un_tag); |
341 $em->persist($un_tag); |
|
342 } |
|
343 elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result']) |
|
344 { |
|
345 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']); |
336 $un_tag_created = true; |
346 $un_tag_created = true; |
337 } |
347 $em->persist($un_tag); |
|
348 } |
|
349 |
|
350 |
338 |
351 |
339 if($id_doc && $id_doc!=""){ |
352 if($id_doc && $id_doc!=""){ |
340 // We associate the unsemantized tag to the DocumentTag and save datas |
353 // We associate the unsemantized tag to the DocumentTag and save datas |
341 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
354 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
342 $dt->setTag($un_tag); |
355 $dt->setTag($un_tag); |
343 $em->flush(); |
356 $em->flush(); |
344 return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
357 return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
345 } |
358 } |
346 else{ |
359 else{ |
347 // Here we are in the context of tag list. |
360 // Here we are in the context of tag list. |
348 if($un_tag_created==TRUE){ |
361 if($un_tag_created==true){ |
349 $em->flush(); |
362 $em->flush(); |
350 $num_page = $this->getRequest()->request->get('num_page'); |
363 $num_page = $this->getRequest()->request->get('num_page'); |
351 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
364 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
352 $sort = $this->getRequest()->request->get('sort'); |
365 $sort = $this->getRequest()->request->get('sort'); |
353 $searched = $this->getRequest()->request->get('searched'); |
366 $searched = $this->getRequest()->request->get('searched'); |