| author | ymh <ymh.work@gmail.com> |
| Tue, 21 Feb 2012 15:15:22 +0100 | |
| changeset 74 | 901463f9b11c |
| parent 68 | e7384fb35f7a |
| child 77 | 021131fbe2c5 |
| permissions | -rwxr-xr-x |
| 2 | 1 |
<?php |
2 |
/* |
|
|
74
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
3 |
* This file is part of the WikiTagBundle package. |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
4 |
* |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
6 |
* |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
8 |
* file that was distributed with this source code. |
|
901463f9b11c
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
9 |
*/ |
| 2 | 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; |
|
| 63 | 19 |
use IRI\Bundle\WikiTagBundle\Services\WikiTagServiceException; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
20 |
use Pagerfanta\Pagerfanta; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
21 |
use Pagerfanta\Adapter\ArrayAdapter; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
22 |
use Pagerfanta\Adapter\DoctrineORMAdapter; |
| 2 | 23 |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
24 |
use Symfony\Component\HttpFoundation\Response; |
|
25 |
||
26 |
||
27 |
class WikiTagController extends Controller |
|
28 |
{ |
|
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
29 |
private static $SEARCH_STAR_CHARACTER = "*"; |
|
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
30 |
|
| 2 | 31 |
/** |
32 |
* Fake index action |
|
33 |
*/ |
|
34 |
public function indexAction() |
|
35 |
{ |
|
36 |
return new Response('<html><body>Nothing to see here.</body></html>'); |
|
37 |
} |
|
38 |
||
39 |
/** |
|
40 |
* Renders the little html to add the css |
|
41 |
*/ |
|
42 |
public function addCssAction() |
|
43 |
{ |
|
44 |
return $this->render('WikiTagBundle:WikiTag:css.html.twig'); |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* Renders the little html to add the javascript |
|
| 43 | 49 |
* |
50 |
* @param unknown_type $tags_list |
|
51 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
| 2 | 52 |
*/ |
|
53
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
53 |
public function addJavascriptAction($tags_list=false, $profile_name=null) |
| 2 | 54 |
{ |
55 |
$cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories(); |
|
56 |
// $cats is {"Label":"Créateur"},{"Label":"Datation"},... |
|
57 |
$nbCats = count($cats); |
|
58 |
$ar = array('' => ''); |
|
| 43 | 59 |
for($i=0;$i<$nbCats;$i++) { |
| 7 | 60 |
$temp = array($cats[$i]["label"] => $cats[$i]["label"]); |
| 2 | 61 |
$ar = array_merge($ar, $temp); |
62 |
} |
|
63 |
// ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},... |
|
64 |
$categories = json_encode($ar); |
|
|
53
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
65 |
// Management of profiles for the list of displayed columns and reorder tag button |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
66 |
$profile_array = $this->container->getParameter("wiki_tag.document_list_profile"); |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
67 |
$columns_array = null; |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
68 |
if($profile_array!=null && $profile_name!=null && $profile_name!=""){ |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
69 |
$columns_array = $profile_array[$profile_name]; |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
70 |
} |
|
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
71 |
return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list, 'columns' => $columns_array)); |
|
33
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
72 |
} |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
73 |
|
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
74 |
/** |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
75 |
* Renders the little html to add the javascript for context search |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
76 |
*/ |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
77 |
public function addJavascriptForContextSearchAction($context_name) |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
78 |
{ |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
79 |
// WARNING : PREREQUISITE : the request to add a tag needs the external document id, |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
80 |
// which is gotten by the jQuery call $('#wikitag_document_id').val() in the page. |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
81 |
// So the page holding this context search MUST have a input value with this id. |
|
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
82 |
// We add the reactive selectors |
|
36
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
83 |
$reac_sel_array = $this->container->getParameter("wiki_tag.reactive_selectors"); |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
84 |
$reactive_selectors = null; |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
85 |
if(array_key_exists($context_name, $reac_sel_array)){ |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
86 |
if($reac_sel_array[$context_name][0]=='document'){ |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
87 |
$reactive_selectors = 'document'; |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
88 |
} |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
89 |
else{ |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
90 |
$reactive_selectors = '"'.join('","',$reac_sel_array[$context_name]).'"'; |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
91 |
} |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
92 |
} |
|
33
6c87166b819c
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents:
32
diff
changeset
|
93 |
return $this->render('WikiTagBundle:WikiTag:javascriptForContextSearch.html.twig', array('reactive_selectors' => $reactive_selectors)); |
| 2 | 94 |
} |
95 |
||
96 |
/** |
|
97 |
* Display a list of ordered tag for a document |
|
98 |
* @param integer $id_doc |
|
99 |
*/ |
|
| 46 | 100 |
public function documentTagsAction($id_doc, $profile_name="") |
| 2 | 101 |
{ |
| 46 | 102 |
// Management of profiles for the list of displayed columns and reorder tag button |
103 |
$profile_array = $this->container->getParameter("wiki_tag.document_list_profile"); |
|
104 |
$columns_array = null; |
|
105 |
if($profile_array!=null && $profile_name!=null && $profile_name!=""){ |
|
106 |
$columns_array = $profile_array[$profile_name]; |
|
107 |
} |
|
108 |
||
| 2 | 109 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
53
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
110 |
return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => $columns_array)); |
| 2 | 111 |
} |
112 |
||
113 |
/** |
|
114 |
* |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
115 |
* The action called when a tag is moved in a document tag list. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
116 |
* |
| 2 | 117 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
118 |
*/ |
|
119 |
public function tagUpDownAction() |
|
120 |
{ |
|
121 |
||
122 |
$req = $this->getRequest()->request; |
|
123 |
$id_doc = $req->get('wikitag_document_id'); |
|
124 |
// post vars new_order and old_order indicate the position (from 1) of the tag in the list. |
|
125 |
// NB : it is different from the DocumentTag.order in the database. |
|
126 |
$new_order = intval($req->get('new_order')) - 1; |
|
127 |
$old_order = intval($req->get('old_order')) - 1; |
|
128 |
// First we get the DocumentTags |
|
129 |
$em = $this->getDoctrine()->getEntityManager(); |
|
130 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
131 |
// We change the moved DocumentTag's order |
|
132 |
$new_dt_order = $ordered_tags[$new_order]->getTagOrder(); |
|
133 |
$moved_dt = $ordered_tags[$old_order]; |
|
134 |
$moved_dt->setTagOrder($new_dt_order); |
|
135 |
// We move the TaggedSheets's order |
|
136 |
if($new_order > $old_order){ |
|
137 |
// And we decrease the other ones |
|
138 |
for ($i=($old_order+1); $i <= ($new_order); $i++){ |
|
139 |
$dt = $ordered_tags[$i]; |
|
140 |
$dt->setTagOrder($dt->getTagOrder() - 1); |
|
141 |
} |
|
142 |
} |
|
143 |
else{ |
|
144 |
// And we increase the other ones |
|
145 |
for ($i=$new_order; $i <= ($old_order-1); $i++){ |
|
146 |
$dt = $ordered_tags[$i]; |
|
147 |
$dt->setTagOrder($dt->getTagOrder() + 1); |
|
148 |
} |
|
149 |
} |
|
150 |
// Save datas. |
|
151 |
$em->flush(); |
|
152 |
||
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
153 |
return $this->renderDocTags($id_doc, $req->get('wikitag_document_profile')); |
| 2 | 154 |
} |
155 |
||
156 |
/** |
|
| 43 | 157 |
* Action to remove a tag from a document tag list |
| 2 | 158 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
159 |
*/ |
|
160 |
public function removeTagFromListAction() |
|
161 |
{ |
|
162 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
163 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
164 |
// We get the DocumentTag meant to be deleted, and remove it. |
|
165 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
166 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
167 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
| 2 | 168 |
$em->remove($dt); |
169 |
$em->flush(); |
|
170 |
||
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
171 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 2 | 172 |
} |
173 |
||
174 |
/** |
|
|
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
|
175 |
* Modify the tag in the context of a tag list for one document |
| 29 | 176 |
* |
| 2 | 177 |
*/ |
178 |
public function modifyDocumentTagAction() |
|
179 |
{ |
|
180 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
181 |
$tag_label = $this->getRequest()->request->get('value'); |
|
182 |
$id_moved_tag = $this->getRequest()->request->get('id'); |
|
183 |
$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
|
184 |
if($tag_label!=$moved_tag->getLabel()){ |
| 2 | 185 |
// We get the DocumentTags |
186 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
187 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
188 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc); |
| 2 | 189 |
$found = false; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
190 |
foreach ($tags as $dt) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
191 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
192 |
if($dt->getTag()->getLabel()===$tag_label) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
193 |
{ |
| 2 | 194 |
$found = true; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
195 |
break; |
| 2 | 196 |
} |
197 |
} |
|
198 |
// If the label was found, we sent a bad request |
|
199 |
if($found==true){ |
|
200 |
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
|
201 |
} |
|
202 |
// We create the new tag or get the already existing tag. $tag, $revision_id, $created |
|
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
203 |
try { |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
204 |
$ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger')); |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
205 |
} |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
206 |
catch (\Exception $e){ |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
207 |
return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
208 |
} |
| 2 | 209 |
$tag = $ar[0]; |
210 |
$revision_id = $ar[1]; |
|
211 |
$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
|
212 |
|
| 2 | 213 |
// We get the DocumentTag and change its tag |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
214 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
215 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_moved_tag)); |
| 2 | 216 |
$dt->setTag($tag); |
217 |
$dt->setWikipediaRevisionId($revision_id); |
|
| 34 | 218 |
|
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
219 |
$score_res = $this->container->get('wiki_tag.search')->search($tag_label, array("externalId"=>$id_doc)); |
| 34 | 220 |
|
221 |
if(count($score_res)>0) |
|
222 |
{ |
|
223 |
$score = floatval($score_res[0]['score']); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
$score = 0.0; |
|
228 |
} |
|
229 |
$dt->setIndexNote($score); |
|
230 |
||
|
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
|
231 |
// 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
|
232 |
$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
|
233 |
$doc->setManualOrder(true); |
| 2 | 234 |
// We save the datas |
235 |
$em->flush(); |
|
236 |
} |
|
| 32 | 237 |
// We render the document's tags |
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
238 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 2 | 239 |
|
240 |
} |
|
241 |
||
242 |
/** |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
243 |
* 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. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
244 |
* The fields taken into account for calculating the score are defined in the wikitag configuration. |
| 2 | 245 |
*/ |
246 |
public function reorderTagDocumentAction() |
|
247 |
{ |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
248 |
$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
|
249 |
$res = $this->getDoctrine()->getRepository('WikiTagBundle:Document'); |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
250 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
251 |
$doc = $res->findOneByExternalId($id_doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
252 |
$doc->setManualOrder(false); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
253 |
$this->getDoctrine()->getEntityManager()->persist($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
254 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
255 |
$doc_service = $this->get('wiki_tag.document')->reorderTags($doc); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
256 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
257 |
$this->getDoctrine()->getEntityManager()->flush(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
258 |
|
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
259 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 2 | 260 |
} |
261 |
||
262 |
/** |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
263 |
* The action called to add a new tag (especially from the completion box) |
| 2 | 264 |
*/ |
265 |
public function addTagAction() |
|
266 |
{ |
|
267 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
268 |
$tag_label = $this->getRequest()->request->get('value'); |
|
| 63 | 269 |
|
270 |
||
271 |
try |
|
272 |
{ |
|
|
65
ba6b8e38d90e
Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
273 |
$this->get('wiki_tag.document')->addTags($id_doc, $tag_label); |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
274 |
} |
| 63 | 275 |
catch (WikiTagServiceException $e) |
276 |
{ |
|
277 |
return new Response(json_encode(array('error' => $e->getErrorCode(), 'message' => $e->getMessage())),$e->getCode()); |
|
| 2 | 278 |
} |
|
65
ba6b8e38d90e
Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
279 |
$this->getDoctrine()->getEntityManager()->flush(); |
| 2 | 280 |
|
|
65
ba6b8e38d90e
Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
281 |
|
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
282 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 2 | 283 |
} |
284 |
||
285 |
||
286 |
/** |
|
| 43 | 287 |
* 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. |
| 2 | 288 |
* |
289 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
290 |
*/ |
|
291 |
public function removeWpLinkAction() |
|
292 |
{ |
|
293 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
294 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
295 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
| 58 | 296 |
|
| 2 | 297 |
$em = $this->getDoctrine()->getEntityManager(); |
| 58 | 298 |
$query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)"); |
299 |
$query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized'])); |
|
300 |
$un_tag = null; |
|
301 |
$un_tags = $query->getResult(); |
|
302 |
if(count($un_tags)>0) { |
|
303 |
$un_tag = $un_tags[0]; |
|
304 |
} |
|
305 |
$un_tag_created = false; |
|
| 2 | 306 |
if(!$un_tag){ |
307 |
// Create another tag almost identical, without the W info |
|
308 |
$un_tag = new Tag(); |
|
309 |
$un_tag->setLabel($tag->getLabel()); |
|
310 |
$un_tag->setOriginalLabel($tag->getOriginalLabel()); |
|
311 |
$un_tag->setWikipediaUrl(null); |
|
312 |
$un_tag->setWikipediaPageId(null); |
|
| 43 | 313 |
$un_tag->setAlternativeWikipediaUrl(null); |
314 |
$un_tag->setAlternativeWikipediaPageId(null); |
|
315 |
$un_tag->setAlternativeLabel(null); |
|
| 2 | 316 |
$un_tag->setDbpediaUri(null); |
317 |
$un_tag->setCategory($tag->getCategory()); |
|
318 |
$un_tag->setAlias($tag->getAlias()); |
|
319 |
$un_tag->setPopularity($tag->getPopularity()); |
|
| 58 | 320 |
$un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']); |
| 43 | 321 |
$un_tag_created = true; |
| 58 | 322 |
$em->persist($un_tag); |
| 2 | 323 |
} |
| 58 | 324 |
elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result']) |
325 |
{ |
|
326 |
$un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']); |
|
327 |
$un_tag_created = true; |
|
328 |
$em->persist($un_tag); |
|
329 |
} |
|
330 |
||
331 |
||
| 2 | 332 |
|
| 13 | 333 |
if($id_doc && $id_doc!=""){ |
334 |
// We associate the unsemantized tag to the DocumentTag and save datas |
|
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
335 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
| 13 | 336 |
$dt->setTag($un_tag); |
337 |
$em->flush(); |
|
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
338 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 13 | 339 |
} |
340 |
else{ |
|
341 |
// Here we are in the context of tag list. |
|
| 58 | 342 |
if($un_tag_created==true){ |
| 13 | 343 |
$em->flush(); |
| 61 | 344 |
return $this->renderAllTags(); |
| 13 | 345 |
} |
346 |
else{ |
|
347 |
// The unsemantized version of the tag already exist, so we send an error. |
|
348 |
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); |
|
349 |
} |
|
350 |
} |
|
| 2 | 351 |
} |
352 |
||
353 |
||
354 |
/** |
|
| 43 | 355 |
* Action to update a tag category. |
356 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
| 2 | 357 |
*/ |
358 |
public function updateTagCategoryAction() |
|
359 |
{ |
|
360 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
361 |
$id_tag = $this->getRequest()->request->get('id'); |
|
362 |
$cat_label = $this->getRequest()->request->get('value'); |
|
363 |
// We get the Tag and update its category. |
|
364 |
$em = $this->getDoctrine()->getEntityManager(); |
|
365 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
366 |
if($cat_label==''){ |
|
367 |
$cat = null; |
|
368 |
$tag->nullCategory(); |
|
369 |
} |
|
370 |
else{ |
|
371 |
$cat = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOneBy(array('label' => $cat_label)); |
|
372 |
$tag->setCategory($cat); |
|
373 |
} |
|
374 |
$em->flush(); |
|
375 |
||
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
376 |
if($id_doc && $id_doc!=""){ |
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
377 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
378 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
379 |
else{ |
| 61 | 380 |
return $this->renderAllTags(); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
381 |
} |
| 2 | 382 |
} |
383 |
||
384 |
||
385 |
/** |
|
386 |
* |
|
387 |
* Generic render partial template |
|
388 |
* @param unknown_type $id_doc |
|
389 |
*/ |
|
|
53
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
390 |
public function renderDocTags($id_doc) |
| 2 | 391 |
{ |
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
392 |
// Get tags and render the table |
| 2 | 393 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
53
22377c9e2eae
First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
52
diff
changeset
|
394 |
return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc)); |
| 2 | 395 |
} |
| 7 | 396 |
|
397 |
||
398 |
/** |
|
| 43 | 399 |
* Action to update the tag alias. |
400 |
* |
|
| 7 | 401 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
402 |
*/ |
|
403 |
public function updateTagAliasAction() |
|
404 |
{ |
|
| 12 | 405 |
$id_tag = $this->getRequest()->request->get('id'); |
406 |
$alias = $this->getRequest()->request->get('value'); |
|
407 |
// We get the Tag and update its category. |
|
408 |
$em = $this->getDoctrine()->getEntityManager(); |
|
409 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
410 |
$tag->setAlias($alias); |
|
411 |
$em->flush(); |
|
412 |
||
| 7 | 413 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
| 12 | 414 |
if($id_doc && $id_doc!=""){ |
415 |
// In case we changed the alias from the document view |
|
|
49
e854d8cb376c
Finalise to implement the document profile with the list of columns.
cavaliet
parents:
47
diff
changeset
|
416 |
return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); |
| 12 | 417 |
} |
418 |
else{ |
|
419 |
// In case we changed the alias from the tag list. |
|
| 61 | 420 |
return $this->renderAllTags(); |
| 12 | 421 |
} |
| 7 | 422 |
} |
423 |
||
424 |
/** |
|
| 43 | 425 |
* List all tags, with pagination and search. |
426 |
* |
|
427 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
| 7 | 428 |
*/ |
429 |
public function allTagsAction() |
|
430 |
{ |
|
431 |
// $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
|
432 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
433 |
$searched = NULL; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
434 |
if(array_key_exists('searched', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
435 |
$searched = $_GET['searched']; |
| 7 | 436 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
437 |
// Number of tags per page |
| 8 | 438 |
$nb_by_page = 50; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
439 |
if(array_key_exists('nb_by_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
440 |
$nb_by_page = intval($_GET['nb_by_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
441 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
442 |
// Current page number |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
443 |
$num_page = 1; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
444 |
if(array_key_exists('num_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
445 |
$num_page = intval($_GET['num_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
446 |
} |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
447 |
// Sorting criteria |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
448 |
$sort = NULL; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
449 |
if(array_key_exists('sort', $_GET)){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
450 |
$sort = $_GET['sort']; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
451 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
452 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
453 |
// 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
|
454 |
$ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
| 16 | 455 |
//return new Response($ar); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
456 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
457 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
458 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
459 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
460 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
461 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
462 |
$pagerfanta = $ar[6]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
463 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
464 |
// 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
|
465 |
$last_page = $pagerfanta->getNbPages(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
466 |
$nb_total = $pagerfanta->getNbResults(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
467 |
$prev_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
468 |
if($pagerfanta->hasPreviousPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
469 |
$prev_page = $pagerfanta->getPreviousPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
470 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
471 |
$next_page = $last_page; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
472 |
if($pagerfanta->hasNextPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
473 |
$next_page = $pagerfanta->getNextPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
474 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
475 |
// 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
|
476 |
$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
|
477 |
$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
|
478 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
479 |
// 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
|
480 |
$conn = $this->getDoctrine()->getEntityManager()->getConnection(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
481 |
$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
|
482 |
$letters = $conn->query($sql)->fetchAll(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
483 |
$search_def = array(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
484 |
foreach ($letters as $l){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
485 |
$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
|
486 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
487 |
|
| 21 | 488 |
return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
489 |
array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, |
|
490 |
'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, |
|
491 |
'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
|
492 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
493 |
|
|
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
|
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 |
* 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
|
496 |
*/ |
|
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 |
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
|
498 |
{ |
|
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 |
$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
|
500 |
$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
|
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 new label. |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
503 |
try { |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
504 |
$this->updateTagWithNewLabel($moved_tag, $tag_label); |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
505 |
} |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
506 |
catch (\Exception $e){ |
| 63 | 507 |
return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500); |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
508 |
} |
|
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
|
509 |
// We render the tag list. |
| 61 | 510 |
return $this->renderAllTags(); |
|
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
|
511 |
} |
| 58 | 512 |
|
513 |
||
|
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
|
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 |
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label. |
| 29 | 516 |
* |
|
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
|
517 |
*/ |
|
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 |
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
|
519 |
{ |
|
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 |
$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
|
521 |
$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
|
522 |
// We update the tag label and its wikipedia info with the original label. |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
523 |
try { |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
524 |
$this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel()); |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
525 |
} |
|
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
526 |
catch (\Exception $e){ |
| 63 | 527 |
return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500); |
|
50
e967654e90cb
First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents:
49
diff
changeset
|
528 |
} |
|
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
|
529 |
|
|
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 render the tag list. |
| 61 | 531 |
return $this->renderAllTags(); |
|
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
|
532 |
} |
| 61 | 533 |
|
534 |
/** |
|
535 |
* Redo a Wikipedia search |
|
536 |
* @return \Symfony\Component\HttpFoundation\Response|\Symfony\Bundle\FrameworkBundle\Controller\Response |
|
537 |
*/ |
|
538 |
public function relaunchWpSearchAction() |
|
539 |
{ |
|
540 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
541 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_tag)); |
|
542 |
// We update the tag label and its wikipedia info with the original label. |
|
543 |
try { |
|
544 |
$this->updateTagWithNewLabel($tag, $tag->getLabel()); |
|
545 |
} |
|
546 |
catch (\Exception $e){ |
|
| 63 | 547 |
return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500); |
| 61 | 548 |
} |
549 |
||
550 |
// We render the tag list. |
|
551 |
return $this->renderAllTags(); |
|
552 |
} |
|
553 |
||
|
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
|
554 |
|
|
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
|
555 |
|
|
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
|
556 |
/** |
|
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
|
557 |
* 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
|
558 |
*/ |
|
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
|
559 |
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
|
560 |
{ |
|
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
|
561 |
if($tag!=null && $label!=null){ |
| 61 | 562 |
// We get the Wikipedia informations for the sent label |
563 |
$tag_label_normalized = WikiTagUtils::normalizeTag($label); |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
564 |
$wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized, null, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger')); |
| 61 | 565 |
$tag->setWikipediaInfo($wp_response); |
566 |
// Save datas. |
|
567 |
$em = $this->getDoctrine()->getEntityManager(); |
|
568 |
$em->persist($tag); |
|
569 |
$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
|
570 |
} |
|
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
|
571 |
} |
|
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
|
572 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
573 |
|
|
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 |
* 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
|
576 |
*/ |
| 61 | 577 |
public function renderAllTags($num_page=null, $nb_by_page=null, $sort=null, $searched=null) |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
578 |
{ |
| 61 | 579 |
if(is_null($num_page)) { |
580 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
581 |
} |
|
582 |
if(is_null($nb_by_page)) { |
|
583 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
584 |
} |
|
585 |
if(is_null($sort)) { |
|
586 |
$sort = $this->getRequest()->request->get('sort'); |
|
587 |
} |
|
588 |
if(is_null($searched)) { |
|
589 |
$searched = $this->getRequest()->request->get('searched'); |
|
590 |
} |
|
|
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
|
591 |
//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
|
592 |
$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
|
593 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
594 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
595 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
596 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
597 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
598 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
599 |
|
| 21 | 600 |
return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
601 |
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
|
602 |
'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
|
603 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
604 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
605 |
/** |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
606 |
* 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
|
607 |
*/ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
608 |
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
|
609 |
{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
610 |
// 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
|
611 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
612 |
if($searched==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
613 |
$searched = ""; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
614 |
} |
|
54
ec51b9f4695f
Upgrade column management with possibility to return to the initial columns. Little debug in all tag list.
cavaliet
parents:
53
diff
changeset
|
615 |
$searched = urldecode($searched); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
616 |
// Number of tags per page |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
617 |
if($nb_by_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
618 |
$nb_by_page = 50; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
619 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
620 |
// Current page number |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
621 |
if($num_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
622 |
$num_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
623 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
624 |
// We build the query. |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
625 |
$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
|
626 |
$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
|
627 |
$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
|
628 |
$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
|
629 |
$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
|
630 |
|
| 16 | 631 |
// We add the search string if necessary |
632 |
if($searched!=""){ |
|
633 |
// We replace "*" by "%", and doctrine wants ' to be ''. |
|
| 46 | 634 |
$qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", str_replace("+", " ", $searched)))."'"))); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
635 |
} |
| 16 | 636 |
//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
|
637 |
|
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
638 |
// We add the sorting criteria |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
639 |
if($sort==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
640 |
$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
|
641 |
$reverse_sort = "popa"; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
642 |
} |
| 26 | 643 |
//$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
|
644 |
switch($sort){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
645 |
case "popd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
646 |
$qb->addOrderBy('t.popularity','DESC'); |
| 26 | 647 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
648 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
649 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
650 |
$reverse_sort = "popa"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
651 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
652 |
case "popa": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
653 |
$qb->addOrderBy('t.popularity','ASC'); |
| 26 | 654 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
655 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
656 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
657 |
$reverse_sort = "popd"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
658 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
659 |
case "labd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
660 |
$qb->addOrderBy('t.normalizedLabel','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
661 |
$qb->addOrderBy('t.label','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
662 |
$reverse_sort = "laba"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
663 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
664 |
case "laba": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
665 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
666 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
667 |
$reverse_sort = "labd"; |
|
52
e804ae133f27
icon images in css, little debug, update document profile configuration
cavaliet
parents:
50
diff
changeset
|
668 |
break; |
| 26 | 669 |
case "nbd": |
670 |
$qb->addOrderBy('nb_docs','DESC'); |
|
671 |
$qb->addOrderBy('t.popularity','DESC'); |
|
672 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
673 |
$qb->addOrderBy('t.label','ASC'); |
|
674 |
$reverse_sort = "nba"; |
|
675 |
break; |
|
676 |
case "nba": |
|
677 |
$qb->addOrderBy('nb_docs','ASC'); |
|
678 |
$qb->addOrderBy('t.popularity','DESC'); |
|
679 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
680 |
$qb->addOrderBy('t.label','ASC'); |
|
681 |
$reverse_sort = "nbd"; |
|
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
682 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
683 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
684 |
|
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
685 |
// We paginate |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
686 |
$adapter = new DoctrineORMAdapter($qb); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
687 |
$pagerfanta = new Pagerfanta($adapter); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
688 |
$pagerfanta->setMaxPerPage($nb_by_page); // 10 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
689 |
$pagerfanta->setCurrentPage($num_page); // 1 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
690 |
$nb_total = $pagerfanta->getNbResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
691 |
$tags = $pagerfanta->getCurrentPageResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
692 |
$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page |
| 15 | 693 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
694 |
return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
| 7 | 695 |
} |
| 2 | 696 |
|
697 |
||
698 |
} |