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