Revision | 7a194c624980a123c99384fb40efba5f040c0106 (tree) |
---|---|
Zeit | 2007-09-30 17:32:58 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
Tracker_form::initFields(): allow to limit calling addField() by fieldname
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.91 2007-09-29 15:49:16 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.92 2007-09-30 08:32:58 henoheno Exp $ | |
4 | 4 | // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team |
5 | 5 | // License: GPL v2 or (at your option) any later version |
6 | 6 | // |
@@ -226,20 +226,22 @@ function plugin_tracker_action() | ||
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | |
229 | -// Data set of XHTML form or someting | |
229 | +// Data set of XHTML form or something | |
230 | 230 | class Tracker_form |
231 | 231 | { |
232 | 232 | var $id; |
233 | 233 | var $base; |
234 | 234 | var $refer; |
235 | 235 | var $config; |
236 | + | |
237 | + var $raw_fields; | |
236 | 238 | var $fields = array(); |
237 | 239 | |
238 | 240 | function Tracker_form($base, $refer, $config) |
239 | 241 | { |
240 | 242 | static $id = 0; // Unique id per instance |
243 | + $this->id = ++$id; | |
241 | 244 | |
242 | - $this->id = ++$id; | |
243 | 245 | $this->base = $base; |
244 | 246 | $this->refer = $refer; |
245 | 247 | $this->config = $config; |
@@ -274,14 +276,25 @@ class Tracker_form | ||
274 | 276 | return TRUE; |
275 | 277 | } |
276 | 278 | |
277 | - function initFields() | |
279 | + function initFields($requests = array()) | |
278 | 280 | { |
279 | - foreach ($this->config->get('fields') as $field) { | |
280 | - $this->addField($field[0], $field[1], $field[2], $field[3], $field[4]); | |
281 | - } | |
282 | - foreach ( | |
283 | - array( | |
284 | - // Reserved ones | |
281 | + if (isset($this->raw_fields)) { | |
282 | + $raw_fields = $this->raw_fields; | |
283 | + } else { | |
284 | + $raw_fields = array(); | |
285 | + // From config | |
286 | + foreach ($this->config->get('fields') as $field) { | |
287 | + $fieldname = isset($field[0]) ? $field[0] : ''; | |
288 | + $raw_fields[$fieldname] = array( | |
289 | + 'display' => isset($field[1]) ? $field[1] : '', | |
290 | + 'type' => isset($field[2]) ? $field[2] : '', | |
291 | + 'options' => isset($field[3]) ? $field[3] : '', | |
292 | + 'default' => isset($field[4]) ? $field[4] : '', | |
293 | + ); | |
294 | + } | |
295 | + // From reserved | |
296 | + $default = array('options' => '20', 'default' => ''); | |
297 | + foreach (array( | |
285 | 298 | '_date' => 'text', // Post date |
286 | 299 | '_update' => 'date', // Last modified date |
287 | 300 | '_past' => 'past', // Elapsed time (passage) |
@@ -291,10 +304,48 @@ class Tracker_form | ||
291 | 304 | '_refer' => 'page', // Page name refer from this (Page who has forms) |
292 | 305 | '_base' => 'page', |
293 | 306 | '_submit' => 'submit' |
294 | - ) as $fieldname => $type) | |
295 | - { | |
296 | - $this->addField($fieldname, plugin_tracker_message('btn' . $fieldname), $type); | |
307 | + ) as $fieldname => $type) { | |
308 | + if (isset($raw_fields[$fieldname])) continue; | |
309 | + $raw_fields[$fieldname] = array( | |
310 | + 'display' => plugin_tracker_message('btn' . $fieldname), | |
311 | + 'type' => $type, | |
312 | + ) + $default; | |
313 | + } | |
314 | + $this->raw_fields = $raw_fields; | |
315 | + } | |
316 | + | |
317 | + if (! is_array($requests)) $requests = array($requests); | |
318 | + if ($requests) { | |
319 | + // A part of | |
320 | + foreach ($requests as $fieldname) { | |
321 | + if (isset($raw_fields[$fieldname])) { | |
322 | + $field = $raw_fields[$fieldname]; | |
323 | + $this->addField( | |
324 | + $fieldname, | |
325 | + $field['display'], | |
326 | + $field['type'], | |
327 | + $field['options'], | |
328 | + $field['default'] | |
329 | + ); | |
330 | + } else{ | |
331 | + // TODO: Return an error: Invalid fieldname | |
332 | + // return FALSE; | |
333 | + } | |
334 | + } | |
335 | + } else { | |
336 | + // All | |
337 | + foreach ($raw_fields as $fieldname => $field) { | |
338 | + $this->addField( | |
339 | + $fieldname, | |
340 | + $field['display'], | |
341 | + $field['type'], | |
342 | + $field['options'], | |
343 | + $field['default'] | |
344 | + ); | |
345 | + } | |
297 | 346 | } |
347 | + | |
348 | + return TRUE; | |
298 | 349 | } |
299 | 350 | } |
300 | 351 |
@@ -794,10 +845,11 @@ class Tracker_list | ||
794 | 845 | function Tracker_list($base, $refer, & $config, $list) |
795 | 846 | { |
796 | 847 | $form = & new Tracker_form($base, $refer, $config); |
797 | - $form->initFields(); | |
798 | 848 | $this->form = $form; |
799 | - | |
800 | 849 | $this->list = $list; |
850 | + | |
851 | + // TODO: Call with sort() and toString() | |
852 | + $this->form->initFields(); | |
801 | 853 | } |
802 | 854 | |
803 | 855 | // Add multiple pages at a time |