Changeset 1015

Show
Ignore:
Timestamp:
07/11/08 23:53:07 (2 months ago)
Author:
bastnic
Message:

fixed #579 : add clause GROUP BY in jDao*, p=Thomas

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/CREDITS

    r1014 r1015  
    166166 - fixed bugs in jDao (#576, #643) 
    167167 - jDaoFactoryBase::countBy : allowing to do count on distinct fields (#580) 
     168 - JDaoConditions::addItemGroup : add clause group by (#579) 
    168169 
    169170Christian Tritten 
  • trunk/lib/jelix/dao/jDaoConditions.class.php

    r727 r1015  
    66* @contributor Laurent Jouanneau 
    77* @copyright  2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 
     8* @copyright  2008 Thomas 
    89* This classes was get originally from the Copix project (CopixDAOSearchConditions, Copix 2.3dev20050901, http://www.copix.org) 
    910* Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence). 
     
    6566 
    6667    /** 
     68    * the groups we wants the list to be 
     69    */ 
     70    public $group = array (); 
     71     
     72    /** 
    6773    * the condition we actually are browsing 
    6874    */ 
     
    8692    } 
    8793 
     94    /** 
     95     * add a group clause 
     96     * 
     97     * @param string $field_id  the property name used to group results 
     98     */ 
     99    function addItemGroup($field_id) { 
     100        $this->group[] = $field_id; 
     101    } 
     102     
    88103    /** 
    89104    * says if there are no conditions nor order 
  • trunk/lib/jelix/dao/jDaoFactoryBase.class.php

    r1007 r1015  
    99 * @copyright   2007 Loic Mathaud 
    1010 * @copyright   2007 Julien Issler 
     11 * @copyright   2008 Thomas 
    1112 * @link        http://www.jelix.org 
    1213 * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    243244            $query .= $this->_createConditionsClause($searchcond); 
    244245        } 
     246        $query.= $this->_createGroupClause($searchcond); 
    245247        $query.= $this->_createOrderClause($searchcond); 
    246248 
     
    349351    } 
    350352 
     353    /** 
     354     * @internal 
     355     */ 
     356    final protected function _createGroupClause($daocond) { 
     357        $group = array (); 
     358        $props = $this->getProperties(); 
     359        foreach ($daocond->group as $name) { 
     360            if (isset($props[$name])) { 
     361                $group[] = $name; 
     362            } 
     363        } 
     364         
     365        if (count ($group)) { 
     366            return ' GROUP BY '.implode(', ', $group); 
     367        } 
     368        return ''; 
     369    } 
     370     
    351371    /** 
    352372     * @internal it don't support isExpr property of a condition because of security issue (SQL injection) 
Download in other formats: Unified Diff Zip Archive