| author | cavaliet |
| Mon, 28 Nov 2011 10:34:24 +0100 | |
| changeset 46 | 6f643fc1de26 |
| parent 37 | 9ba15af20acc |
| child 47 | 34718ebfb3c0 |
| 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); |
|
|
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
|
62 |
return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list)); |
|
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
|
63 |
} |
|
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
|
64 |
|
|
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
|
65 |
/** |
|
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
|
66 |
* 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
|
67 |
*/ |
|
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
|
68 |
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
|
69 |
{ |
|
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
|
70 |
// 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
|
71 |
// 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
|
72 |
// 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
|
73 |
// 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
|
74 |
$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
|
75 |
$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
|
76 |
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
|
77 |
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
|
78 |
$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
|
79 |
} |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
80 |
else{ |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
81 |
$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
|
82 |
} |
|
540607cf3447
Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents:
35
diff
changeset
|
83 |
} |
|
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
|
84 |
return $this->render('WikiTagBundle:WikiTag:javascriptForContextSearch.html.twig', array('reactive_selectors' => $reactive_selectors)); |
| 2 | 85 |
} |
86 |
||
87 |
/** |
|
88 |
* Display a list of ordered tag for a document |
|
89 |
* @param integer $id_doc |
|
90 |
*/ |
|
| 46 | 91 |
public function documentTagsAction($id_doc, $profile_name="") |
| 2 | 92 |
{ |
| 46 | 93 |
// Management of profiles for the list of displayed columns and reorder tag button |
94 |
$profile_array = $this->container->getParameter("wiki_tag.document_list_profile"); |
|
95 |
$columns_array = null; |
|
96 |
if($profile_array!=null && $profile_name!=null && $profile_name!=""){ |
|
97 |
$columns_array = $profile_array[$profile_name]; |
|
98 |
} |
|
99 |
||
| 2 | 100 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
| 46 | 101 |
return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'profile_name' => $profile_name, 'columns' => $columns_array)); |
| 2 | 102 |
} |
103 |
||
104 |
/** |
|
105 |
* |
|
106 |
* TODO : Enter description here ... |
|
107 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
108 |
*/ |
|
109 |
public function tagUpDownAction() |
|
110 |
{ |
|
111 |
||
112 |
$req = $this->getRequest()->request; |
|
113 |
$id_doc = $req->get('wikitag_document_id'); |
|
114 |
// post vars new_order and old_order indicate the position (from 1) of the tag in the list. |
|
115 |
// NB : it is different from the DocumentTag.order in the database. |
|
116 |
$new_order = intval($req->get('new_order')) - 1; |
|
117 |
$old_order = intval($req->get('old_order')) - 1; |
|
118 |
// First we get the DocumentTags |
|
119 |
$em = $this->getDoctrine()->getEntityManager(); |
|
120 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
121 |
// We change the moved DocumentTag's order |
|
122 |
$new_dt_order = $ordered_tags[$new_order]->getTagOrder(); |
|
123 |
$moved_dt = $ordered_tags[$old_order]; |
|
124 |
$moved_dt->setTagOrder($new_dt_order); |
|
125 |
// We move the TaggedSheets's order |
|
126 |
if($new_order > $old_order){ |
|
127 |
// And we decrease the other ones |
|
128 |
for ($i=($old_order+1); $i <= ($new_order); $i++){ |
|
129 |
$dt = $ordered_tags[$i]; |
|
130 |
$dt->setTagOrder($dt->getTagOrder() - 1); |
|
131 |
} |
|
132 |
} |
|
133 |
else{ |
|
134 |
// And we increase the other ones |
|
135 |
for ($i=$new_order; $i <= ($old_order-1); $i++){ |
|
136 |
$dt = $ordered_tags[$i]; |
|
137 |
$dt->setTagOrder($dt->getTagOrder() + 1); |
|
138 |
} |
|
139 |
} |
|
140 |
// Save datas. |
|
141 |
$em->flush(); |
|
142 |
||
143 |
return $this->renderDocTags($id_doc); |
|
144 |
} |
|
145 |
||
146 |
/** |
|
147 |
* |
|
148 |
* TODO: Enter description here ... |
|
149 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
150 |
*/ |
|
151 |
public function removeTagFromListAction() |
|
152 |
{ |
|
153 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
154 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
155 |
// We get the DocumentTag meant to be deleted, and remove it. |
|
156 |
$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
|
157 |
//TODO: use external id |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
158 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
159 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
| 2 | 160 |
$em->remove($dt); |
161 |
$em->flush(); |
|
162 |
||
163 |
return $this->renderDocTags($id_doc); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
|
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
|
167 |
* Modify the tag in the context of a tag list for one document |
| 29 | 168 |
* |
| 2 | 169 |
*/ |
170 |
public function modifyDocumentTagAction() |
|
171 |
{ |
|
172 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
173 |
$tag_label = $this->getRequest()->request->get('value'); |
|
174 |
$id_moved_tag = $this->getRequest()->request->get('id'); |
|
175 |
$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
|
176 |
if($tag_label!=$moved_tag->getLabel()){ |
| 2 | 177 |
// We get the DocumentTags |
178 |
$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
|
179 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
180 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc); |
| 2 | 181 |
$found = false; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
182 |
foreach ($tags as $dt) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
183 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
184 |
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
|
185 |
{ |
| 2 | 186 |
$found = true; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
187 |
break; |
| 2 | 188 |
} |
189 |
} |
|
190 |
// If the label was found, we sent a bad request |
|
191 |
if($found==true){ |
|
192 |
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
|
193 |
} |
|
194 |
// We create the new tag or get the already existing tag. $tag, $revision_id, $created |
|
| 32 | 195 |
$ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine()); |
| 2 | 196 |
$tag = $ar[0]; |
197 |
$revision_id = $ar[1]; |
|
198 |
$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
|
199 |
|
| 2 | 200 |
// 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
|
201 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
202 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_moved_tag)); |
| 2 | 203 |
$dt->setTag($tag); |
204 |
$dt->setWikipediaRevisionId($revision_id); |
|
| 34 | 205 |
|
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
206 |
$score_res = $this->container->get('wiki_tag.search')->search($tag_label, array("externalId"=>$id_doc)); |
| 34 | 207 |
|
208 |
if(count($score_res)>0) |
|
209 |
{ |
|
210 |
$score = floatval($score_res[0]['score']); |
|
211 |
} |
|
212 |
else |
|
213 |
{ |
|
214 |
$score = 0.0; |
|
215 |
} |
|
216 |
$dt->setIndexNote($score); |
|
217 |
||
|
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
|
218 |
// 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
|
219 |
$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
|
220 |
$doc->setManualOrder(true); |
| 2 | 221 |
// We save the datas |
222 |
$em->flush(); |
|
223 |
} |
|
| 32 | 224 |
// We render the document's tags |
225 |
return $this->renderDocTags($id_doc); |
|
| 2 | 226 |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* |
|
231 |
* TODO : Enter description here ... |
|
| 7 | 232 |
* TODO : implement |
| 2 | 233 |
*/ |
234 |
public function reorderTagDocumentAction() |
|
235 |
{ |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
236 |
$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
|
237 |
$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
|
238 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
239 |
$doc = $res->findOneByExternalId($id_doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
240 |
$doc->setManualOrder(false); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
241 |
$this->getDoctrine()->getEntityManager()->persist($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
242 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
243 |
$search_service = $this->get('wiki_tag.search'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
244 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
245 |
$search_service->reorderTagsForDocument($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
246 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
247 |
$this->getDoctrine()->getEntityManager()->flush(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
248 |
|
| 2 | 249 |
return $this->renderDocTags($id_doc); |
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* |
|
254 |
* TODO: Enter description here ... |
|
255 |
*/ |
|
256 |
public function addTagAction() |
|
257 |
{ |
|
258 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
259 |
$tag_label = $this->getRequest()->request->get('value'); |
|
260 |
// We get the DocumentTags |
|
261 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
262 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc); |
| 2 | 263 |
$nb_tags = count($tags); |
264 |
$found = false; |
|
265 |
$i = 0; |
|
266 |
while($i<$nb_tags && $found==false){ |
|
267 |
$dt = $tags[$i]; |
|
268 |
if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){ |
|
269 |
$found = true; |
|
270 |
} |
|
271 |
$i++; |
|
272 |
} |
|
273 |
// If the label was found, we sent a bad request |
|
274 |
if($found==true){ |
|
275 |
//TODO : translation |
|
276 |
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); |
|
277 |
} |
|
| 8 | 278 |
// returns array($tag, $revision_id, $created) |
| 2 | 279 |
$ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) |
280 |
$tag = $ar[0]; |
|
281 |
$revision_id = $ar[1]; |
|
282 |
$created = $ar[2]; |
|
| 8 | 283 |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
284 |
$tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId())); |
| 2 | 285 |
$nb_tags = count($tags); |
286 |
||
287 |
if($created==true || $nb_tags==0){ |
|
288 |
$new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc); |
|
289 |
// The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned. |
|
290 |
$a1 = reset($new_order_ar); |
|
291 |
$new_order = intval(reset($a1)) + 1; |
|
292 |
// TODO: use a factory that returns an DocumentTagInterface |
|
293 |
$new_DT = new DocumentTag(); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
294 |
$new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc)); |
| 2 | 295 |
$new_DT->setTag($tag); |
296 |
$new_DT->setOriginalOrder($new_order); |
|
297 |
$new_DT->setTagOrder($new_order); |
|
298 |
$new_DT->setWikipediaRevisionId($revision_id); |
|
299 |
$em->persist($new_DT); |
|
300 |
$em->flush(); |
|
301 |
} |
|
302 |
||
303 |
return $this->renderDocTags($id_doc); |
|
304 |
} |
|
305 |
||
306 |
||
307 |
/** |
|
308 |
* |
|
309 |
* TODO: Enter description here ... |
|
310 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
311 |
*/ |
|
312 |
public function removeWpLinkAction() |
|
313 |
{ |
|
314 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
315 |
$id_tag = $this->getRequest()->request->get('tag_id'); |
|
316 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
317 |
//return new Response(var_dump(array($tag))); |
|
318 |
// We search if the unsemantized version of the tag already exist. |
|
319 |
$un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result'])); |
|
320 |
$em = $this->getDoctrine()->getEntityManager(); |
|
| 13 | 321 |
$un_tag_created = FALSE; |
| 2 | 322 |
if(!$un_tag){ |
323 |
// Create another tag almost identical, without the W info |
|
324 |
// TODO: use a factory that return a TagInterface |
|
325 |
$un_tag = new Tag(); |
|
326 |
$un_tag->setLabel($tag->getLabel()); |
|
327 |
$un_tag->setOriginalLabel($tag->getOriginalLabel()); |
|
328 |
$un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
|
329 |
$un_tag->setWikipediaUrl(null); |
|
330 |
$un_tag->setWikipediaPageId(null); |
|
331 |
$un_tag->setDbpediaUri(null); |
|
332 |
$un_tag->setCategory($tag->getCategory()); |
|
333 |
$un_tag->setAlias($tag->getAlias()); |
|
334 |
$un_tag->setPopularity($tag->getPopularity()); |
|
335 |
$em->persist($un_tag); |
|
| 13 | 336 |
$un_tag_created = TRUE; |
| 2 | 337 |
} |
338 |
||
| 13 | 339 |
if($id_doc && $id_doc!=""){ |
340 |
// 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
|
341 |
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag)); |
| 13 | 342 |
$dt->setTag($un_tag); |
343 |
$em->flush(); |
|
344 |
return $this->renderDocTags($id_doc); |
|
345 |
} |
|
346 |
else{ |
|
347 |
// Here we are in the context of tag list. |
|
348 |
if($un_tag_created==TRUE){ |
|
349 |
$em->flush(); |
|
350 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
351 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
352 |
$sort = $this->getRequest()->request->get('sort'); |
|
353 |
$searched = $this->getRequest()->request->get('searched'); |
|
354 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
355 |
} |
|
356 |
else{ |
|
357 |
// The unsemantized version of the tag already exist, so we send an error. |
|
358 |
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); |
|
359 |
} |
|
360 |
} |
|
| 2 | 361 |
} |
362 |
||
363 |
||
364 |
/** |
|
365 |
* |
|
366 |
* TODO: Enter description here ... |
|
367 |
*/ |
|
368 |
public function updateTagCategoryAction() |
|
369 |
{ |
|
370 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
|
371 |
$id_tag = $this->getRequest()->request->get('id'); |
|
372 |
$cat_label = $this->getRequest()->request->get('value'); |
|
373 |
// We get the Tag and update its category. |
|
374 |
$em = $this->getDoctrine()->getEntityManager(); |
|
375 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
376 |
if($cat_label==''){ |
|
377 |
$cat = null; |
|
378 |
$tag->nullCategory(); |
|
379 |
} |
|
380 |
else{ |
|
381 |
$cat = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOneBy(array('label' => $cat_label)); |
|
382 |
$tag->setCategory($cat); |
|
383 |
} |
|
384 |
$em->flush(); |
|
385 |
||
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
386 |
if($id_doc && $id_doc!=""){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
387 |
return $this->renderDocTags($id_doc); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
388 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
389 |
else{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
390 |
$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
|
391 |
$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
|
392 |
$sort = $this->getRequest()->request->get('sort'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
393 |
$searched = $this->getRequest()->request->get('searched'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
394 |
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
|
395 |
} |
| 2 | 396 |
} |
397 |
||
398 |
||
399 |
/** |
|
400 |
* |
|
401 |
* Generic render partial template |
|
402 |
* @param unknown_type $id_doc |
|
403 |
*/ |
|
404 |
public function renderDocTags($id_doc) |
|
405 |
{ |
|
406 |
$ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc); |
|
| 46 | 407 |
return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => null)); |
| 2 | 408 |
} |
| 7 | 409 |
|
410 |
||
411 |
/** |
|
412 |
* |
|
413 |
* TODO : Enter description here ... |
|
414 |
* TODO : implement |
|
415 |
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response |
|
416 |
*/ |
|
417 |
public function updateTagAliasAction() |
|
418 |
{ |
|
| 12 | 419 |
$id_tag = $this->getRequest()->request->get('id'); |
420 |
$alias = $this->getRequest()->request->get('value'); |
|
421 |
// We get the Tag and update its category. |
|
422 |
$em = $this->getDoctrine()->getEntityManager(); |
|
423 |
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag); |
|
424 |
$tag->setAlias($alias); |
|
425 |
$em->flush(); |
|
426 |
||
| 7 | 427 |
$id_doc = $this->getRequest()->request->get('wikitag_document_id'); |
| 12 | 428 |
if($id_doc && $id_doc!=""){ |
429 |
// In case we changed the alias from the document view |
|
430 |
return $this->renderDocTags($id_doc); |
|
431 |
} |
|
432 |
else{ |
|
433 |
// In case we changed the alias from the tag list. |
|
434 |
$num_page = $this->getRequest()->request->get('num_page'); |
|
435 |
$nb_by_page = $this->getRequest()->request->get('nb_by_page'); |
|
436 |
$sort = $this->getRequest()->request->get('sort'); |
|
437 |
$searched = $this->getRequest()->request->get('searched'); |
|
438 |
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); |
|
439 |
} |
|
| 7 | 440 |
} |
441 |
||
442 |
/** |
|
443 |
* List of all tags |
|
444 |
* TODO: Enter description here ... |
|
445 |
*/ |
|
446 |
public function allTagsAction() |
|
447 |
{ |
|
448 |
// $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
|
449 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
450 |
$searched = NULL; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
451 |
if(array_key_exists('searched', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
452 |
$searched = $_GET['searched']; |
| 7 | 453 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
454 |
// Number of tags per page |
| 8 | 455 |
$nb_by_page = 50; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
456 |
if(array_key_exists('nb_by_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
457 |
$nb_by_page = intval($_GET['nb_by_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
458 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
459 |
// Current page number |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
460 |
$num_page = 1; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
461 |
if(array_key_exists('num_page', $_GET)){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
462 |
$num_page = intval($_GET['num_page']); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
463 |
} |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
464 |
// Sorting criteria |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
465 |
$sort = NULL; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
466 |
if(array_key_exists('sort', $_GET)){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
467 |
$sort = $_GET['sort']; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
468 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
469 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
470 |
// 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
|
471 |
$ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
| 16 | 472 |
//return new Response($ar); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
473 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
474 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
475 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
476 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
477 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
478 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
479 |
$pagerfanta = $ar[6]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
480 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
481 |
// 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
|
482 |
$last_page = $pagerfanta->getNbPages(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
483 |
$nb_total = $pagerfanta->getNbResults(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
484 |
$prev_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
485 |
if($pagerfanta->hasPreviousPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
486 |
$prev_page = $pagerfanta->getPreviousPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
487 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
488 |
$next_page = $last_page; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
489 |
if($pagerfanta->hasNextPage()){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
490 |
$next_page = $pagerfanta->getNextPage(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
491 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
492 |
// 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
|
493 |
$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
|
494 |
$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
|
495 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
496 |
// 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
|
497 |
$conn = $this->getDoctrine()->getEntityManager()->getConnection(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
498 |
$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
|
499 |
$letters = $conn->query($sql)->fetchAll(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
500 |
$search_def = array(); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
501 |
foreach ($letters as $l){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
502 |
$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
|
503 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
504 |
|
| 21 | 505 |
return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
506 |
array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, |
|
507 |
'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, |
|
508 |
'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
|
509 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
510 |
|
|
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 |
/** |
|
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 |
* 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
|
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 |
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
|
515 |
{ |
|
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 |
$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
|
517 |
$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
|
518 |
$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
|
519 |
// 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
|
520 |
$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
|
521 |
|
|
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 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
|
523 |
$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
|
524 |
$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
|
525 |
$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
|
526 |
$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
|
527 |
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
|
528 |
} |
|
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 |
/** |
|
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 |
* |
|
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 |
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label. |
| 29 | 533 |
* |
|
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
|
534 |
*/ |
|
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 |
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
|
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 |
$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
|
538 |
$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
|
539 |
// We update the tag label and its wikipedia info with the original label. |
| 46 | 540 |
return $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel()); |
|
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
|
541 |
|
|
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 |
// 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
|
543 |
$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
|
544 |
$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
|
545 |
$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
|
546 |
$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
|
547 |
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
|
548 |
} |
|
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
|
549 |
|
|
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
|
550 |
|
|
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
|
551 |
/** |
|
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
|
552 |
* 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
|
553 |
*/ |
|
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 |
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
|
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 |
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
|
557 |
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
|
558 |
// 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
|
559 |
$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
|
560 |
$wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
| 46 | 561 |
//return new Response(var_dump($wp_response)); |
562 |
$new_label = $tag_label_normalized; |
|
|
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
|
563 |
$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
|
564 |
$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
|
565 |
$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
|
566 |
$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
|
567 |
$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
|
568 |
// 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
|
569 |
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
|
570 |
$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
|
571 |
} |
| 46 | 572 |
else{ |
573 |
$tag->setLabel($tag_label_normalized); |
|
574 |
} |
|
575 |
if(!is_null($status)){ |
|
|
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
|
576 |
$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
|
577 |
} |
| 46 | 578 |
else{ |
579 |
$tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']); |
|
580 |
} |
|
|
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
|
581 |
$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
|
582 |
$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
|
583 |
$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
|
584 |
// 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
|
585 |
$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
|
586 |
$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
|
587 |
$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
|
588 |
} |
|
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
|
589 |
} |
|
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
|
590 |
} |
|
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
|
591 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
592 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
593 |
/** |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
594 |
* 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
|
595 |
*/ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
596 |
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
|
597 |
{ |
|
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
|
598 |
|
|
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
|
599 |
//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
|
600 |
$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
|
601 |
$tags = $ar[0]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
602 |
$num_page = $ar[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
603 |
$nb_by_page = $ar[2]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
604 |
$searched = $ar[3]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
605 |
$sort = $ar[4]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
606 |
$reverse_sort = $ar[5]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
607 |
|
| 21 | 608 |
return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
609 |
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
|
610 |
'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
|
611 |
|
|
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
|
612 |
return $this->getAllTags(); |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
613 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
614 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
615 |
|
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
616 |
/** |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
617 |
* 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
|
618 |
*/ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
619 |
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
|
620 |
{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
621 |
// 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
|
622 |
// Searched string |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
623 |
if($searched==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
624 |
$searched = ""; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
625 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
626 |
// Number of tags per page |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
627 |
if($nb_by_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
628 |
$nb_by_page = 50; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
629 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
630 |
// Current page number |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
631 |
if($num_page==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
632 |
$num_page = 1; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
633 |
} |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
634 |
|
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
635 |
// We build the query. |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
636 |
$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
|
637 |
$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
|
638 |
$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
|
639 |
$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
|
640 |
$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
|
641 |
|
| 16 | 642 |
// We add the search string if necessary |
643 |
if($searched!=""){ |
|
644 |
// We replace "*" by "%", and doctrine wants ' to be ''. |
|
| 46 | 645 |
$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
|
646 |
} |
| 16 | 647 |
//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
|
648 |
|
|
10
a1234ceba912
add first letter list. It works but searching ' bugs.
cavaliet
parents:
9
diff
changeset
|
649 |
// We add the sorting criteria |
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
650 |
if($sort==NULL){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
651 |
$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
|
652 |
$reverse_sort = "popa"; |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
653 |
} |
| 26 | 654 |
//$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
|
655 |
switch($sort){ |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
656 |
case "popd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
657 |
$qb->addOrderBy('t.popularity','DESC'); |
| 26 | 658 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
659 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
660 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
661 |
$reverse_sort = "popa"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
662 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
663 |
case "popa": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
664 |
$qb->addOrderBy('t.popularity','ASC'); |
| 26 | 665 |
$qb->addOrderBy('nb_docs','DESC'); |
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
666 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
667 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
668 |
$reverse_sort = "popd"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
669 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
670 |
case "labd": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
671 |
$qb->addOrderBy('t.normalizedLabel','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
672 |
$qb->addOrderBy('t.label','DESC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
673 |
$reverse_sort = "laba"; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
674 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
675 |
case "laba": |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
676 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
677 |
$qb->addOrderBy('t.label','ASC'); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
678 |
$reverse_sort = "labd"; |
| 26 | 679 |
case "nbd": |
680 |
$qb->addOrderBy('nb_docs','DESC'); |
|
681 |
$qb->addOrderBy('t.popularity','DESC'); |
|
682 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
683 |
$qb->addOrderBy('t.label','ASC'); |
|
684 |
$reverse_sort = "nba"; |
|
685 |
break; |
|
686 |
case "nba": |
|
687 |
$qb->addOrderBy('nb_docs','ASC'); |
|
688 |
$qb->addOrderBy('t.popularity','DESC'); |
|
689 |
$qb->addOrderBy('t.normalizedLabel','ASC'); |
|
690 |
$qb->addOrderBy('t.label','ASC'); |
|
691 |
$reverse_sort = "nbd"; |
|
|
9
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
692 |
break; |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
693 |
} |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
694 |
|
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
695 |
// We paginate |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
696 |
$adapter = new DoctrineORMAdapter($qb); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
697 |
$pagerfanta = new Pagerfanta($adapter); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
698 |
$pagerfanta->setMaxPerPage($nb_by_page); // 10 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
699 |
$pagerfanta->setCurrentPage($num_page); // 1 by default |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
700 |
$nb_total = $pagerfanta->getNbResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
701 |
$tags = $pagerfanta->getCurrentPageResults(); |
|
cc32af725176
first step for tag list and add Pagerfanta for paginator
cavaliet
parents:
8
diff
changeset
|
702 |
$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page |
| 15 | 703 |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
10
diff
changeset
|
704 |
return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
| 7 | 705 |
} |
| 2 | 706 |
|
707 |
||
708 |
} |