43 return $this->render('WikiTagBundle:WikiTag:css.html.twig'); |
43 return $this->render('WikiTagBundle:WikiTag:css.html.twig'); |
44 } |
44 } |
45 |
45 |
46 /** |
46 /** |
47 * Renders the little html to add the javascript |
47 * Renders the little html to add the javascript |
48 * TODO: review why this injection in javascript, t10n? |
48 * |
49 */ |
49 * @param unknown_type $tags_list |
50 public function addJavascriptAction($tags_list=FALSE) |
50 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
51 */ |
|
52 public function addJavascriptAction($tags_list=false) |
51 { |
53 { |
52 $cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories(); |
54 $cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories(); |
53 // $cats is {"Label":"Créateur"},{"Label":"Datation"},... |
55 // $cats is {"Label":"Créateur"},{"Label":"Datation"},... |
54 $nbCats = count($cats); |
56 $nbCats = count($cats); |
55 $ar = array('' => ''); |
57 $ar = array('' => ''); |
56 for($i=0;$i<$nbCats;$i++){ |
58 for($i=0;$i<$nbCats;$i++) { |
57 $temp = array($cats[$i]["label"] => $cats[$i]["label"]); |
59 $temp = array($cats[$i]["label"] => $cats[$i]["label"]); |
58 $ar = array_merge($ar, $temp); |
60 $ar = array_merge($ar, $temp); |
59 } |
61 } |
60 // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},... |
62 // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},... |
61 $categories = json_encode($ar); |
63 $categories = json_encode($ar); |
101 return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'profile_name' => $profile_name, 'columns' => $columns_array)); |
103 return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'profile_name' => $profile_name, 'columns' => $columns_array)); |
102 } |
104 } |
103 |
105 |
104 /** |
106 /** |
105 * |
107 * |
106 * TODO : Enter description here ... |
108 * The action called when a tag is moved in a document tag list. |
|
109 * |
107 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
110 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
108 */ |
111 */ |
109 public function tagUpDownAction() |
112 public function tagUpDownAction() |
110 { |
113 { |
111 |
114 |
142 |
145 |
143 return $this->renderDocTags($id_doc); |
146 return $this->renderDocTags($id_doc); |
144 } |
147 } |
145 |
148 |
146 /** |
149 /** |
147 * |
150 * Action to remove a tag from a document tag list |
148 * TODO: Enter description here ... |
|
149 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
151 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
150 */ |
152 */ |
151 public function removeTagFromListAction() |
153 public function removeTagFromListAction() |
152 { |
154 { |
153 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
155 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
154 $id_tag = $this->getRequest()->request->get('tag_id'); |
156 $id_tag = $this->getRequest()->request->get('tag_id'); |
155 // We get the DocumentTag meant to be deleted, and remove it. |
157 // We get the DocumentTag meant to be deleted, and remove it. |
156 $em = $this->getDoctrine()->getEntityManager(); |
158 $em = $this->getDoctrine()->getEntityManager(); |
157 //TODO: use external id |
|
158 |
159 |
159 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
160 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
160 $em->remove($dt); |
161 $em->remove($dt); |
161 $em->flush(); |
162 $em->flush(); |
162 |
163 |
190 // If the label was found, we sent a bad request |
191 // If the label was found, we sent a bad request |
191 if($found==true){ |
192 if($found==true){ |
192 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
193 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
193 } |
194 } |
194 // We create the new tag or get the already existing tag. $tag, $revision_id, $created |
195 // We create the new tag or get the already existing tag. $tag, $revision_id, $created |
195 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine()); |
196 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label); |
196 $tag = $ar[0]; |
197 $tag = $ar[0]; |
197 $revision_id = $ar[1]; |
198 $revision_id = $ar[1]; |
198 $created = $ar[2]; |
199 $created = $ar[2]; |
199 |
200 |
200 // We get the DocumentTag and change its tag |
201 // We get the DocumentTag and change its tag |
225 return $this->renderDocTags($id_doc); |
226 return $this->renderDocTags($id_doc); |
226 |
227 |
227 } |
228 } |
228 |
229 |
229 /** |
230 /** |
230 * |
231 * 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. |
231 * TODO : Enter description here ... |
232 * The fields taken into account for calculating the score are defined in the wikitag configuration. |
232 * TODO : implement |
|
233 */ |
233 */ |
234 public function reorderTagDocumentAction() |
234 public function reorderTagDocumentAction() |
235 { |
235 { |
236 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
236 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
237 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
237 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
248 |
248 |
249 return $this->renderDocTags($id_doc); |
249 return $this->renderDocTags($id_doc); |
250 } |
250 } |
251 |
251 |
252 /** |
252 /** |
253 * |
253 * The action called to add a new tag (especially from the completion box) |
254 * TODO: Enter description here ... |
|
255 */ |
254 */ |
256 public function addTagAction() |
255 public function addTagAction() |
257 { |
256 { |
258 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
257 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
259 $tag_label = $this->getRequest()->request->get('value'); |
258 $tag_label = $this->getRequest()->request->get('value'); |
274 if($found==true){ |
273 if($found==true){ |
275 //TODO : translation |
274 //TODO : translation |
276 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
275 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
277 } |
276 } |
278 // returns array($tag, $revision_id, $created) |
277 // returns array($tag, $revision_id, $created) |
279 $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
278 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);// tag, revision_id, created = get_or_create_tag(tag_label) |
280 $tag = $ar[0]; |
279 $tag = $ar[0]; |
281 $revision_id = $ar[1]; |
280 $revision_id = $ar[1]; |
282 $created = $ar[2]; |
281 $created = $ar[2]; |
283 |
282 |
284 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
283 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
287 if($created==true || $nb_tags==0){ |
286 if($created==true || $nb_tags==0){ |
288 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
287 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
289 // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
288 // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
290 $a1 = reset($new_order_ar); |
289 $a1 = reset($new_order_ar); |
291 $new_order = intval(reset($a1)) + 1; |
290 $new_order = intval(reset($a1)) + 1; |
292 // TODO: use a factory that returns an DocumentTagInterface |
|
293 $new_DT = new DocumentTag(); |
291 $new_DT = new DocumentTag(); |
294 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
292 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
295 $new_DT->setTag($tag); |
293 $new_DT->setTag($tag); |
296 $new_DT->setOriginalOrder($new_order); |
294 $new_DT->setOriginalOrder($new_order); |
297 $new_DT->setTagOrder($new_order); |
295 $new_DT->setTagOrder($new_order); |
303 return $this->renderDocTags($id_doc); |
301 return $this->renderDocTags($id_doc); |
304 } |
302 } |
305 |
303 |
306 |
304 |
307 /** |
305 /** |
308 * |
306 * Action to remove the wikipedia link form a tag. This action create a copy of the original tag with all the link to wikipedia set to null. |
309 * TODO: Enter description here ... |
307 * |
310 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
308 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
311 */ |
309 */ |
312 public function removeWpLinkAction() |
310 public function removeWpLinkAction() |
313 { |
311 { |
314 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
312 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
319 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
317 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
320 $em = $this->getDoctrine()->getEntityManager(); |
318 $em = $this->getDoctrine()->getEntityManager(); |
321 $un_tag_created = FALSE; |
319 $un_tag_created = FALSE; |
322 if(!$un_tag){ |
320 if(!$un_tag){ |
323 // Create another tag almost identical, without the W info |
321 // Create another tag almost identical, without the W info |
324 // TODO: use a factory that return a TagInterface |
|
325 $un_tag = new Tag(); |
322 $un_tag = new Tag(); |
326 $un_tag->setLabel($tag->getLabel()); |
323 $un_tag->setLabel($tag->getLabel()); |
327 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
324 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
328 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
325 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
329 $un_tag->setWikipediaUrl(null); |
326 $un_tag->setWikipediaUrl(null); |
330 $un_tag->setWikipediaPageId(null); |
327 $un_tag->setWikipediaPageId(null); |
|
328 $un_tag->setAlternativeWikipediaUrl(null); |
|
329 $un_tag->setAlternativeWikipediaPageId(null); |
|
330 $un_tag->setAlternativeLabel(null); |
331 $un_tag->setDbpediaUri(null); |
331 $un_tag->setDbpediaUri(null); |
332 $un_tag->setCategory($tag->getCategory()); |
332 $un_tag->setCategory($tag->getCategory()); |
333 $un_tag->setAlias($tag->getAlias()); |
333 $un_tag->setAlias($tag->getAlias()); |
334 $un_tag->setPopularity($tag->getPopularity()); |
334 $un_tag->setPopularity($tag->getPopularity()); |
335 $em->persist($un_tag); |
335 $em->persist($un_tag); |
336 $un_tag_created = TRUE; |
336 $un_tag_created = true; |
337 } |
337 } |
338 |
338 |
339 if($id_doc && $id_doc!=""){ |
339 if($id_doc && $id_doc!=""){ |
340 // We associate the unsemantized tag to the DocumentTag and save datas |
340 // 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)); |
341 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
407 return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => null)); |
407 return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => null)); |
408 } |
408 } |
409 |
409 |
410 |
410 |
411 /** |
411 /** |
412 * |
412 * Action to update the tag alias. |
413 * TODO : Enter description here ... |
413 * |
414 * TODO : implement |
|
415 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
414 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
416 */ |
415 */ |
417 public function updateTagAliasAction() |
416 public function updateTagAliasAction() |
418 { |
417 { |
419 $id_tag = $this->getRequest()->request->get('id'); |
418 $id_tag = $this->getRequest()->request->get('id'); |
438 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
437 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
439 } |
438 } |
440 } |
439 } |
441 |
440 |
442 /** |
441 /** |
443 * List of all tags |
442 * List all tags, with pagination and search. |
444 * TODO: Enter description here ... |
443 * |
|
444 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
445 */ |
445 */ |
446 public function allTagsAction() |
446 public function allTagsAction() |
447 { |
447 { |
448 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
448 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
449 // Searched string |
449 // Searched string |
556 if($tag!=null && $label!=null){ |
556 if($tag!=null && $label!=null){ |
557 if($label!=$tag->getLabel()){ |
557 if($label!=$tag->getLabel()){ |
558 // We get the Wikipedia informations for the sent label |
558 // We get the Wikipedia informations for the sent label |
559 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
559 $tag_label_normalized = WikiTagUtils::normalizeTag($label); |
560 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
560 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
561 //return new Response(var_dump($wp_response)); |
561 $tag->setWikipediaInfo($wp_response); |
562 $new_label = $tag_label_normalized; |
|
563 $status = $wp_response['status']; |
|
564 $url = $wp_response['wikipedia_url']; |
|
565 $pageid = $wp_response['pageid']; |
|
566 $dbpedia_uri = $wp_response["dbpedia_uri"]; |
|
567 $wikipedia_revision_id = $wp_response['revision_id']; |
|
568 // We save the datas : we DO NOT create a new tag, we change the current tag's informations |
|
569 if($new_label!=null){ |
|
570 $tag->setLabel($new_label); |
|
571 } |
|
572 else{ |
|
573 $tag->setLabel($tag_label_normalized); |
|
574 } |
|
575 if(!is_null($status)){ |
|
576 $tag->setUrlStatus($status); |
|
577 } |
|
578 else{ |
|
579 $tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
|
580 } |
|
581 $tag->setWikipediaUrl($url); |
|
582 $tag->setWikipediaPageId($pageid); |
|
583 $tag->setDbpediaUri($dbpedia_uri); |
|
584 // Save datas. |
562 // Save datas. |
585 $em = $this->getDoctrine()->getEntityManager(); |
563 $em = $this->getDoctrine()->getEntityManager(); |
586 $em->persist($tag); |
564 $em->persist($tag); |
587 $em->flush(); |
565 $em->flush(); |
588 } |
566 } |