Changeset 596

Show
Ignore:
Timestamp:
09/28/07 16:26:51 (1 year ago)
Author:
laurentj
Message:

ticket #280: added table headers in the crud_list.tpl
added property on jControllerDaoCrud to specify the records order
fixed a bug in jDaoBase::findBy : order clause was not generated

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0beta3.x/lib/jelix/controllers/jControllerDaoCrud.class.php

    r595 r596  
    4141    protected $propertiesForList = array(); 
    4242 
     43 
     44    /** 
     45     * list of properties which serve to order the record list 
     46     * if empty list (default), the list is in a natural order 
     47     * keys are properties name, and values are "asc" or "desc" 
     48     * @var array 
     49     */ 
     50    protected $propertiesForRecordsOrder = array(); 
     51 
    4352    /** 
    4453     * template to display the list of records 
     
    133142 
    134143        $dao = jDao::get($this->dao, $this->dbProfil); 
    135         $results = $dao->findBy(jDao::createConditions(),$offset,$this->listPageSize); 
     144 
     145        $cond = jDao::createConditions(); 
     146        foreach ($this->propertiesForRecordsOrder as $p=>$order) { 
     147            $cond->addItemOrder($p, $order); 
     148        } 
     149 
     150        $results = $dao->findBy($cond,$offset,$this->listPageSize); 
    136151        $pk = $dao->getPrimaryKeyNames(); 
    137152 
    138         jForms::destroy($this->form, $this->pseudoFormId); 
    139  
     153        // we're using a form to have the portunity to have 
     154        // labels for each columns. 
     155        $form = jForms::create($this->form, $this->pseudoFormId); 
    140156        $tpl = new jTpl(); 
    141157        $tpl->assign('list',$results); 
    142158        $tpl->assign('primarykey', $pk[0]); 
    143         if(count($this->propertiesForList)) 
    144             $tpl->assign('properties', $this->propertiesForList); 
    145         else{ 
    146             $tpl->assign('properties', array_keys($dao->getProperties())); 
    147         } 
     159 
     160        if(count($this->propertiesForList)) { 
     161            $prop = $this->propertiesForList; 
     162        }else{ 
     163            $prop = array_keys($dao->getProperties()); 
     164        } 
     165 
     166        $tpl->assign('properties', $prop); 
     167        $tpl->assign('controls',$form->getControls()); 
    148168        $tpl->assign('editAction' , $this->_getAction('preupdate')); 
    149169        $tpl->assign('createAction' , $this->_getAction('create')); 
     
    157177 
    158178        $this->_index($rep, $tpl); 
    159  
    160179        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    161  
     180        jForms::destroy($this->form, $this->pseudoFormId); 
    162181        return $rep; 
    163182    } 
  • branches/1.0beta3.x/lib/jelix/controllers/jControllerDaoCrud.class.php

    r595 r596  
    4141    protected $propertiesForList = array(); 
    4242 
     43 
     44    /** 
     45     * list of properties which serve to order the record list 
     46     * if empty list (default), the list is in a natural order 
     47     * keys are properties name, and values are "asc" or "desc" 
     48     * @var array 
     49     */ 
     50    protected $propertiesForRecordsOrder = array(); 
     51 
    4352    /** 
    4453     * template to display the list of records 
     
    133142 
    134143        $dao = jDao::get($this->dao, $this->dbProfil); 
    135         $results = $dao->findBy(jDao::createConditions(),$offset,$this->listPageSize); 
     144 
     145        $cond = jDao::createConditions(); 
     146        foreach ($this->propertiesForRecordsOrder as $p=>$order) { 
     147            $cond->addItemOrder($p, $order); 
     148        } 
     149 
     150        $results = $dao->findBy($cond,$offset,$this->listPageSize); 
    136151        $pk = $dao->getPrimaryKeyNames(); 
    137152 
    138         jForms::destroy($this->form, $this->pseudoFormId); 
    139  
     153        // we're using a form to have the portunity to have 
     154        // labels for each columns. 
     155        $form = jForms::create($this->form, $this->pseudoFormId); 
    140156        $tpl = new jTpl(); 
    141157        $tpl->assign('list',$results); 
    142158        $tpl->assign('primarykey', $pk[0]); 
    143         if(count($this->propertiesForList)) 
    144             $tpl->assign('properties', $this->propertiesForList); 
    145         else{ 
    146             $tpl->assign('properties', array_keys($dao->getProperties())); 
    147         } 
     159 
     160        if(count($this->propertiesForList)) { 
     161            $prop = $this->propertiesForList; 
     162        }else{ 
     163            $prop = array_keys($dao->getProperties()); 
     164        } 
     165 
     166        $tpl->assign('properties', $prop); 
     167        $tpl->assign('controls',$form->getControls()); 
    148168        $tpl->assign('editAction' , $this->_getAction('preupdate')); 
    149169        $tpl->assign('createAction' , $this->_getAction('create')); 
     
    157177 
    158178        $this->_index($rep, $tpl); 
    159  
    160179        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    161  
     180        jForms::destroy($this->form, $this->pseudoFormId); 
    162181        return $rep; 
    163182    } 
  • branches/1.0beta3.x/lib/jelix/core-modules/jelix/templates/crud_list.tpl

    r571 r596  
    11<h1>{@jelix~crud.title.list@}</h1> 
    22 
    3 <table class="crud-record-list"> 
     3<table class="crud-record-list" border="1"> 
     4<thead> 
     5<tr> 
     6    {foreach $properties as $propname} 
     7    {if isset($controls[$propname])} 
     8    <th>{$controls[$propname]->label|eschtml}</th> 
     9    {else} 
     10    <th>{$propname|eschtml}</th> 
     11    {/if} 
     12    {/foreach} 
     13    <th>&nbsp;</th> 
     14</tr> 
     15</thead> 
     16<tbody> 
    417{foreach $list as $record} 
    518<tr> 
     
    1225</tr> 
    1326{/foreach} 
     27</tbody> 
    1428</table> 
    1529<p class="crud-pages">Pages : {pagelinks $listAction, array(),  $recordCount, $page, $listPageSize, $offsetParameterName }</p> 
  • branches/1.0beta3.x/lib/jelix/core-modules/jelix/templates/crud_list.tpl

    r571 r596  
    11<h1>{@jelix~crud.title.list@}</h1> 
    22 
    3 <table class="crud-record-list"> 
     3<table class="crud-record-list" border="1"> 
     4<thead> 
     5<tr> 
     6    {foreach $properties as $propname} 
     7    {if isset($controls[$propname])} 
     8    <th>{$controls[$propname]->label|eschtml}</th> 
     9    {else} 
     10    <th>{$propname|eschtml}</th> 
     11    {/if} 
     12    {/foreach} 
     13    <th>&nbsp;</th> 
     14</tr> 
     15</thead> 
     16<tbody> 
    417{foreach $list as $record} 
    518<tr> 
     
    1225</tr> 
    1326{/foreach} 
     27</tbody> 
    1428</table> 
    1529<p class="crud-pages">Pages : {pagelinks $listAction, array(),  $recordCount, $page, $listPageSize, $offsetParameterName }</p> 
  • branches/1.0beta3.x/lib/jelix/dao/jDaoBase.class.php

    r576 r596  
    394394            $order = array (); 
    395395            foreach ($daocond->order as $name => $way){ 
    396                 if (isset($fields[$name])){ 
     396                if (isset($props[$name])){ 
    397397                    $order[] = $name.' '.$way; 
    398398                } 
  • branches/1.0beta3.x/lib/jelix/dao/jDaoBase.class.php

    r576 r596  
    394394            $order = array (); 
    395395            foreach ($daocond->order as $name => $way){ 
    396                 if (isset($fields[$name])){ 
     396                if (isset($props[$name])){ 
    397397                    $order[] = $name.' '.$way; 
    398398                } 
  • branches/1.0beta3.x/testapp/modules/testapp/controllers/samplecrud.classic.php

    r572 r596  
    2121    protected $form = 'testapp~products'; 
    2222 
     23 
     24    protected $propertiesForRecordsOrder = array('price'=>'desc'); 
    2325} 
    2426 
  • branches/1.0beta3.x/testapp/modules/testapp/controllers/samplecrud.classic.php

    r572 r596  
    2121    protected $form = 'testapp~products'; 
    2222 
     23 
     24    protected $propertiesForRecordsOrder = array('price'=>'desc'); 
    2325} 
    2426 
  • trunk/lib/jelix/controllers/jControllerDaoCrud.class.php

    r595 r596  
    4141    protected $propertiesForList = array(); 
    4242 
     43 
     44    /** 
     45     * list of properties which serve to order the record list 
     46     * if empty list (default), the list is in a natural order 
     47     * keys are properties name, and values are "asc" or "desc" 
     48     * @var array 
     49     */ 
     50    protected $propertiesForRecordsOrder = array(); 
     51 
    4352    /** 
    4453     * template to display the list of records 
     
    133142 
    134143        $dao = jDao::get($this->dao, $this->dbProfil); 
    135         $results = $dao->findBy(jDao::createConditions(),$offset,$this->listPageSize); 
     144 
     145        $cond = jDao::createConditions(); 
     146        foreach ($this->propertiesForRecordsOrder as $p=>$order) { 
     147            $cond->addItemOrder($p, $order); 
     148        } 
     149 
     150        $results = $dao->findBy($cond,$offset,$this->listPageSize); 
    136151        $pk = $dao->getPrimaryKeyNames(); 
    137152 
    138         jForms::destroy($this->form, $this->pseudoFormId); 
    139  
     153        // we're using a form to have the portunity to have 
     154        // labels for each columns. 
     155        $form = jForms::create($this->form, $this->pseudoFormId); 
    140156        $tpl = new jTpl(); 
    141157        $tpl->assign('list',$results); 
    142158        $tpl->assign('primarykey', $pk[0]); 
    143         if(count($this->propertiesForList)) 
    144             $tpl->assign('properties', $this->propertiesForList); 
    145         else{ 
    146             $tpl->assign('properties', array_keys($dao->getProperties())); 
    147         } 
     159 
     160        if(count($this->propertiesForList)) { 
     161            $prop = $this->propertiesForList; 
     162        }else{ 
     163            $prop = array_keys($dao->getProperties()); 
     164        } 
     165 
     166        $tpl->assign('properties', $prop); 
     167        $tpl->assign('controls',$form->getControls()); 
    148168        $tpl->assign('editAction' , $this->_getAction('preupdate')); 
    149169        $tpl->assign('createAction' , $this->_getAction('create')); 
     
    157177 
    158178        $this->_index($rep, $tpl); 
    159  
    160179        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    161  
     180        jForms::destroy($this->form, $this->pseudoFormId); 
    162181        return $rep; 
    163182    } 
  • trunk/lib/jelix/controllers/jControllerDaoCrud.class.php

    r595 r596  
    4141    protected $propertiesForList = array(); 
    4242 
     43 
     44    /** 
     45     * list of properties which serve to order the record list 
     46     * if empty list (default), the list is in a natural order 
     47     * keys are properties name, and values are "asc" or "desc" 
     48     * @var array 
     49     */ 
     50    protected $propertiesForRecordsOrder = array(); 
     51 
    4352    /** 
    4453     * template to display the list of records 
     
    133142 
    134143        $dao = jDao::get($this->dao, $this->dbProfil); 
    135         $results = $dao->findBy(jDao::createConditions(),$offset,$this->listPageSize); 
     144 
     145        $cond = jDao::createConditions(); 
     146        foreach ($this->propertiesForRecordsOrder as $p=>$order) { 
     147            $cond->addItemOrder($p, $order); 
     148        } 
     149 
     150        $results = $dao->findBy($cond,$offset,$this->listPageSize); 
    136151        $pk = $dao->getPrimaryKeyNames(); 
    137152 
    138         jForms::destroy($this->form, $this->pseudoFormId); 
    139  
     153        // we're using a form to have the portunity to have 
     154        // labels for each columns. 
     155        $form = jForms::create($this->form, $this->pseudoFormId); 
    140156        $tpl = new jTpl(); 
    141157        $tpl->assign('list',$results); 
    142158        $tpl->assign('primarykey', $pk[0]); 
    143         if(count($this->propertiesForList)) 
    144             $tpl->assign('properties', $this->propertiesForList); 
    145         else{ 
    146             $tpl->assign('properties', array_keys($dao->getProperties())); 
    147         } 
     159 
     160        if(count($this->propertiesForList)) { 
     161            $prop = $this->propertiesForList; 
     162        }else{ 
     163            $prop = array_keys($dao->getProperties()); 
     164        } 
     165 
     166        $tpl->assign('properties', $prop); 
     167        $tpl->assign('controls',$form->getControls()); 
    148168        $tpl->assign('editAction' , $this->_getAction('preupdate')); 
    149169        $tpl->assign('createAction' , $this->_getAction('create')); 
     
    157177 
    158178        $this->_index($rep, $tpl); 
    159  
    160179        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    161  
     180        jForms::destroy($this->form, $this->pseudoFormId); 
    162181        return $rep; 
    163182    } 
  • trunk/lib/jelix/core-modules/jelix/templates/crud_list.tpl

    r571 r596  
    11<h1>{@jelix~crud.title.list@}</h1> 
    22 
    3 <table class="crud-record-list"> 
     3<table class="crud-record-list" border="1"> 
     4<thead> 
     5<tr> 
     6    {foreach $properties as $propname} 
     7    {if isset($controls[$propname])} 
     8    <th>{$controls[$propname]->label|eschtml}</th> 
     9    {else} 
     10    <th>{$propname|eschtml}</th> 
     11    {/if} 
     12    {/foreach} 
     13    <th>&nbsp;</th> 
     14</tr> 
     15</thead> 
     16<tbody> 
    417{foreach $list as $record} 
    518<tr> 
     
    1225</tr> 
    1326{/foreach} 
     27</tbody> 
    1428</table> 
    1529<p class="crud-pages">Pages : {pagelinks $listAction, array(),  $recordCount, $page, $listPageSize, $offsetParameterName }</p> 
  • trunk/lib/jelix/core-modules/jelix/templates/crud_list.tpl

    r571 r596  
    11<h1>{@jelix~crud.title.list@}</h1> 
    22 
    3 <table class="crud-record-list"> 
     3<table class="crud-record-list" border="1"> 
     4<thead> 
     5<tr> 
     6    {foreach $properties as $propname} 
     7    {if isset($controls[$propname])} 
     8    <th>{$controls[$propname]->label|eschtml}</th> 
     9    {else} 
     10    <th>{$propname|eschtml}</th> 
     11    {/if} 
     12    {/foreach} 
     13    <th>&nbsp;</th> 
     14</tr> 
     15</thead> 
     16<tbody> 
    417{foreach $list as $record} 
    518<tr> 
     
    1225</tr> 
    1326{/foreach} 
     27</tbody> 
    1428</table> 
    1529<p class="crud-pages">Pages : {pagelinks $listAction, array(),  $recordCount, $page, $listPageSize, $offsetParameterName }</p> 
  • trunk/lib/jelix/dao/jDaoBase.class.php

    r576 r596  
    394394            $order = array (); 
    395395            foreach ($daocond->order as $name => $way){ 
    396                 if (isset($fields[$name])){ 
     396                if (isset($props[$name])){ 
    397397                    $order[] = $name.' '.$way; 
    398398                } 
  • trunk/lib/jelix/dao/jDaoBase.class.php

    r576 r596  
    394394            $order = array (); 
    395395            foreach ($daocond->order as $name => $way){ 
    396                 if (isset($fields[$name])){ 
     396                if (isset($props[$name])){ 
    397397                    $order[] = $name.' '.$way; 
    398398                } 
  • trunk/testapp/modules/testapp/controllers/samplecrud.classic.php

    r572 r596  
    2121    protected $form = 'testapp~products'; 
    2222 
     23 
     24    protected $propertiesForRecordsOrder = array('price'=>'desc'); 
    2325} 
    2426 
  • trunk/testapp/modules/testapp/controllers/samplecrud.classic.php

    r572 r596  
    2121    protected $form = 'testapp~products'; 
    2222 
     23 
     24    protected $propertiesForRecordsOrder = array('price'=>'desc'); 
    2325} 
    2426 
Download in other formats: Unified Diff Zip Archive