471 /** |
471 /** |
472 * Generic render partial template for tag list |
472 * Generic render partial template for tag list |
473 */ |
473 */ |
474 public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
474 public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) |
475 { |
475 { |
476 // We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
476 |
|
477 //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
477 $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
478 $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); |
478 $tags = $ar[0]; |
479 $tags = $ar[0]; |
479 $num_page = $ar[1]; |
480 $num_page = $ar[1]; |
480 $nb_by_page = $ar[2]; |
481 $nb_by_page = $ar[2]; |
481 $searched = $ar[3]; |
482 $searched = $ar[3]; |
482 $sort = $ar[4]; |
483 $sort = $ar[4]; |
483 $reverse_sort = $ar[5]; |
484 $reverse_sort = $ar[5]; |
484 |
485 |
485 return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
486 return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', |
486 array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, 'reverse_sort' => $reverse_sort)); |
487 array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, 'reverse_sort' => $reverse_sort)); |
|
488 |
|
489 return $this->getAllTags(); |
487 } |
490 } |
488 |
491 |
489 |
492 |
490 /** |
493 /** |
491 * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) |
494 * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) |
506 $num_page = 1; |
509 $num_page = 1; |
507 } |
510 } |
508 |
511 |
509 // We build the query. |
512 // We build the query. |
510 $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); |
513 $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); |
511 $qb->select('t')->from('WikiTagBundle:Tag','t'); |
514 $qb->select('t', 'COUNT( dt.id ) AS nb_docs'); |
|
515 $qb->from('WikiTagBundle:Tag','t'); |
|
516 $qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag'); |
|
517 $qb->addGroupBy('t.id'); |
|
518 |
512 // We add the search string if necessary ('* bugs) |
519 // We add the search string if necessary ('* bugs) |
513 if($searched!="" && $searched!="'*"){ |
520 if($searched!="" && $searched!="'*"){ |
514 // We replace "*" by "%". |
521 // We replace "*" by "%". |
515 $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); |
522 $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); |
516 } |
523 } |
|
524 |
517 // We add the sorting criteria |
525 // We add the sorting criteria |
518 if($sort==NULL){ |
526 if($sort==NULL){ |
519 $sort = "popd"; // sort by descendent popularity by default. |
527 $sort = "popd"; // sort by descendent popularity by default. |
520 $reverse_sort = "popa"; |
528 $reverse_sort = "popa"; |
521 } |
529 } |
547 |
555 |
548 // We paginate |
556 // We paginate |
549 $adapter = new DoctrineORMAdapter($qb); |
557 $adapter = new DoctrineORMAdapter($qb); |
550 $pagerfanta = new Pagerfanta($adapter); |
558 $pagerfanta = new Pagerfanta($adapter); |
551 $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default |
559 $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default |
552 //$last_page = $pagerfanta->getNbPages(); |
|
553 $pagerfanta->setCurrentPage($num_page); // 1 by default |
560 $pagerfanta->setCurrentPage($num_page); // 1 by default |
554 $nb_total = $pagerfanta->getNbResults(); |
561 $nb_total = $pagerfanta->getNbResults(); |
555 $tags = $pagerfanta->getCurrentPageResults(); |
562 $tags = $pagerfanta->getCurrentPageResults(); |
556 $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page |
563 $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page |
557 |
|
558 return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
564 return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); |
559 } |
565 } |
560 |
566 |
561 |
567 |
562 } |
568 } |