Dotclear


Ignore:
Timestamp:
04/09/13 09:08:48 (12 years ago)
Author:
Dsls <dsls@…>
Branch:
twig
Message:

Intermediate commit, needs to be better documented

  • introducing new dcListFetcher class for lists
  • Lists are now driving filters
  • forms tags are now defined in twig format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.list.php

    r1152 r1154  
    1616     protected $entries; 
    1717     protected $filterset; 
     18     protected $fetcher; 
    1819     protected $selection; 
     20     protected $current_page; 
     21     protected $nb_items; 
     22     protected $nb_items_per_page; 
    1923 
    2024 
     
    4650     @param    form_prefix    <b>string</b>       form prefix to use for parameters 
    4751     */ 
    48      public function __construct($core,$name,$action,$form_prefix="f_") { 
     52     public function __construct($core,$name,$filterset,$fetcher,$action,$form_prefix="f_") { 
    4953          parent::__construct($core,$name,$action,'POST'); 
    5054          $this->entries = array(); 
     
    5256          $this->selection = new dcFieldCheckbox('entries',NULL,array('multiple' => true)); 
    5357          $this->addField($this->selection); 
     58          $this->filterset = $filterset; 
     59          $this->fetcher = $fetcher; 
    5460     } 
    5561 
    5662     public function setup() { 
    57           parent::setup(); 
    5863          $this 
    5964               ->addField(new dcFieldCombo('action',$this->actions_combo, '', array( 
    6065                    'label' => __('Selected entries action:')))) 
    61                ->addField(new dcFieldSubmit('ok',__('ok'), array())); 
     66               ->addField(new dcFieldSubmit('ok',__('ok'), array())) 
     67               ->addField(new dcFieldHidden('page','1')); 
    6268          $columns_combo = array(); 
    6369          foreach ($this->columns as $c) { 
     
    7379               __('Order'),  
    7480               __('Order'), 'orderby', $order_combo,array('singleval'=> true, 'static' => true))); 
    75           $this->filterset->addFilter(new dcFilterText( 
     81          $limit = new dcFilterText( 
    7682               'limit', 
    77                __('Limit'), __('Limit'), 'limit',array('singleval'=> true,'static' =>true))); 
     83               __('Limit'), __('Limit'), 'limit',array('singleval'=> true,'static' =>true)); 
     84          $this->filterset->addFilter($limit); 
     85          $this->filterset->setup(); 
     86          parent::setup(); 
     87          $this->nb_items_per_page = $limit->getFields()->getValue(); 
     88          $this->fetchEntries(); 
     89 
     90     } 
     91 
     92     protected function fetchEntries() { 
     93          $params = new ArrayObject(); 
     94          $offset = $this->nb_items_per_page*($this->page->getValue()-1); 
     95          $this->filterset->applyFilters($params); 
     96          $this->nb_items = $this->fetcher->getEntriesCount($params); 
     97          $entries = $this->fetcher->getEntries($params,$offset,$this->nb_items_per_page); 
     98          $this->setEntries($entries); 
     99          /*echo "LIMIT:".$this->nb_items_per_page; 
     100          echo 'count :'.print_r($this->nb_items,true); 
     101          echo 'page'.$this->page;*/ 
    78102     } 
    79103 
     
    104128     public function setFilterSet($fs) { 
    105129          $this->filterset = $fs; 
    106      } 
    107  
    108 } 
    109  
    110 class dcFilterCheckbox extends dcFilter { 
    111  
    112      public function __construct($id,$name,$desc) { 
    113           parent::__construct($id,$name,$desc,$request_param); 
    114      } 
    115  
    116  
    117  
    118      public function appendSingleLine($line,$pos) { 
    119           $f = $this->fields[$pos]; 
    120           $line['ffield'] = $f->getName(); 
    121           if ($this->static) { 
    122                $line['display_inline'] = true; 
    123           } 
    124  
    125           if ($pos == 0) { 
    126                $line['fwidget']='filter_checkbox'; 
    127                $line['desc']=$this->desc; 
    128           }; 
    129      } 
    130  
    131      public function addValue($value=NULL) { 
    132           if (count($this->fields)>0) 
    133                return; 
    134           if ($value === NULL) { 
    135                $value = 1; 
    136           } 
    137           $f = new dcFieldCheckbox( 
    138                $this->getFieldID($pos), 
    139                $value, 
    140                array()); 
    141           $this->filterset->addField($f); 
    142           $this->fields[]=$f; 
    143      } 
    144  
    145      public function applyFilter($params) { 
    146130     } 
    147131 
     
    186170} 
    187171 
     172abstract class dcListFetcher { 
     173     protected $core; 
     174     public function __construct($core) { 
     175          $this->core = $core; 
     176     } 
     177 
     178     abstract function getEntries($params,$offset,$limit); 
     179     abstract function getEntriesCount($params); 
     180} 
    188181 
    189182dcItemList::__init__($GLOBALS['core']->tpl); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map