8 * file that was distributed with this source code. |
8 * file that was distributed with this source code. |
9 */ |
9 */ |
10 |
10 |
11 namespace IRI\Bundle\WikiTagBundle\Controller; |
11 namespace IRI\Bundle\WikiTagBundle\Controller; |
12 |
12 |
|
13 use Doctrine\ORM\Query\ResultSetMapping; |
|
14 use Doctrine\DBAL\DriverManager; |
|
15 |
13 use IRI\Bundle\WikiTagBundle\Entity\DocumentTag; |
16 use IRI\Bundle\WikiTagBundle\Entity\DocumentTag; |
14 use IRI\Bundle\WikiTagBundle\Entity\Tag; |
17 use IRI\Bundle\WikiTagBundle\Entity\Tag; |
15 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
18 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
16 use Pagerfanta\Pagerfanta; |
19 use Pagerfanta\Pagerfanta; |
17 use Pagerfanta\Adapter\ArrayAdapter; |
20 use Pagerfanta\Adapter\ArrayAdapter; |
352 * List of all tags |
357 * List of all tags |
353 * TODO: Enter description here ... |
358 * TODO: Enter description here ... |
354 */ |
359 */ |
355 public function allTagsAction() |
360 public function allTagsAction() |
356 { |
361 { |
357 //$tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('urlStatus' => 2)); |
|
358 //$tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('id' => 10)); |
|
359 // We get/set all the parameters for the search and pagination. |
362 // We get/set all the parameters for the search and pagination. |
360 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
363 // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. |
361 // Searched string |
364 // Searched string |
362 $searched = ""; |
365 $searched = ""; |
363 if(array_key_exists('searched', $_GET)){ |
366 if(array_key_exists('searched', $_GET)){ |
372 $num_page = 1; |
375 $num_page = 1; |
373 if(array_key_exists('num_page', $_GET)){ |
376 if(array_key_exists('num_page', $_GET)){ |
374 $num_page = intval($_GET['num_page']); |
377 $num_page = intval($_GET['num_page']); |
375 } |
378 } |
376 |
379 |
377 |
|
378 |
|
379 // We build the query. |
380 // We build the query. |
380 $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); |
381 $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); |
381 $qb->select('t') |
382 $qb->select('t')->from('WikiTagBundle:Tag','t'); |
382 ->from('WikiTagBundle:Tag','t'); |
383 // We add the search string if necessary ('* bugs) |
383 // We add the search string if necessary |
384 if($searched!="" && $searched!="'*"){ |
384 if($searched!=""){ |
|
385 // We replace "*" by "%". |
385 // We replace "*" by "%". |
386 $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); |
386 $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); |
387 } |
387 } |
388 // W add the sorting criteria |
388 // We add the sorting criteria |
389 $sort = "popd"; // sort by descendent popularity by default. |
389 $sort = "popd"; // sort by descendent popularity by default. |
390 $reverse_sort = "popa"; |
390 $reverse_sort = "popa"; |
391 if(array_key_exists('sort', $_GET)){ |
391 if(array_key_exists('sort', $_GET)){ |
392 $sort = $_GET['sort']; |
392 $sort = $_GET['sort']; |
393 } |
393 } |
439 // We calculate start_index and end_index (tag number in the whole list) |
439 // We calculate start_index and end_index (tag number in the whole list) |
440 $start_index = 1 + (($num_page - 1) * $nb_by_page); |
440 $start_index = 1 + (($num_page - 1) * $nb_by_page); |
441 $end_index = min($nb_total, $start_index + $nb_by_page - 1); |
441 $end_index = min($nb_total, $start_index + $nb_by_page - 1); |
442 |
442 |
443 // We build the list of tags's first letters to make quick search. |
443 // We build the list of tags's first letters to make quick search. |
444 $search_def = array('A'=>'a*', 'B'=>'b*', 'C'=>'c*', 'D'=>'d*', 'E'=>'e*', 'F'=>'f*', 'G'=>'g*', 'H'=>'h*', 'I'=>'i*', 'J'=>'j*', 'K'=>'k*', 'L'=>'l*', |
444 $conn = $this->getDoctrine()->getEntityManager()->getConnection(); |
445 'M'=>'m*', 'N'=>'n*', 'O'=>'o*', 'P'=>'p*', 'Q'=>'q*', 'R'=>'r*', 'S'=>'s*', 'T'=>'t*', 'U'=>'u*', 'V'=>'v*', 'W'=>'w*', 'X'=>'x*', 'Y'=>'y*', 'Z'=>'z*'); |
445 $sql = "SELECT UPPER(SUBSTRING(normalized_label,1,1)) as fl FROM wikitag_tag GROUP BY fl ORDER BY fl"; |
|
446 $letters = $conn->query($sql)->fetchAll(); |
|
447 $search_def = array(); |
|
448 foreach ($letters as $l){ |
|
449 $search_def[$l[0]] = $l[0].WikiTagController::$SEARCH_STAR_CHARACTER; |
|
450 } |
446 |
451 |
447 return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
452 return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', |
448 array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, |
453 array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, |
449 'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, |
454 'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, |
450 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort)); |
455 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort)); |