Entity/DocumentTagRepository.php
changeset 133 550862f07e6a
parent 74 901463f9b11c
equal deleted inserted replaced
132:077ea5b34caf 133:550862f07e6a
     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\Entity;
    11 namespace IRI\Bundle\WikiTagBundle\Entity;
    12 
    12 
       
    13 use Doctrine\ORM\AbstractQuery;
    13 use Doctrine\ORM\Query;
    14 use Doctrine\ORM\Query;
    14 
    15 
    15 use Doctrine\ORM\QueryBuilder;
    16 use Doctrine\ORM\QueryBuilder;
    16 
    17 
    17 use Doctrine\ORM\EntityRepository;
    18 use Doctrine\ORM\EntityRepository;
    24  * repository methods below.
    25  * repository methods below.
    25  */
    26  */
    26 class DocumentTagRepository extends EntityRepository
    27 class DocumentTagRepository extends EntityRepository
    27 {
    28 {
    28    /**
    29    /**
    29     *  Find ordered tags by document id
    30     * Find ordered document tags by document id.
       
    31     * Allow to control the hydration mode of the returned data (c.f. Doctrine\ORM\AbstractQuery::HYDRATE_*)
       
    32     *
       
    33     * @param mixed $doc_id The document id
       
    34     * @param int   $hydrationMode Value from Doctrine\ORM\AbstractQuery::HYDRATE_*. 
       
    35     * @return array (c.f from Doctrine\ORM\AbstractQuery::get_result())
    30     */
    36     */
    31     public function findOrderedTagsForDoc($doc_id)
    37     public function findOrderedTagsForDoc($doc_id, $hydrationMode=AbstractQuery::HYDRATE_OBJECT)
    32     {
    38     {
    33         return $this->getEntityManager()
    39         return $this->getEntityManager()
    34         ->createQuery("SELECT doctag FROM WikiTagBundle:DocumentTag doctag JOIN doctag.document doc WHERE doc.externalId=:doc_id ORDER BY doctag.tagOrder ASC")
    40         ->createQuery("SELECT doctag, tag FROM WikiTagBundle:DocumentTag doctag JOIN doctag.tag tag JOIN doctag.document doc WHERE doc.externalId=:doc_id ORDER BY doctag.tagOrder ASC")
    35         ->setParameter("doc_id", strval($doc_id))
    41         ->setParameter("doc_id", strval($doc_id))
    36         ->getResult();
    42         ->getResult($hydrationMode);
    37     }
    43     }
    38     
    44     
    39     private function findMaxOrderInUow($entityList, $doc_id, $max_order) {
    45     private function findMaxOrderInUow($entityList, $doc_id, $max_order) {
    40         foreach($entityList as $entity) {
    46         foreach($entityList as $entity) {
    41             if(is_a($entity, "\IRI\Bundle\WikiTagBundle\Model\DocumentTagInterface") &&
    47             if(is_a($entity, "\IRI\Bundle\WikiTagBundle\Model\DocumentTagInterface") &&