--- a/Controller/WikiTagController.php Mon Oct 24 19:08:04 2011 +0200
+++ b/Controller/WikiTagController.php Tue Oct 25 12:20:47 2011 +0200
@@ -266,6 +266,7 @@
// 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;
if(!$un_tag){
// Create another tag almost identical, without the W info
// TODO: use a factory that return a TagInterface
@@ -280,14 +281,32 @@
$un_tag->setAlias($tag->getAlias());
$un_tag->setPopularity($tag->getPopularity());
$em->persist($un_tag);
+ $un_tag_created = TRUE;
}
- // We associate the unsemantized tag to the DocumentTag and save datas
- // TODO: do the request on external id of document
- $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag));
- $dt->setTag($un_tag);
- $em->flush();
- return $this->renderDocTags($id_doc);
+ if($id_doc && $id_doc!=""){
+ // We associate the unsemantized tag to the DocumentTag and save datas
+ // TODO: do the request on external id of document
+ $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag));
+ $dt->setTag($un_tag);
+ $em->flush();
+ return $this->renderDocTags($id_doc);
+ }
+ else{
+ // Here we are in the context of tag list.
+ 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');
+ $sort = $this->getRequest()->request->get('sort');
+ $searched = $this->getRequest()->request->get('searched');
+ return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
+ }
+ else{
+ // The unsemantized version of the tag already exist, so we send an error.
+ 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);
+ }
+ }
}