# HG changeset patch # User cavaliet # Date 1319209854 -7200 # Node ID cc32af72517618a30f426fe5fba0572ad0a50035 # Parent 7d2fb5d7c9fff6d099ab7d154e7b520bec6773e3 first step for tag list and add Pagerfanta for paginator diff -r 7d2fb5d7c9ff -r cc32af725176 Controller/WikiTagController.php --- a/Controller/WikiTagController.php Thu Oct 20 18:35:33 2011 +0200 +++ b/Controller/WikiTagController.php Fri Oct 21 17:10:54 2011 +0200 @@ -13,6 +13,9 @@ use IRI\Bundle\WikiTagBundle\Entity\DocumentTag; use IRI\Bundle\WikiTagBundle\Entity\Tag; use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; +use Pagerfanta\Pagerfanta; +use Pagerfanta\Adapter\ArrayAdapter; +use Pagerfanta\Adapter\DoctrineORMAdapter; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; @@ -351,25 +354,100 @@ */ public function allTagsAction() { - $tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('id' => '10')); + //$tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('urlStatus' => 2)); + //$tags = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findBy(array('id' => 10)); + // We get/set all the parameters for the search and pagination. // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. - $toto = null; - if(array_key_exists('toto', $_GET)){ - $toto = $_GET['toto']; + // Searched string + $searched = ""; + if(array_key_exists('searched', $_GET)){ + $searched = $_GET['searched']; } - $searched = "truc"; - $search_def = array('A', 'B'); + // Number of tags per page $nb_by_page = 50; - $sort = "p+"; - $current_page = NULL;// avec start_index et end_index - $nb_total = "truc";// nb de pages - $num_page = 2; - $last_page = 4; + if(array_key_exists('nb_by_page', $_GET)){ + $nb_by_page = intval($_GET['nb_by_page']); + } + // Current page number + $num_page = 1; + if(array_key_exists('num_page', $_GET)){ + $num_page = intval($_GET['num_page']); + } + + + + // We build the query. + $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); + $qb->select('t') + ->from('WikiTagBundle:Tag','t'); + // We add the search string if necessary + if($searched!=""){ + // We replace "*" by "%". + $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); + } + // W add the sorting criteria + $sort = "popd"; // sort by descendent popularity by default. + $reverse_sort = "popa"; + if(array_key_exists('sort', $_GET)){ + $sort = $_GET['sort']; + } + $sort_query = "t.popularity DESC t.normalizedLabel ASC t.label ASC"; + switch($sort){ + case "popd": + $qb->addOrderBy('t.popularity','DESC'); + $qb->addOrderBy('t.normalizedLabel','ASC'); + $qb->addOrderBy('t.label','ASC'); + $reverse_sort = "popa"; + break; + case "popa": + $qb->addOrderBy('t.popularity','ASC'); + $qb->addOrderBy('t.normalizedLabel','ASC'); + $qb->addOrderBy('t.label','ASC'); + $reverse_sort = "popd"; + break; + case "labd": + $qb->addOrderBy('t.normalizedLabel','DESC'); + $qb->addOrderBy('t.label','DESC'); + $reverse_sort = "laba"; + break; + case "laba": + $qb->addOrderBy('t.normalizedLabel','ASC'); + $qb->addOrderBy('t.label','ASC'); + $reverse_sort = "labd"; + break; + } + + // We paginate + $adapter = new DoctrineORMAdapter($qb); + $pagerfanta = new Pagerfanta($adapter); + $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default + $last_page = $pagerfanta->getNbPages(); + $pagerfanta->setCurrentPage($num_page); // 1 by default + $nb_total = $pagerfanta->getNbResults(); + $tags = $pagerfanta->getCurrentPageResults(); + $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page + + // We get the previous and next page number $prev_page = 1; - $next_page = 3; + if($pagerfanta->hasPreviousPage()){ + $prev_page = $pagerfanta->getPreviousPage(); + } + $next_page = $last_page; + if($pagerfanta->hasNextPage()){ + $next_page = $pagerfanta->getNextPage(); + } + // We calculate start_index and end_index (tag number in the whole list) + $start_index = 1 + (($num_page - 1) * $nb_by_page); + $end_index = min($nb_total, $start_index + $nb_by_page - 1); + + // We build the list of tags's first letters to make quick search. + $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*', + '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*'); + return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', - array('tags' => $tags, 'searched' => $searched, '$search_def' => $search_def, '$nb_by_page' => $nb_by_page, '$sort' => $sort, '$current_page' => $current_page, - '$nb_total' => $nb_total, '$num_page' => $num_page, '$last_page' => $last_page, '$prev_page' => $prev_page, '$next_page' => $next_page)); + array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, + 'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, + 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort)); } diff -r 7d2fb5d7c9ff -r cc32af725176 Resources/views/WikiTag/TagList.html.twig --- a/Resources/views/WikiTag/TagList.html.twig Thu Oct 20 18:35:33 2011 +0200 +++ b/Resources/views/WikiTag/TagList.html.twig Fri Oct 21 17:10:54 2011 +0200 @@ -1,52 +1,45 @@
-

