# HG changeset patch # User ymh # Date 1319744254 -7200 # Node ID 985f1992895d004bd605144e8eac60be07489283 # Parent 7051e55a3131afd9fb536cce692e2f1637b1142d# Parent 876df98c9208927e8352220b3906f5b5f0f0ebf4 merged done diff -r 7051e55a3131 -r 985f1992895d Controller/WikiTagController.php --- a/Controller/WikiTagController.php Thu Oct 27 21:26:30 2011 +0200 +++ b/Controller/WikiTagController.php Thu Oct 27 21:37:34 2011 +0200 @@ -26,6 +26,7 @@ class WikiTagController extends Controller { private static $SEARCH_STAR_CHARACTER = "*"; + private static $ROUTE_FOR_DOCUMENTS_BY_TAG = "company_other"; /** * Fake index action @@ -429,6 +430,7 @@ // We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); + //return new Response($ar); $tags = $ar[0]; $num_page = $ar[1]; $nb_by_page = $ar[2]; @@ -464,7 +466,7 @@ 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, '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)); + 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => WikiTagController::$ROUTE_FOR_DOCUMENTS_BY_TAG)); } @@ -473,7 +475,8 @@ */ public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) { - // We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); + + //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); $tags = $ar[0]; $num_page = $ar[1]; @@ -483,7 +486,10 @@ $reverse_sort = $ar[5]; return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', - array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, 'reverse_sort' => $reverse_sort)); + array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, + 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => WikiTagController::$ROUTE_FOR_DOCUMENTS_BY_TAG)); + + return $this->getAllTags(); } @@ -508,12 +514,18 @@ // We build the query. $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); - $qb->select('t')->from('WikiTagBundle:Tag','t'); - // We add the search string if necessary ('* bugs) - if($searched!="" && $searched!="'*"){ - // We replace "*" by "%". - $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); + $qb->select('t', 'COUNT( dt.id ) AS nb_docs'); + $qb->from('WikiTagBundle:Tag','t'); + $qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag'); + $qb->addGroupBy('t.id'); + + // We add the search string if necessary + if($searched!=""){ + // We replace "*" by "%", and doctrine wants ' to be ''. + $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", $searched))."'"))); } + //return $qb->getDql(); + // We add the sorting criteria if($sort==NULL){ $sort = "popd"; // sort by descendent popularity by default. @@ -549,7 +561,6 @@ $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(); diff -r 7051e55a3131 -r 985f1992895d Model/Document.php --- a/Model/Document.php Thu Oct 27 21:26:30 2011 +0200 +++ b/Model/Document.php Thu Oct 27 21:37:34 2011 +0200 @@ -10,6 +10,8 @@ namespace IRI\Bundle\WikiTagBundle\Model; +use Doctrine\Common\Collections\ArrayCollection; + abstract class Document implements DocumentInterface { /** @@ -28,6 +30,11 @@ */ protected $externalId; + /** + * @var ArrayCollection $tags + */ + protected $tags; + /** * Get id @@ -78,4 +85,13 @@ return $this->externalId; } + /** + * TODO: (non-PHPdoc) + * @see IRI\Bundle\WikiTagBundle\Model.BaseDocumentInterface::getTags() + */ + function getTags() + { + return $this->tags; + } + } diff -r 7051e55a3131 -r 985f1992895d Model/DocumentInterface.php --- a/Model/DocumentInterface.php Thu Oct 27 21:26:30 2011 +0200 +++ b/Model/DocumentInterface.php Thu Oct 27 21:37:34 2011 +0200 @@ -11,6 +11,8 @@ namespace IRI\Bundle\WikiTagBundle\Model; +use Doctrine\Common\Collections\ArrayCollection; + interface DocumentInterface { /** diff -r 7051e55a3131 -r 985f1992895d Model/Tag.php --- a/Model/Tag.php Thu Oct 27 21:26:30 2011 +0200 +++ b/Model/Tag.php Thu Oct 27 21:37:34 2011 +0200 @@ -9,7 +9,9 @@ */ namespace IRI\Bundle\WikiTagBundle\Model; - use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; + use Doctrine\Common\Collections\ArrayCollection; + +use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; abstract class Tag implements TagInterface { @@ -70,6 +72,11 @@ */ protected $category; + /** + * @var ArrayCollection $documents + */ + protected $documents; + /** * Get id @@ -301,6 +308,16 @@ { return $this->category; } + + /** + * Get Documents + * + * @return ArrayCollection + */ + public function getDocuments() + { + return $this->documents; + } /** * Set category to Null diff -r 7051e55a3131 -r 985f1992895d Model/TagInterface.php --- a/Model/TagInterface.php Thu Oct 27 21:26:30 2011 +0200 +++ b/Model/TagInterface.php Thu Oct 27 21:37:34 2011 +0200 @@ -11,6 +11,8 @@ namespace IRI\Bundle\WikiTagBundle\Model; +use Doctrine\Common\Collections\ArrayCollection; + interface TagInterface { /** @@ -169,5 +171,18 @@ */ function getCategory(); + /** + * Get Documents + * + * @return ArrayCollection + */ + function getDocuments(); + + /** + * Nullify category + * + */ + function nullCategory(); + } \ No newline at end of file diff -r 7051e55a3131 -r 985f1992895d Resources/config/doctrine/Document.orm.yml --- a/Resources/config/doctrine/Document.orm.yml Thu Oct 27 21:26:30 2011 +0200 +++ b/Resources/config/doctrine/Document.orm.yml Thu Oct 27 21:37:34 2011 +0200 @@ -10,15 +10,11 @@ id: true generator: strategy: AUTO -# title: -# type: string -# length: '1024' -# description: -# type: text manualOrder: type: boolean column: manual_order -# externalId: -# type: string -# length: '1024' + oneToMany: + tags: + targetEntity: DocumentTag + mappedBy: document lifecycleCallbacks: { } diff -r 7051e55a3131 -r 985f1992895d Resources/config/doctrine/DocumentTag.orm.yml --- a/Resources/config/doctrine/DocumentTag.orm.yml Thu Oct 27 21:26:30 2011 +0200 +++ b/Resources/config/doctrine/DocumentTag.orm.yml Thu Oct 27 21:37:34 2011 +0200 @@ -23,6 +23,7 @@ manyToOne: tag: targetEntity: Tag + inversedBy: documents joinColumn: name: tag_id referencedColumnName: id @@ -30,6 +31,7 @@ onDelete: CASCADE document: targetEntity: Document + inversedBy: tags joinColumn: name: document_id referencedColumnName: id diff -r 7051e55a3131 -r 985f1992895d Resources/config/doctrine/Tag.orm.yml --- a/Resources/config/doctrine/Tag.orm.yml Thu Oct 27 21:26:30 2011 +0200 +++ b/Resources/config/doctrine/Tag.orm.yml Thu Oct 27 21:37:34 2011 +0200 @@ -46,4 +46,8 @@ manyToOne: category: targetEntity: Category + oneToMany: + documents: + targetEntity: DocumentTag + mappedBy: tag lifecycleCallbacks: { } diff -r 7051e55a3131 -r 985f1992895d Resources/views/WikiTag/TagListTable.html.twig --- a/Resources/views/WikiTag/TagListTable.html.twig Thu Oct 27 21:26:30 2011 +0200 +++ b/Resources/views/WikiTag/TagListTable.html.twig Thu Oct 27 21:37:34 2011 +0200 @@ -52,7 +52,8 @@ {% endif %} - {% for tag in tags %} + {% for ar in tags %} + {% set tag, nb_docs = ar.0, ar.nb_docs %} {{tag.id}} {{tag.label}} @@ -75,14 +76,11 @@ {{tag.label}} {% if tag.alias %}{{tag.alias}}{% endif %} - ? -{# - {% if tag.num_ds > 0 %} - {{tag.num_ds}} + {% if nb_docs > 0 %} + {{nb_docs}} {% else %} - {{tag.num_ds}} + {{nb_docs}} {% endif %} -#} {{tag.popularity}} {% endfor %}