94 return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
94 return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
95 } |
95 } |
96 |
96 |
97 /** |
97 /** |
98 * |
98 * |
99 * TODO : Enter description here ... |
99 * The action called when a tag is moved in a document tag list. |
|
100 * |
100 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
101 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
101 */ |
102 */ |
102 public function tagUpDownAction() |
103 public function tagUpDownAction() |
103 { |
104 { |
104 |
105 |
183 // If the label was found, we sent a bad request |
184 // If the label was found, we sent a bad request |
184 if($found==true){ |
185 if($found==true){ |
185 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
186 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
186 } |
187 } |
187 // We create the new tag or get the already existing tag. $tag, $revision_id, $created |
188 // We create the new tag or get the already existing tag. $tag, $revision_id, $created |
188 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine()); |
189 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label); |
189 $tag = $ar[0]; |
190 $tag = $ar[0]; |
190 $revision_id = $ar[1]; |
191 $revision_id = $ar[1]; |
191 $created = $ar[2]; |
192 $created = $ar[2]; |
192 |
193 |
193 // We get the DocumentTag and change its tag |
194 // We get the DocumentTag and change its tag |
218 return $this->renderDocTags($id_doc); |
219 return $this->renderDocTags($id_doc); |
219 |
220 |
220 } |
221 } |
221 |
222 |
222 /** |
223 /** |
223 * |
224 * The action called to reorder the the tags of a document. The tags are reordered according to the indexation score of the tag label on the document. |
224 * TODO : Enter description here ... |
225 * The fields taken into account for calculating the score are defined in the wikitag configuration. |
225 * TODO : implement |
|
226 */ |
226 */ |
227 public function reorderTagDocumentAction() |
227 public function reorderTagDocumentAction() |
228 { |
228 { |
229 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
229 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
230 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
230 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
241 |
241 |
242 return $this->renderDocTags($id_doc); |
242 return $this->renderDocTags($id_doc); |
243 } |
243 } |
244 |
244 |
245 /** |
245 /** |
246 * |
246 * The action called to add a new tag (especially from the completion box) |
247 * TODO: Enter description here ... |
|
248 */ |
247 */ |
249 public function addTagAction() |
248 public function addTagAction() |
250 { |
249 { |
251 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
250 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
252 $tag_label = $this->getRequest()->request->get('value'); |
251 $tag_label = $this->getRequest()->request->get('value'); |
267 if($found==true){ |
266 if($found==true){ |
268 //TODO : translation |
267 //TODO : translation |
269 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
268 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
270 } |
269 } |
271 // returns array($tag, $revision_id, $created) |
270 // returns array($tag, $revision_id, $created) |
272 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
271 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);// tag, revision_id, created = get_or_create_tag(tag_label) |
273 $tag = $ar[0]; |
272 $tag = $ar[0]; |
274 $revision_id = $ar[1]; |
273 $revision_id = $ar[1]; |
275 $created = $ar[2]; |
274 $created = $ar[2]; |
276 |
275 |
277 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
276 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
549 if($tag!=null && $label!=null){ |
548 if($tag!=null && $label!=null){ |
550 if($label!=$tag->getLabel()){ |
549 if($label!=$tag->getLabel()){ |
551 // We get the Wikipedia informations for the sent label |
550 // We get the Wikipedia informations for the sent label |
552 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
551 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
553 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
552 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
554 $new_label = $wp_response['new_label']; |
553 |
555 $status = $wp_response['status']; |
554 $tag->setWikipediaInfo($wp_response); |
556 $url = $wp_response['wikipedia_url']; |
555 |
557 $pageid = $wp_response['pageid']; |
|
558 $dbpedia_uri = $wp_response["dbpedia_uri"]; |
|
559 $wikipedia_revision_id = $wp_response['revision_id']; |
|
560 // We save the datas : we DO NOT create a new tag, we change the current tag's informations |
|
561 if($new_label!=null){ |
|
562 $tag->setLabel($new_label); |
|
563 } |
|
564 if($status!=null){ |
|
565 $tag->setUrlStatus($status); |
|
566 } |
|
567 $tag->setWikipediaUrl($url); |
|
568 $tag->setWikipediaPageId($pageid); |
|
569 $tag->setDbpediaUri($dbpedia_uri); |
|
570 // Save datas. |
556 // Save datas. |
571 $em = $this->getDoctrine()->getEntityManager(); |
557 $em = $this->getDoctrine()->getEntityManager(); |
572 $em->persist($tag); |
558 $em->persist($tag); |
573 $em->flush(); |
559 $em->flush(); |
574 } |
560 } |