Chercher : -{#{% for s in search_def %} -{{s.0}} -{% endfor %}#} - -

-

Tags {#{{ current_page.start_index }} à {{ current_page.end_index }} sur {{ nb_total }}#}

-

-{# +

Chercher : + {% for k,v in search_def %} + {{k}} + {% endfor %} + +

+

Tags {{ start_index }} à {{ end_index }} sur {{ nb_total }}

+

{% if searched and searched != "" %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >>

+ >   + >>

{% else %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >> + >   + >>

{% endif %}

-#} -
-{# - +
+{# - - -#} +#}
{% include "WikiTagBundle:WikiTag:TagListTable.html.twig" %}

-{# {% if searched and searched != "" %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >>

+ >   + >>

{% else %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >> + >   + >>

{% endif %}

-#}
\ No newline at end of file diff -r 7d2fb5d7c9ff -r cc32af725176 Resources/views/WikiTag/TagListTable.html.twig --- a/Resources/views/WikiTag/TagListTable.html.twig Thu Oct 20 18:35:33 2011 +0200 +++ b/Resources/views/WikiTag/TagListTable.html.twig Fri Oct 21 17:10:54 2011 +0200 @@ -1,1 +1,90 @@ -DUDE 2 \ No newline at end of file +{% block tag_table %} + + + + + + + + + + + + {% for tag in tags %} + + + + + + + + + + + + {% endfor %} +
id + {% if sort != "laba" and sort != "labd" %} + {% if searched and searched != "" %} + label + {% else %} + label + {% endif %} + {% else %} + label   + {% if searched and searched != "" %} + + {% else %} + + {% endif %} + {% if sort == "laba" %} + + {% else %} + + {% endif %} + + {% endif %} + original_labelLien WLien DCatégorieSupprimer
le lien W
AliasNb de
fiches
+ {% if sort != "popa" and sort != "popd" %} + {% if searched and searched != "" %} + Popularité + {% else %} + Popularité + {% endif %} + {% else %} + Popularité   + {% if searched and searched != "" %} + + {% else %} + + {% endif %} + {% if sort == "popa" %} + + {% else %} + + {% endif %} + + {% endif %} +
{{tag.id}}{{tag.label}}{{tag.originallabel}} + {% if tag.wikipediaurl and tag.wikipediaurl != "" %} + + {% else %} + + {% endif %} + + {% if tag.dbpediauri and tag.dbpediauri != "" %} + + {% else %} +   + {% endif %} + {% if tag.category %}{{ tag.category.label }}{% endif %}{{tag.label}}{% if tag.alias %}{{tag.alias}}{% endif %} + ? +{# + {% if tag.num_ds > 0 %} + {{tag.num_ds}} + {% else %} + {{tag.num_ds}} + {% endif %} +#} + {{tag.popularity}}
+{% endblock %} \ No newline at end of file diff -r 7d2fb5d7c9ff -r cc32af725176 Resources/views/WikiTag/tagTable.html.twig --- a/Resources/views/WikiTag/tagTable.html.twig Thu Oct 20 18:35:33 2011 +0200 +++ b/Resources/views/WikiTag/tagTable.html.twig Fri Oct 21 17:10:54 2011 +0200 @@ -45,13 +45,3 @@ {{t.tag.label}} {% endfor %} - - {#

All the tags :

- - - - {% for tag in tags %} - - - {% endfor %} -
IDLABELCAT NAME
{{ tag.id }}{{ tag.label }}{% if tag.category %}{{ tag.category.label }}{% endif %}
#} diff -r 7d2fb5d7c9ff -r cc32af725176 Utils/WikiTagUtils.php --- a/Utils/WikiTagUtils.php Thu Oct 20 18:35:33 2011 +0200 +++ b/Utils/WikiTagUtils.php Fri Oct 21 17:10:54 2011 +0200 @@ -98,6 +98,8 @@ } $tag_label = trim($tag_label);//tag.strip() $tag_label = str_replace("_", " ", $tag_label);//tag.replace("_", " ") + $tag_label = str_replace("Œ", "oe", $tag_label); + $tag_label = str_replace("œ", "oe", $tag_label); $tag_label = preg_replace('/\s+/', ' ', $tag_label);//" ".join(tag.split()) $tag_label = ucfirst($tag_label);//tag[0].upper() + tag[1:] return $tag_label;