Dotclear

source: inc/admin/class.dc.list.php @ 1152:fbd922f6ed09

Revision 1152:fbd922f6ed09, 4.5 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

form filters reloaded, first try for lists (to be completed)
form fields now support multiple values.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13class dcItemList extends dcForm {
14
15     protected $columns;
16     protected $entries;
17     protected $filterset;
18     protected $selection;
19
20
21     public static function __init__($env) {
22          $env->getExtension('dc_form')->addTemplate('@forms/lists_layout.html.twig');
23          $env->addFunction(
24               new Twig_SimpleFunction(
25                    'listitems',
26                    'dcItemList::renderList',
27                    array(
28                         'is_safe' => array('html'),
29                         'needs_context' => true,
30                         'needs_environment' => true
31          )));
32     }
33
34     public static function renderList($env,$context,$name,$attributes=array())
35     {
36          $context['listname']=$name;
37          echo $env->getExtension('dc_form')->renderWidget(
38               'entrieslist',
39               $context
40          );
41     }
42     /**
43     Inits dcItemList object
44     
45     @param    core      <b>dcCore</b>       Dotclear core reference
46     @param    form_prefix    <b>string</b>       form prefix to use for parameters
47     */
48     public function __construct($core,$name,$action,$form_prefix="f_") {
49          parent::__construct($core,$name,$action,'POST');
50          $this->entries = array();
51          $this->columns = array();
52          $this->selection = new dcFieldCheckbox('entries',NULL,array('multiple' => true));
53          $this->addField($this->selection);
54     }
55
56     public function setup() {
57          parent::setup();
58          $this
59               ->addField(new dcFieldCombo('action',$this->actions_combo, '', array(
60                    'label' => __('Selected entries action:'))))
61               ->addField(new dcFieldSubmit('ok',__('ok'), array()));
62          $columns_combo = array();
63          foreach ($this->columns as $c) {
64               $columns_combo[$c->getID()] = $c->getName();
65          }
66          $this->filterset->addFilter(new dcFilterCombo(
67               'sortby',
68               __('Sort By'), 
69               __('Sort by'), 'sortby', $columns_combo,array('singleval'=> true,'static' => true)));
70          $order_combo = array('asc' => __('Ascending'),'desc' => __('Descending'));
71          $this->filterset->addFilter(new dcFilterCombo(
72               'order',
73               __('Order'), 
74               __('Order'), 'orderby', $order_combo,array('singleval'=> true, 'static' => true)));
75          $this->filterset->addFilter(new dcFilterText(
76               'limit',
77               __('Limit'), __('Limit'), 'limit',array('singleval'=> true,'static' =>true)));
78     }
79
80     public function setEntries($entries) {
81          $this->entries = $entries;
82          $this->core->tpl->addGlobal('list_'.$this->name,$this->getContext());
83          foreach ($this->entries as $e) {
84               $this->selection->addValue($e->post_id);
85          }
86     }
87
88     public function getContext() {
89          $ccontext = new ArrayObject();
90          foreach ($this->columns as $c) {
91               $c->appendEditLines($ccontext);
92          }
93          return array(
94               'cols' => $ccontext,
95               'entries' => $this->entries);
96     }
97
98     public function addColumn($c) {
99          $this->columns[] = $c;
100          $c->setForm($this);
101          return $this;
102     }
103
104     public function setFilterSet($fs) {
105          $this->filterset = $fs;
106     }
107
108}
109
110class 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) {
146     }
147
148}
149
150class dcColumn {
151     protected $form;
152     protected $id;
153     protected $name;
154     protected $sortable;
155     protected $col_id;
156
157     public function __construct($id, $name, $col_id,$attributes=array()) {
158          $this->id = $id;
159          $this->name = $name;
160          $this->col_id = $col_id;
161     }
162
163     public function getName() {
164          return $this->name;
165     }
166
167     public function getID() {
168          return $this->id;
169     }
170
171     public function getColID(){
172          return $this->col_id;
173     }
174
175     public function setForm($f){
176          $this->form = $f;
177     }
178
179     public function appendEditLines($line) {
180          $line[] = array (
181               'name' => $this->name,
182               'col_id' => $this->col_id,
183               'widget' => 'col_'.$this->id);
184     }
185
186}
187
188
189dcItemList::__init__($GLOBALS['core']->tpl);
190
191?>
Note: See TracBrowser for help on using the repository browser.

Sites map