Ticket #580: 580-jDaoConditions-countBy-distinct.diff

File 580-jDaoConditions-countBy-distinct.diff, 1.1 kB (added by thomas, 8 months ago)
  • lib/jelix/dao/jDaoFactoryBase.class.php

    old new  
    262262     * @param jDaoConditions $searchcond 
    263263     * @return int the count 
    264264     */ 
    265     final public function countBy($searchcond) { 
    266         $query = 'SELECT COUNT(*) as c '.$this->_fromClause.$this->_whereClause; 
     265    final public function countBy($searchcond, $distinct=null) { 
     266        $count = '*'; 
     267        if ($distinct !== null) { 
     268            $props = $this->getProperties(); 
     269            if (isset($props[$distinct])) 
     270                $count = 'DISTINCT '.$this->_tables[$props[$distinct]['table']]['realname'].'.'.$props[$distinct]['fieldName']; 
     271        } 
     272         
     273        $query = 'SELECT COUNT('.$count.') as c '.$this->_fromClause.$this->_whereClause; 
    267274        if ($searchcond->hasConditions ()){ 
    268275            $query .= ($this->_whereClause !='' ? ' AND ' : ' WHERE '); 
    269276            $query .= $this->_createConditionsClause($searchcond); 
Download in other formats: Original Format