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