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); |
136 |
138 |
137 return $this->renderDocTags($id_doc); |
139 return $this->renderDocTags($id_doc); |
138 } |
140 } |
139 |
141 |
140 /** |
142 /** |
141 * |
143 * Action to remove a tag from a document tag list |
142 * TODO: Enter description here ... |
|
143 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
144 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
144 */ |
145 */ |
145 public function removeTagFromListAction() |
146 public function removeTagFromListAction() |
146 { |
147 { |
147 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
148 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
148 $id_tag = $this->getRequest()->request->get('tag_id'); |
149 $id_tag = $this->getRequest()->request->get('tag_id'); |
149 // We get the DocumentTag meant to be deleted, and remove it. |
150 // We get the DocumentTag meant to be deleted, and remove it. |
150 $em = $this->getDoctrine()->getEntityManager(); |
151 $em = $this->getDoctrine()->getEntityManager(); |
151 //TODO: use external id |
|
152 |
152 |
153 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
153 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
154 $em->remove($dt); |
154 $em->remove($dt); |
155 $em->flush(); |
155 $em->flush(); |
156 |
156 |
279 if($created==true || $nb_tags==0){ |
279 if($created==true || $nb_tags==0){ |
280 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
280 $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
281 // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
281 // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
282 $a1 = reset($new_order_ar); |
282 $a1 = reset($new_order_ar); |
283 $new_order = intval(reset($a1)) + 1; |
283 $new_order = intval(reset($a1)) + 1; |
284 // TODO: use a factory that returns an DocumentTagInterface |
|
285 $new_DT = new DocumentTag(); |
284 $new_DT = new DocumentTag(); |
286 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
285 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
287 $new_DT->setTag($tag); |
286 $new_DT->setTag($tag); |
288 $new_DT->setOriginalOrder($new_order); |
287 $new_DT->setOriginalOrder($new_order); |
289 $new_DT->setTagOrder($new_order); |
288 $new_DT->setTagOrder($new_order); |
295 return $this->renderDocTags($id_doc); |
294 return $this->renderDocTags($id_doc); |
296 } |
295 } |
297 |
296 |
298 |
297 |
299 /** |
298 /** |
300 * |
299 * 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. |
301 * TODO: Enter description here ... |
300 * |
302 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
301 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
303 */ |
302 */ |
304 public function removeWpLinkAction() |
303 public function removeWpLinkAction() |
305 { |
304 { |
306 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
305 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
311 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
310 $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
312 $em = $this->getDoctrine()->getEntityManager(); |
311 $em = $this->getDoctrine()->getEntityManager(); |
313 $un_tag_created = FALSE; |
312 $un_tag_created = FALSE; |
314 if(!$un_tag){ |
313 if(!$un_tag){ |
315 // Create another tag almost identical, without the W info |
314 // Create another tag almost identical, without the W info |
316 // TODO: use a factory that return a TagInterface |
|
317 $un_tag = new Tag(); |
315 $un_tag = new Tag(); |
318 $un_tag->setLabel($tag->getLabel()); |
316 $un_tag->setLabel($tag->getLabel()); |
319 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
317 $un_tag->setOriginalLabel($tag->getOriginalLabel()); |
320 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
318 $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
321 $un_tag->setWikipediaUrl(null); |
319 $un_tag->setWikipediaUrl(null); |
322 $un_tag->setWikipediaPageId(null); |
320 $un_tag->setWikipediaPageId(null); |
|
321 $un_tag->setAlternativeWikipediaUrl(null); |
|
322 $un_tag->setAlternativeWikipediaPageId(null); |
|
323 $un_tag->setAlternativeLabel(null); |
323 $un_tag->setDbpediaUri(null); |
324 $un_tag->setDbpediaUri(null); |
324 $un_tag->setCategory($tag->getCategory()); |
325 $un_tag->setCategory($tag->getCategory()); |
325 $un_tag->setAlias($tag->getAlias()); |
326 $un_tag->setAlias($tag->getAlias()); |
326 $un_tag->setPopularity($tag->getPopularity()); |
327 $un_tag->setPopularity($tag->getPopularity()); |
327 $em->persist($un_tag); |
328 $em->persist($un_tag); |
328 $un_tag_created = TRUE; |
329 $un_tag_created = true; |
329 } |
330 } |
330 |
331 |
331 if($id_doc && $id_doc!=""){ |
332 if($id_doc && $id_doc!=""){ |
332 // We associate the unsemantized tag to the DocumentTag and save datas |
333 // We associate the unsemantized tag to the DocumentTag and save datas |
333 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
334 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
399 return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
400 return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
400 } |
401 } |
401 |
402 |
402 |
403 |
403 /** |
404 /** |
404 * |
405 * Action to update the tag alias. |
405 * TODO : Enter description here ... |
406 * |
406 * TODO : implement |
|
407 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
407 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
408 */ |
408 */ |
409 public function updateTagAliasAction() |
409 public function updateTagAliasAction() |
410 { |
410 { |
411 $id_tag = $this->getRequest()->request->get('id'); |
411 $id_tag = $this->getRequest()->request->get('id'); |
430 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
430 return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
431 } |
431 } |
432 } |
432 } |
433 |
433 |
434 /** |
434 /** |
435 * List of all tags |
435 * List all tags, with pagination and search. |
436 * TODO: Enter description here ... |
436 * |
|
437 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
437 */ |
438 */ |
438 public function allTagsAction() |
439 public function allTagsAction() |
439 { |
440 { |
440 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
441 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
441 // Searched string |
442 // Searched string |