| author | ymh <ymh.work@gmail.com> |
| Wed, 09 Nov 2011 16:25:13 +0100 | |
| changeset 30 | d2fba1e3b94b |
| parent 29 | 7496254cfead |
| child 32 | 38dcd2db04e4 |
| child 34 | 21fab44f46fe |
| permissions | -rwxr-xr-x |
| 2 | 1 |
<?php |
2 |
/* |
|
| 21 | 3 |
* This file is part of the WikiTagBundle package. |
| 2 | 4 |
* |
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
6 |
* |
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
8 |
* file that was distributed with this source code. |
|
9 |
*/ |
|
10 |
||
11 |
namespace IRI\Bundle\WikiTagBundle\Controller; |
|
12 |
||
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
13 |
use Doctrine\ORM\Query\ResultSetMapping; |
|
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
14 |
use Doctrine\DBAL\DriverManager; |
|
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
15 |
|
| 2 | 16 |
use IRI\Bundle\WikiTagBundle\Entity\DocumentTag; |
17 |
use IRI\Bundle\WikiTagBundle\Entity\Tag; |
|
18 |
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
|
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
19 |
use Pagerfanta\Pagerfanta; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
20 |
use Pagerfanta\Adapter\ArrayAdapter; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
21 |
use Pagerfanta\Adapter\DoctrineORMAdapter; |
| 2 | 22 |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
23 |
use Symfony\Component\HttpFoundation\Response; |
|
24 |
||
25 |
||
26 |
class WikiTagController extends Controller |
|
27 |
{ |
|
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
28 |
private static $SEARCH_STAR_CHARACTER = "*"; |
|
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
29 |
|
| 2 | 30 |
/** |
31 |
* Fake index action |
|
32 |
*/ |
|
33 |
public function indexAction() |
|
34 |
{ |
|
35 |
return new Response('<html><body>Nothing to see here.</body></html>'); |
|
36 |
} |
|
37 |
||
38 |
/** |
|
39 |
* Renders the little html to add the css |
|
40 |
*/ |
|
41 |
public function addCssAction() |
|
42 |
{ |
|
43 |
return $this->render('WikiTagBundle:WikiTag:css.html.twig'); |
|
44 |
} |
|
45 |
||
46 |
/** |
|
47 |
* Renders the little html to add the javascript |
|
48 |
* TODO: review why this injection in javascript, t10n? |
|
49 |
*/ |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
50 |
public function addJavascriptAction($tags_list=FALSE) |
| 2 | 51 |
{ |
52 |
$cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories(); |
|
53 |
// $cats is {"Label":"Créateur"},{"Label":"Datation"},... |
|
54 |
$nbCats = count($cats); |
|
55 |
$ar = array('' => ''); |
|
56 |
for($i=0;$i<$nbCats;$i++){ |
|
| 7 | 57 |
$temp = array($cats[$i]["label"] => $cats[$i]["label"]); |
| 2 | 58 |
$ar = array_merge($ar, $temp); |
59 |
} |
|
60 |
// ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},... |
|
61 |
$categories = json_encode($ar); |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
62 |
return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories,'tags_list' => $tags_list)); |
| 2 | 63 |
} |
64 |
||
65 |
/** |
|
66 |
* Display a list of ordered tag for a document |
|
67 |
* @param integer $id_doc |
|
68 |
*/ |
|
69 |
public function documentTagsAction($id_doc) |
|
70 |
{ |
|
71 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
72 |
return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
|
73 |
} |
|
74 |
||
75 |
/** |
|
76 |
* |
|
77 |
* TODO : Enter description here ... |
|
78 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
79 |
*/ |
|
80 |
public function tagUpDownAction() |
|
81 |
{ |
|
82 |
||
83 |
$req = $this->getRequest()->request; |
|
84 |
$id_doc = $req->get('wikitag_document_id'); |
|
85 |
// post vars new_order and old_order indicate the position (from 1) of the tag in the list. |
|
86 |
// NB : it is different from the DocumentTag.order in the database. |
|
87 |
$new_order = intval($req->get('new_order')) - 1; |
|
88 |
$old_order = intval($req->get('old_order')) - 1; |
|
89 |
// First we get the DocumentTags |
|
90 |
$em = $this->getDoctrine()->getEntityManager(); |
|
91 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
92 |
// We change the moved DocumentTag's order |
|
93 |
$new_dt_order = $ordered_tags[$new_order]->getTagOrder(); |
|
94 |
$moved_dt = $ordered_tags[$old_order]; |
|
95 |
$moved_dt->setTagOrder($new_dt_order); |
|
96 |
// We move the TaggedSheets's order |
|
97 |
if($new_order > $old_order){ |
|
98 |
// And we decrease the other ones |
|
99 |
for ($i=($old_order+1); $i <= ($new_order); $i++){ |
|
100 |
$dt = $ordered_tags[$i]; |
|
101 |
$dt->setTagOrder($dt->getTagOrder() - 1); |
|
102 |
} |
|
103 |
} |
|
104 |
else{ |
|
105 |
// And we increase the other ones |
|
106 |
for ($i=$new_order; $i <= ($old_order-1); $i++){ |
|
107 |
$dt = $ordered_tags[$i]; |
|
108 |
$dt->setTagOrder($dt->getTagOrder() + 1); |
|
109 |
} |
|
110 |
} |
|
111 |
// Save datas. |
|
112 |
$em->flush(); |
|
113 |
||
114 |
return $this->renderDocTags($id_doc); |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* |
|
119 |
* TODO: Enter description here ... |
|
120 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
121 |
*/ |
|
122 |
public function removeTagFromListAction() |
|
123 |
{ |
|
124 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
125 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
126 |
// We get the DocumentTag meant to be deleted, and remove it. |
|
127 |
$em = $this->getDoctrine()->getEntityManager(); |
|
128 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('tag' => $id_tag, 'document' => $id_doc)); |
|
129 |
$em->remove($dt); |
|
130 |
$em->flush(); |
|
131 |
||
132 |
return $this->renderDocTags($id_doc); |
|
133 |
} |
|
134 |
||
135 |
/** |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
136 |
* Modify the tag in the context of a tag list for one document |
| 29 | 137 |
* |
| 2 | 138 |
*/ |
139 |
public function modifyDocumentTagAction() |
|
140 |
{ |
|
141 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
142 |
$tag_label = $this->getRequest()->request->get('value'); |
|
143 |
$id_moved_tag = $this->getRequest()->request->get('id'); |
|
144 |
$moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
145 |
if($tag_label!=$moved_tag->getLabel()){ |
| 2 | 146 |
// We get the DocumentTags |
147 |
$em = $this->getDoctrine()->getEntityManager(); |
|
148 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc)); |
|
149 |
$nb_tags = count($tags); |
|
150 |
$found = false; |
|
151 |
$i = 0; |
|
152 |
while($i<$nb_tags && $found==false){ |
|
153 |
$dt = $tags[$i]; |
|
154 |
if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){ |
|
155 |
$found = true; |
|
156 |
} |
|
157 |
$i++; |
|
158 |
} |
|
159 |
// If the label was found, we sent a bad request |
|
160 |
if($found==true){ |
|
161 |
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
|
162 |
} |
|
163 |
// We create the new tag or get the already existing tag. $tag, $revision_id, $created |
|
164 |
$ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
|
165 |
$tag = $ar[0]; |
|
166 |
$revision_id = $ar[1]; |
|
167 |
$created = $ar[2]; |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
168 |
|
| 2 | 169 |
// We get the DocumentTag and change its tag |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
170 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag)); |
| 2 | 171 |
$dt->setTag($tag); |
172 |
$dt->setWikipediaRevisionId($revision_id); |
|
173 |
// |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
174 |
// TODO: HERE QUERY TO GET A INDEX_NOTE/SCORE for the tag. Here is python code : |
| 2 | 175 |
//kwargs = {DJANGO_ID + "__exact": unicode(ds_id)} |
176 |
//results = SearchQuerySet().filter(title=tag_label).filter_or(description=tag_label).filter(**kwargs) |
|
177 |
//if len(results) > 0: |
|
178 |
// ts.index_note = results[0].score |
|
179 |
// |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
180 |
// We set ManualOrder = true for the current document |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
181 |
$doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('externalId' => $id_doc)); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
182 |
$doc->setManualOrder(true); |
| 2 | 183 |
// We save the datas |
184 |
$em->flush(); |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
185 |
// We render the document's tags |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
186 |
return $this->renderDocTags($id_doc); |
| 2 | 187 |
} |
188 |
||
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* |
|
193 |
* TODO : Enter description here ... |
|
| 7 | 194 |
* TODO : implement |
| 2 | 195 |
*/ |
196 |
public function reorderTagDocumentAction() |
|
197 |
{ |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
198 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
199 |
$res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
200 |
$doc = $res->findOneByExternalId($id_doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
201 |
$doc->setManualOrder(false); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
202 |
$this->getDoctrine()->getEntityManager()->persist($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
203 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
204 |
$search_service = $this->get('wiki_tag.search'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
205 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
206 |
$search_service->reorderTagsForDocument($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
207 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
208 |
$this->getDoctrine()->getEntityManager()->flush(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
209 |
|
| 2 | 210 |
return $this->renderDocTags($id_doc); |
211 |
} |
|
212 |
||
213 |
/** |
|
214 |
* |
|
215 |
* TODO: Enter description here ... |
|
216 |
*/ |
|
217 |
public function addTagAction() |
|
218 |
{ |
|
219 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
220 |
$tag_label = $this->getRequest()->request->get('value'); |
|
221 |
// We get the DocumentTags |
|
222 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
223 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc); |
| 2 | 224 |
$nb_tags = count($tags); |
225 |
$found = false; |
|
226 |
$i = 0; |
|
227 |
while($i<$nb_tags && $found==false){ |
|
228 |
$dt = $tags[$i]; |
|
229 |
if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){ |
|
230 |
$found = true; |
|
231 |
} |
|
232 |
$i++; |
|
233 |
} |
|
234 |
// If the label was found, we sent a bad request |
|
235 |
if($found==true){ |
|
236 |
//TODO : translation |
|
237 |
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
|
238 |
} |
|
| 8 | 239 |
// returns array($tag, $revision_id, $created) |
| 2 | 240 |
$ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
241 |
$tag = $ar[0]; |
|
242 |
$revision_id = $ar[1]; |
|
243 |
$created = $ar[2]; |
|
| 8 | 244 |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
245 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
| 2 | 246 |
$nb_tags = count($tags); |
247 |
||
248 |
if($created==true || $nb_tags==0){ |
|
249 |
$new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
|
250 |
// The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
|
251 |
$a1 = reset($new_order_ar); |
|
252 |
$new_order = intval(reset($a1)) + 1; |
|
253 |
// TODO: use a factory that returns an DocumentTagInterface |
|
254 |
$new_DT = new DocumentTag(); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
255 |
$new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
| 2 | 256 |
$new_DT->setTag($tag); |
257 |
$new_DT->setOriginalOrder($new_order); |
|
258 |
$new_DT->setTagOrder($new_order); |
|
259 |
$new_DT->setWikipediaRevisionId($revision_id); |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
260 |
//TODO ; calculate score |
| 2 | 261 |
$em->persist($new_DT); |
262 |
$em->flush(); |
|
263 |
} |
|
264 |
||
265 |
return $this->renderDocTags($id_doc); |
|
266 |
} |
|
267 |
||
268 |
||
269 |
/** |
|
270 |
* |
|
271 |
* TODO: Enter description here ... |
|
272 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
273 |
*/ |
|
274 |
public function removeWpLinkAction() |
|
275 |
{ |
|
276 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
277 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
278 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
279 |
//return new Response(var_dump(array($tag))); |
|
280 |
// We search if the unsemantized version of the tag already exist. |
|
281 |
$un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
|
282 |
$em = $this->getDoctrine()->getEntityManager(); |
|
| 13 | 283 |
$un_tag_created = FALSE; |
| 2 | 284 |
if(!$un_tag){ |
285 |
// Create another tag almost identical, without the W info |
|
286 |
// TODO: use a factory that return a TagInterface |
|
287 |
$un_tag = new Tag(); |
|
288 |
$un_tag->setLabel($tag->getLabel()); |
|
289 |
$un_tag->setOriginalLabel($tag->getOriginalLabel()); |
|
290 |
$un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
|
291 |
$un_tag->setWikipediaUrl(null); |
|
292 |
$un_tag->setWikipediaPageId(null); |
|
293 |
$un_tag->setDbpediaUri(null); |
|
294 |
$un_tag->setCategory($tag->getCategory()); |
|
295 |
$un_tag->setAlias($tag->getAlias()); |
|
296 |
$un_tag->setPopularity($tag->getPopularity()); |
|
297 |
$em->persist($un_tag); |
|
| 13 | 298 |
$un_tag_created = TRUE; |
| 2 | 299 |
} |
300 |
||
| 13 | 301 |
if($id_doc && $id_doc!=""){ |
302 |
// We associate the unsemantized tag to the DocumentTag and save datas |
|
303 |
// TODO: do the request on external id of document |
|
304 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag)); |
|
305 |
$dt->setTag($un_tag); |
|
306 |
$em->flush(); |
|
307 |
return $this->renderDocTags($id_doc); |
|
308 |
} |
|
309 |
else{ |
|
310 |
// Here we are in the context of tag list. |
|
311 |
if($un_tag_created==TRUE){ |
|
312 |
$em->flush(); |
|
313 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
314 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
315 |
$sort = $this->getRequest()->request->get('sort'); |
|
316 |
$searched = $this->getRequest()->request->get('searched'); |
|
317 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
318 |
} |
|
319 |
else{ |
|
320 |
// The unsemantized version of the tag already exist, so we send an error. |
|
321 |
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); |
|
322 |
} |
|
323 |
} |
|
| 2 | 324 |
} |
325 |
||
326 |
||
327 |
/** |
|
328 |
* |
|
329 |
* TODO: Enter description here ... |
|
330 |
*/ |
|
331 |
public function updateTagCategoryAction() |
|
332 |
{ |
|
333 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
334 |
$id_tag = $this->getRequest()->request->get('id'); |
|
335 |
$cat_label = $this->getRequest()->request->get('value'); |
|
336 |
// We get the Tag and update its category. |
|
337 |
$em = $this->getDoctrine()->getEntityManager(); |
|
338 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
339 |
if($cat_label==''){ |
|
340 |
$cat = null; |
|
341 |
$tag->nullCategory(); |
|
342 |
} |
|
343 |
else{ |
|
344 |
$cat = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOneBy(array('label' => $cat_label)); |
|
345 |
$tag->setCategory($cat); |
|
346 |
} |
|
347 |
$em->flush(); |
|
348 |
||
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
349 |
if($id_doc && $id_doc!=""){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
350 |
return $this->renderDocTags($id_doc); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
351 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
352 |
else{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
353 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
354 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
355 |
$sort = $this->getRequest()->request->get('sort'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
356 |
$searched = $this->getRequest()->request->get('searched'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
357 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
358 |
} |
| 2 | 359 |
} |
360 |
||
361 |
||
362 |
/** |
|
363 |
* |
|
364 |
* Generic render partial template |
|
365 |
* @param unknown_type $id_doc |
|
366 |
*/ |
|
367 |
public function renderDocTags($id_doc) |
|
368 |
{ |
|
369 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
370 |
return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
|
371 |
} |
|
| 7 | 372 |
|
373 |
||
374 |
/** |
|
375 |
* |
|
376 |
* TODO : Enter description here ... |
|
377 |
* TODO : implement |
|
378 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
379 |
*/ |
|
380 |
public function updateTagAliasAction() |
|
381 |
{ |
|
| 12 | 382 |
$id_tag = $this->getRequest()->request->get('id'); |
383 |
$alias = $this->getRequest()->request->get('value'); |
|
384 |
// We get the Tag and update its category. |
|
385 |
$em = $this->getDoctrine()->getEntityManager(); |
|
386 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
387 |
$tag->setAlias($alias); |
|
388 |
$em->flush(); |
|
389 |
||
| 7 | 390 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
| 12 | 391 |
if($id_doc && $id_doc!=""){ |
392 |
// In case we changed the alias from the document view |
|
393 |
return $this->renderDocTags($id_doc); |
|
394 |
} |
|
395 |
else{ |
|
396 |
// In case we changed the alias from the tag list. |
|
397 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
398 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
399 |
$sort = $this->getRequest()->request->get('sort'); |
|
400 |
$searched = $this->getRequest()->request->get('searched'); |
|
401 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
402 |
} |
|
| 7 | 403 |
} |
404 |
||
405 |
/** |
|
406 |
* List of all tags |
|
407 |
* TODO: Enter description here ... |
|
408 |
*/ |
|
409 |
public function allTagsAction() |
|
410 |
{ |
|
411 |
// $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
412 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
413 |
$searched = NULL; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
414 |
if(array_key_exists('searched', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
415 |
$searched = $_GET['searched']; |
| 7 | 416 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
417 |
// Number of tags per page |
| 8 | 418 |
$nb_by_page = 50; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
419 |
if(array_key_exists('nb_by_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
420 |
$nb_by_page = intval($_GET['nb_by_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
421 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
422 |
// Current page number |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
423 |
$num_page = 1; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
424 |
if(array_key_exists('num_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
425 |
$num_page = intval($_GET['num_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
426 |
} |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
427 |
// Sorting criteria |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
428 |
$sort = NULL; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
429 |
if(array_key_exists('sort', $_GET)){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
430 |
$sort = $_GET['sort']; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
431 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
432 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
433 |
// We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
434 |
$ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
| 16 | 435 |
//return new Response($ar); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
436 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
437 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
438 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
439 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
440 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
441 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
442 |
$pagerfanta = $ar[6]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
443 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
444 |
// We get the needed vars : number totals of tags, previous and next page number |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
445 |
$last_page = $pagerfanta->getNbPages(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
446 |
$nb_total = $pagerfanta->getNbResults(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
447 |
$prev_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
448 |
if($pagerfanta->hasPreviousPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
449 |
$prev_page = $pagerfanta->getPreviousPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
450 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
451 |
$next_page = $last_page; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
452 |
if($pagerfanta->hasNextPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
453 |
$next_page = $pagerfanta->getNextPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
454 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
455 |
// We calculate start_index and end_index (number of tags in the whole list) |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
456 |
$start_index = 1 + (($num_page - 1) * $nb_by_page); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
457 |
$end_index = min($nb_total, $start_index + $nb_by_page - 1); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
458 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
459 |
// We build the list of tags's first letters to make quick search. |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
460 |
$conn = $this->getDoctrine()->getEntityManager()->getConnection(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
461 |
$sql = "SELECT UPPER(SUBSTRING(normalized_label,1,1)) as fl FROM wikitag_tag GROUP BY fl ORDER BY fl"; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
462 |
$letters = $conn->query($sql)->fetchAll(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
463 |
$search_def = array(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
464 |
foreach ($letters as $l){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
465 |
$search_def[$l[0]] = $l[0].WikiTagController::$SEARCH_STAR_CHARACTER; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
466 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
467 |
|
| 21 | 468 |
return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
469 |
array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, |
|
470 |
'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, |
|
471 |
'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"))); |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
472 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
473 |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
474 |
/** |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
475 |
* Modify the tag in the context of all tags list. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
476 |
*/ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
477 |
public function modifyTagAction() |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
478 |
{ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
479 |
$tag_label = $this->getRequest()->request->get('value'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
480 |
$id_moved_tag = $this->getRequest()->request->get('id'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
481 |
$moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
482 |
// We update the tag label and its wikipedia info with the new label. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
483 |
$this->updateTagWithNewLabel($moved_tag, $tag_label); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
484 |
|
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
485 |
// We render the tag list. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
486 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
487 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
488 |
$sort = $this->getRequest()->request->get('sort'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
489 |
$searched = $this->getRequest()->request->get('searched'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
490 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
491 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
492 |
|
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
493 |
/** |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
494 |
* |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
495 |
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label. |
| 29 | 496 |
* |
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
497 |
*/ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
498 |
public function resetWpInfoAction() |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
499 |
{ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
500 |
$id_moved_tag = $this->getRequest()->request->get('tag_id'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
501 |
$moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
502 |
// We update the tag label and its wikipedia info with the original label. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
503 |
$this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel()); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
504 |
|
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
505 |
// We render the tag list. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
506 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
507 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
508 |
$sort = $this->getRequest()->request->get('sort'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
509 |
$searched = $this->getRequest()->request->get('searched'); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
510 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
511 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
512 |
|
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
513 |
|
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
514 |
/** |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
515 |
* Generic render partial template for tag list |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
516 |
*/ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
517 |
private function updateTagWithNewLabel($tag, $label) |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
518 |
{ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
519 |
if($tag!=null && $label!=null){ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
520 |
if($label!=$tag->getLabel()){ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
521 |
// We get the Wikipedia informations for the sent label |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
522 |
$tag_label_normalized = WikiTagUtils::normalizeTag($label); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
523 |
$wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
524 |
$new_label = $wp_response['new_label']; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
525 |
$status = $wp_response['status']; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
526 |
$url = $wp_response['wikipedia_url']; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
527 |
$pageid = $wp_response['pageid']; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
528 |
$dbpedia_uri = $wp_response["dbpedia_uri"]; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
529 |
$wikipedia_revision_id = $wp_response['revision_id']; |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
530 |
// We save the datas : we DO NOT create a new tag, we change the current tag's informations |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
531 |
if($new_label!=null){ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
532 |
$tag->setLabel($new_label); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
533 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
534 |
if($status!=null){ |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
535 |
$tag->setUrlStatus($status); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
536 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
537 |
$tag->setWikipediaUrl($url); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
538 |
$tag->setWikipediaPageId($pageid); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
539 |
$tag->setDbpediaUri($dbpedia_uri); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
540 |
// Save datas. |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
541 |
$em = $this->getDoctrine()->getEntityManager(); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
542 |
$em->persist($tag); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
543 |
$em->flush(); |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
544 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
545 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
546 |
} |
|
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
547 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
548 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
549 |
/** |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
550 |
* Generic render partial template for tag list |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
551 |
*/ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
552 |
public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
553 |
{ |
|
14
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
554 |
|
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
555 |
//We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
556 |
$ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
557 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
558 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
559 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
560 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
561 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
562 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
563 |
|
| 21 | 564 |
return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
565 |
array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, |
|
|
22
99c15cfe420b
Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents:
21
diff
changeset
|
566 |
'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"))); |
|
14
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
567 |
|
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
568 |
return $this->getAllTags(); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
569 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
570 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
571 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
572 |
/** |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
573 |
* Generic to get all tags with the context (pagination number, nb by page, searched string, sort) |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
574 |
*/ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
575 |
private function getAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
576 |
{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
577 |
// We get/set all the parameters for the search and pagination. |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
578 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
579 |
if($searched==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
580 |
$searched = ""; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
581 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
582 |
// Number of tags per page |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
583 |
if($nb_by_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
584 |
$nb_by_page = 50; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
585 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
586 |
// Current page number |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
587 |
if($num_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
588 |
$num_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
589 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
590 |
|
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
591 |
// We build the query. |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
592 |
$qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); |
|
14
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
593 |
$qb->select('t', 'COUNT( dt.id ) AS nb_docs'); |
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
594 |
$qb->from('WikiTagBundle:Tag','t'); |
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
595 |
$qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag'); |
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
596 |
$qb->addGroupBy('t.id'); |
|
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
597 |
|
| 16 | 598 |
// We add the search string if necessary |
599 |
if($searched!=""){ |
|
600 |
// We replace "*" by "%", and doctrine wants ' to be ''. |
|
601 |
$qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", $searched))."'"))); |
|
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
602 |
} |
| 16 | 603 |
//return $qb->getDql(); |
|
14
673b2766024e
Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents:
13
diff
changeset
|
604 |
|
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
605 |
// We add the sorting criteria |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
606 |
if($sort==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
607 |
$sort = "popd"; // sort by descendent popularity by default. |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
608 |
$reverse_sort = "popa"; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
609 |
} |
| 26 | 610 |
//$sort_query = "nb_docs DESC t.popularity DESC t.normalizedLabel ASC t.label ASC"; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
611 |
switch($sort){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
612 |
case "popd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
613 |
$qb->addOrderBy('t.popularity','DESC'); |
| 26 | 614 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
615 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
616 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
617 |
$reverse_sort = "popa"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
618 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
619 |
case "popa": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
620 |
$qb->addOrderBy('t.popularity','ASC'); |
| 26 | 621 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
622 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
623 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
624 |
$reverse_sort = "popd"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
625 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
626 |
case "labd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
627 |
$qb->addOrderBy('t.normalizedLabel','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
628 |
$qb->addOrderBy('t.label','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
629 |
$reverse_sort = "laba"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
630 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
631 |
case "laba": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
632 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
633 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
634 |
$reverse_sort = "labd"; |
| 26 | 635 |
case "nbd": |
636 |
$qb->addOrderBy('nb_docs','DESC'); |
|
637 |
$qb->addOrderBy('t.popularity','DESC'); |
|
638 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
639 |
$qb->addOrderBy('t.label','ASC'); |
|
640 |
$reverse_sort = "nba"; |
|
641 |
break; |
|
642 |
case "nba": |
|
643 |
$qb->addOrderBy('nb_docs','ASC'); |
|
644 |
$qb->addOrderBy('t.popularity','DESC'); |
|
645 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
646 |
$qb->addOrderBy('t.label','ASC'); |
|
647 |
$reverse_sort = "nbd"; |
|
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
648 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
649 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
650 |
|
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
651 |
// We paginate |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
652 |
$adapter = new DoctrineORMAdapter($qb); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
653 |
$pagerfanta = new Pagerfanta($adapter); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
654 |
$pagerfanta->setMaxPerPage($nb_by_page); // 10 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
655 |
$pagerfanta->setCurrentPage($num_page); // 1 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
656 |
$nb_total = $pagerfanta->getNbResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
657 |
$tags = $pagerfanta->getCurrentPageResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
658 |
$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page |
| 15 | 659 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
660 |
return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
| 7 | 661 |
} |
| 2 | 662 |
|
663 |
||
664 |
} |