equal
deleted
inserted
replaced
145 { |
145 { |
146 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
146 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
147 $id_tag = $this->getRequest()->request->get('tag_id'); |
147 $id_tag = $this->getRequest()->request->get('tag_id'); |
148 // We get the DocumentTag meant to be deleted, and remove it. |
148 // We get the DocumentTag meant to be deleted, and remove it. |
149 $em = $this->getDoctrine()->getEntityManager(); |
149 $em = $this->getDoctrine()->getEntityManager(); |
150 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('tag' => $id_tag, 'document' => $id_doc)); |
150 //TODO: use external id |
|
151 |
|
152 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
151 $em->remove($dt); |
153 $em->remove($dt); |
152 $em->flush(); |
154 $em->flush(); |
153 |
155 |
154 return $this->renderDocTags($id_doc); |
156 return $this->renderDocTags($id_doc); |
155 } |
157 } |
165 $id_moved_tag = $this->getRequest()->request->get('id'); |
167 $id_moved_tag = $this->getRequest()->request->get('id'); |
166 $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); |
168 $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); |
167 if($tag_label!=$moved_tag->getLabel()){ |
169 if($tag_label!=$moved_tag->getLabel()){ |
168 // We get the DocumentTags |
170 // We get the DocumentTags |
169 $em = $this->getDoctrine()->getEntityManager(); |
171 $em = $this->getDoctrine()->getEntityManager(); |
170 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc)); |
172 |
171 $nb_tags = count($tags); |
173 $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc); |
172 $found = false; |
174 $found = false; |
173 $i = 0; |
175 foreach ($tags as $dt) |
174 while($i<$nb_tags && $found==false){ |
176 { |
175 $dt = $tags[$i]; |
177 if($dt->getTag()->getLabel()===$tag_label) |
176 if($dt->getTag()->getLabel()==$tag_label){ |
178 { |
177 $found = true; |
179 $found = true; |
|
180 break; |
178 } |
181 } |
179 $i++; |
|
180 } |
182 } |
181 // If the label was found, we sent a bad request |
183 // If the label was found, we sent a bad request |
182 if($found==true){ |
184 if($found==true){ |
183 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
185 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
184 } |
186 } |
187 $tag = $ar[0]; |
189 $tag = $ar[0]; |
188 $revision_id = $ar[1]; |
190 $revision_id = $ar[1]; |
189 $created = $ar[2]; |
191 $created = $ar[2]; |
190 |
192 |
191 // We get the DocumentTag and change its tag |
193 // We get the DocumentTag and change its tag |
192 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag)); |
194 |
|
195 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_moved_tag)); |
193 $dt->setTag($tag); |
196 $dt->setTag($tag); |
194 $dt->setWikipediaRevisionId($revision_id); |
197 $dt->setWikipediaRevisionId($revision_id); |
195 |
198 |
196 $score_res = $this->container->get('wiki_tag.search')->search($tag_label, array("id"=>$id_doc)); |
199 $score_res = $this->container->get('wiki_tag.search')->search($tag_label, array("externalId"=>$id_doc)); |
197 |
200 |
198 if(count($score_res)>0) |
201 if(count($score_res)>0) |
199 { |
202 { |
200 $score = floatval($score_res[0]['score']); |
203 $score = floatval($score_res[0]['score']); |
201 } |
204 } |
223 */ |
226 */ |
224 public function reorderTagDocumentAction() |
227 public function reorderTagDocumentAction() |
225 { |
228 { |
226 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
229 $id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
227 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
230 $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
|
231 |
228 $doc = $res->findOneByExternalId($id_doc); |
232 $doc = $res->findOneByExternalId($id_doc); |
229 $doc->setManualOrder(false); |
233 $doc->setManualOrder(false); |
230 $this->getDoctrine()->getEntityManager()->persist($doc); |
234 $this->getDoctrine()->getEntityManager()->persist($doc); |
231 |
235 |
232 $search_service = $this->get('wiki_tag.search'); |
236 $search_service = $this->get('wiki_tag.search'); |
283 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
287 $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
284 $new_DT->setTag($tag); |
288 $new_DT->setTag($tag); |
285 $new_DT->setOriginalOrder($new_order); |
289 $new_DT->setOriginalOrder($new_order); |
286 $new_DT->setTagOrder($new_order); |
290 $new_DT->setTagOrder($new_order); |
287 $new_DT->setWikipediaRevisionId($revision_id); |
291 $new_DT->setWikipediaRevisionId($revision_id); |
288 //TODO ; calculate score |
|
289 $em->persist($new_DT); |
292 $em->persist($new_DT); |
290 $em->flush(); |
293 $em->flush(); |
291 } |
294 } |
292 |
295 |
293 return $this->renderDocTags($id_doc); |
296 return $this->renderDocTags($id_doc); |
326 $un_tag_created = TRUE; |
329 $un_tag_created = TRUE; |
327 } |
330 } |
328 |
331 |
329 if($id_doc && $id_doc!=""){ |
332 if($id_doc && $id_doc!=""){ |
330 // We associate the unsemantized tag to the DocumentTag and save datas |
333 // We associate the unsemantized tag to the DocumentTag and save datas |
331 // TODO: do the request on external id of document |
334 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
332 $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag)); |
|
333 $dt->setTag($un_tag); |
335 $dt->setTag($un_tag); |
334 $em->flush(); |
336 $em->flush(); |
335 return $this->renderDocTags($id_doc); |
337 return $this->renderDocTags($id_doc); |
336 } |
338 } |
337 else{ |
339 else{ |