Changeset 1137

Show
Ignore:
Timestamp:
10/28/08 16:45:02 (2 months ago)
Author:
julieni
Message:

ticket #724: jDao: autoremove of empty groups in jDaoConditions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0.x/lib/jelix/CREDITS

    r1106 r1137  
    2424Vincent Bonnard 
    2525 - bug fix in jXmlRpc.class.php (#190) 
    26   
     26 
    2727Cedric 
    2828 - bug fix in jFile::read 
     
    8181 - fixes about table_prefix in jDb (#702, #703) 
    8282 - jTcpdf: added default font for header and footer (#693) 
     83 - jDao: autoremove of empty groups in jDaoConditions (#724) 
    8384 
    8485Bastien Jaillot (aka bastnic) 
     
    9899Nicolas Lassalle 
    99100 - bug fix in jResponseBinary (#188) 
    100   
     101 
    101102Yannick Le Guédart (aka Torgan) 
    102103 - auth driver: jAuthDriverClass 
  • branches/1.0.x/lib/jelix/dao/jDaoConditions.class.php

    r727 r1137  
    44* @subpackage dao 
    55* @author     Croes Gérald, Laurent Jouanneau 
    6 * @contributor Laurent Jouanneau 
     6* @contributor Laurent Jouanneau, Julien Issler 
    77* @copyright  2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 
     8* @copyright  2008 Julien Issler 
    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). 
     
    4546        $this->parent = $parent; 
    4647        $this->glueOp = $glueOp; 
     48    } 
     49 
     50    public function isEmpty(){ 
     51        return empty($this->conditions) && empty($this->group); 
    4752    } 
    4853} 
     
    111116    function startGroup ($glueOp = 'AND'){ 
    112117        $cond= new jDaoCondition ($glueOp, $this->_currentCondition); 
    113         $this->_currentCondition->group[] = $cond; 
    114118        $this->_currentCondition = $cond; 
    115119    } 
     
    120124    function endGroup (){ 
    121125        if ($this->_currentCondition->parent !== null){ 
     126            if(!$this->_currentCondition->isEmpty()) 
     127                $this->_currentCondition->parent->group[] = $this->_currentCondition; 
    122128            $this->_currentCondition = $this->_currentCondition->parent; 
    123129        } 
     
    138144    } 
    139145} 
    140 ?> 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jdao.conditions.html_cli.php

    r851 r1137  
    106106    } 
    107107 
     108    function testEmptyRecursive(){ 
     109        $cond = new jDaoConditions(); 
     110        $cond->startGroup(); 
     111        $cond->startGroup('OR'); 
     112        $cond->endGroup(); 
     113        $cond->endGroup(); 
     114        $this->assertFalse($cond->hasConditions()); 
     115        $this->assertTrue($cond->isEmpty()); 
     116    } 
    108117 
    109  
     118    function testNonEmptyRecursive(){ 
     119        $cond = new jDaoConditions(); 
     120        $cond->startGroup(); 
     121        $cond->startGroup('OR'); 
     122        $cond->addCondition('test','=',1); 
     123        $cond->endGroup(); 
     124        $cond->endGroup(); 
     125        $this->assertTrue($cond->hasConditions()); 
     126        $this->assertFalse($cond->isEmpty()); 
     127    } 
    110128} 
    111  
    112  
    113 ?> 
  • trunk/lib/jelix/CREDITS

    r1130 r1137  
    3737 - jForms: radiobutton with value 0 should not get selected by default (#691) 
    3838 - jTcpdf: added default font for header and footer (#693) 
     39 - jDao: autoremove of empty groups in jDaoConditions (#724) 
    3940 
    4041Bastien Jaillot (aka bastnic) 
  • trunk/lib/jelix/dao/jDaoConditions.class.php

    r1026 r1137  
    44* @subpackage dao 
    55* @author     Croes Gérald, Laurent Jouanneau 
    6 * @contributor Laurent Jouanneau 
     6* @contributor Laurent Jouanneau, Julien Issler 
    77* @copyright  2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 
    88* @copyright  2008 Thomas 
     9* @copyright  2008 Julien Issler 
    910* This classes was get originally from the Copix project (CopixDAOSearchConditions, Copix 2.3dev20050901, http://www.copix.org) 
    1011* Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence). 
     
    4748        $this->glueOp = $glueOp; 
    4849    } 
     50 
     51    public function isEmpty(){ 
     52        return empty($this->conditions) && empty($this->group); 
     53    } 
    4954} 
    5055 
     
    6974    */ 
    7075    public $group = array (); 
    71      
     76 
    7277    /** 
    7378    * the condition we actually are browsing 
     
    100105        $this->group[] = $field_id; 
    101106    } 
    102      
     107 
    103108    /** 
    104109    * says if there are no conditions nor order 
     
    126131    function startGroup ($glueOp = 'AND'){ 
    127132        $cond= new jDaoCondition ($glueOp, $this->_currentCondition); 
    128         $this->_currentCondition->group[] = $cond; 
    129133        $this->_currentCondition = $cond; 
    130134    } 
     
    135139    function endGroup (){ 
    136140        if ($this->_currentCondition->parent !== null){ 
     141            if(!$this->_currentCondition->isEmpty()) 
     142                $this->_currentCondition->parent->group[] = $this->_currentCondition; 
    137143            $this->_currentCondition = $this->_currentCondition->parent; 
    138144        } 
     
    153159    } 
    154160} 
    155  
  • trunk/testapp/modules/jelix_tests/tests/jdao.conditions.html_cli.php

    r815 r1137  
    44* @subpackage  jelix_tests module 
    55* @author      Jouanneau Laurent 
    6 * @contributor 
     6* @contributor Julien Issler 
    77* @copyright   2006-2007 Jouanneau laurent 
     8* @copyright   2008 Julien Issler 
    89* @link        http://www.jelix.org 
    910* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    106107    } 
    107108 
     109    function testEmptyRecursive(){ 
     110        $cond = new jDaoConditions(); 
     111        $cond->startGroup(); 
     112        $cond->startGroup('OR'); 
     113        $cond->endGroup(); 
     114        $cond->endGroup(); 
     115        $this->assertFalse($cond->hasConditions()); 
     116        $this->assertTrue($cond->isEmpty()); 
     117    } 
    108118 
    109  
     119    function testNonEmptyRecursive(){ 
     120        $cond = new jDaoConditions(); 
     121        $cond->startGroup(); 
     122        $cond->startGroup('OR'); 
     123        $cond->addCondition('test','=',1); 
     124        $cond->endGroup(); 
     125        $cond->endGroup(); 
     126        $this->assertTrue($cond->hasConditions()); 
     127        $this->assertFalse($cond->isEmpty()); 
     128    } 
    110129} 
    111  
    112  
    113 ?> 
Download in other formats: Unified Diff Zip Archive