264 $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
264 $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
265 //return new Response(var_dump(array($tag))); |
265 //return new Response(var_dump(array($tag))); |
266 // We search if the unsemantized version of the tag already exist. |
266 // We search if the unsemantized version of the tag already exist. |
267 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
267 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
268 $em = $this->getDoctrine()->getEntityManager(); |
268 $em = $this->getDoctrine()->getEntityManager(); |
|
269 $un_tag_created = FALSE; |
269 if(!$un_tag){ |
270 if(!$un_tag){ |
270 // Create another tag almost identical, without the W info |
271 // Create another tag almost identical, without the W info |
271 // TODO: use a factory that return a TagInterface |
272 // TODO: use a factory that return a TagInterface |
272 $un_tag = new Tag(); |
273 $un_tag = new Tag(); |
273 $un_tag->setLabel($tag->getLabel()); |
274 $un_tag->setLabel($tag->getLabel()); |
278 $un_tag->setDbpediaUri(null); |
279 $un_tag->setDbpediaUri(null); |
279 $un_tag->setCategory($tag->getCategory()); |
280 $un_tag->setCategory($tag->getCategory()); |
280 $un_tag->setAlias($tag->getAlias()); |
281 $un_tag->setAlias($tag->getAlias()); |
281 $un_tag->setPopularity($tag->getPopularity()); |
282 $un_tag->setPopularity($tag->getPopularity()); |
282 $em->persist($un_tag); |
283 $em->persist($un_tag); |
283 } |
284 $un_tag_created = TRUE; |
284 // We associate the unsemantized tag to the DocumentTag and save datas |
285 } |
285 // TODO: do the request on external id of document |
286 |
286 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag)); |
287 if($id_doc && $id_doc!=""){ |
287 $dt->setTag($un_tag); |
288 // We associate the unsemantized tag to the DocumentTag and save datas |
288 $em->flush(); |
289 // TODO: do the request on external id of document |
289 |
290 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag)); |
290 return $this->renderDocTags($id_doc); |
291 $dt->setTag($un_tag); |
|
292 $em->flush(); |
|
293 return $this->renderDocTags($id_doc); |
|
294 } |
|
295 else{ |
|
296 // Here we are in the context of tag list. |
|
297 if($un_tag_created==TRUE){ |
|
298 $em->flush(); |
|
299 $num_page = $this->getRequest()->request->get('num_page'); |
|
300 $nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
301 $sort = $this->getRequest()->request->get('sort'); |
|
302 $searched = $this->getRequest()->request->get('searched'); |
|
303 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
304 } |
|
305 else{ |
|
306 // The unsemantized version of the tag already exist, so we send an error. |
|
307 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("La version désémantisée du tag %s (%s) existe déjà.", $un_tag->getLabel(), $un_tag->getOriginalLabel()))),400); |
|
308 } |
|
309 } |
291 } |
310 } |
292 |
311 |
293 |
312 |
294 /** |
313 /** |
295 * |
314 * |