Changeset 350

Show
Ignore:
Timestamp:
01/15/07 11:29:32 (2 years ago)
Author:
bballizlife
Message:

add method to jDaoFactoryBase : countBy($searchcond)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/dao/jDaoBase.class.php

    r328 r350  
    44 * @subpackage  dao 
    55 * @author      Laurent Jouanneau 
    6  * @contributor 
     6 * @contributor Loic Mathaud 
    77 * @copyright   2005-2006 Laurent Jouanneau 
     8 * @copyright   2007 Loic Mathaud 
    89 * @link        http://www.jelix.org 
    910 * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    272273    } 
    273274 
     275    /** 
     276     * return the number of records corresponding to the conditions stored into the 
     277     * jDaoConditions object. 
     278     * @author Loic Mathaud 
     279     * @copyright 2007 Loic Mathaud 
     280     * @since 1.0b2 
     281     * @param jDaoConditions $searchcond 
     282     * @return int the count 
     283     */ 
     284    public function countBy($searchcond) { 
     285        $query = 'SELECT COUNT(*) as c '.$this->_fromClause.$this->_whereClause; 
     286        if (!$searchcond->isEmpty ()){ 
     287            $query .= ($this->_whereClause !='' ? ' AND ' : ' WHERE '); 
     288            $query .= $this->_createConditionsClause($searchcond); 
     289        } 
     290        $rs  =  $this->_conn->query ($query); 
     291        $res =  $rs->fetch(); 
     292        return intval($res->c); 
     293    } 
     294     
    274295    abstract protected function _getPkWhereClauseForSelect($pk); 
    275296    abstract protected function _getPkWhereClauseForNonSelect($pk); 
Download in other formats: Unified Diff Zip Archive