Ticket #579: 579-jDaoConditions-group.diff

File 579-jDaoConditions-group.diff, 2.0 kB (added by thomas, 4 months ago)
  • lib/jelix/dao/jDaoConditions.class.php

    old new  
    6464    public $order = array (); 
    6565 
    6666    /** 
     67    * the groups we wants the list to be 
     68    */ 
     69    public $group = array (); 
     70     
     71    /** 
    6772    * the condition we actually are browsing 
    6873    */ 
    6974    private $_currentCondition; 
     
    8691    } 
    8792 
    8893    /** 
     94     * add a group clause 
     95     * 
     96     * @param string $field_id  the property name used to group results 
     97     */ 
     98    function addItemGroup($field_id) { 
     99        $this->group[] = $field_id; 
     100    } 
     101     
     102    /** 
    89103    * says if there are no conditions nor order 
    90104    * @return boolean  false if there isn't condition 
    91105    */ 
  • lib/jelix/dao/jDaoFactoryBase.class.php

    old new  
    242242            $query .= ($this->_whereClause !='' ? ' AND ' : ' WHERE '); 
    243243            $query .= $this->_createConditionsClause($searchcond); 
    244244        } 
     245        $query.= $this->_createGroupClause($searchcond); 
    245246        $query.= $this->_createOrderClause($searchcond); 
    246247 
    247248        if($limitCount != 0){ 
     
    342343    } 
    343344 
    344345    /** 
     346     * @internal 
     347     */ 
     348    final protected function _createGroupClause($daocond) { 
     349        $group = array (); 
     350        $props = $this->getProperties(); 
     351        foreach ($daocond->group as $name) { 
     352            if (isset($props[$name])) { 
     353                $group[] = $name; 
     354            } 
     355        } 
     356         
     357        if (count ($group)) { 
     358            return ' GROUP BY '.implode(', ', $group); 
     359        } 
     360        return ''; 
     361    } 
     362     
     363    /** 
    345364     * @internal it don't support isExpr property of a condition because of security issue (SQL injection) 
    346365     * because the value could be provided by a form, it is escaped in any case 
    347366     */ 
Download in other formats: Original Format