|
Revision 2593, 1.8 kB
(checked in by Geert, 2 months ago)
|
CodingStyle maintenance!
|
- Property svn:eol-style set to
LF
- Property copyright set to
Copyright (c) 2007-2008 Kohana Team
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
<?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
class Form_Checklist_Core extends Form_Input { |
|---|
| 13 |
|
|---|
| 14 |
protected $data = array |
|---|
| 15 |
( |
|---|
| 16 |
'name' => '', |
|---|
| 17 |
'type' => 'checkbox', |
|---|
| 18 |
'class' => 'checklist', |
|---|
| 19 |
'options' => array(), |
|---|
| 20 |
); |
|---|
| 21 |
|
|---|
| 22 |
protected $protect = array('name', 'type'); |
|---|
| 23 |
|
|---|
| 24 |
public function __construct($name) |
|---|
| 25 |
{ |
|---|
| 26 |
$this->data['name'] = $name; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
public function __get($key) |
|---|
| 30 |
{ |
|---|
| 31 |
if ($key == 'value') |
|---|
| 32 |
{ |
|---|
| 33 |
|
|---|
| 34 |
$array = array(); |
|---|
| 35 |
foreach ($this->data['options'] as $id => $opt) |
|---|
| 36 |
{ |
|---|
| 37 |
|
|---|
| 38 |
($opt[1] === TRUE) and $array[] = $id; |
|---|
| 39 |
} |
|---|
| 40 |
return $array; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
return parent::__get($key); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
public function render() |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
$base_data = $this->data; |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
$base_data['name'] .= '[]'; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
$nl = "\n"; |
|---|
| 56 |
|
|---|
| 57 |
$checklist = '<ul class="'.arr::remove('class', $base_data).'">'.$nl; |
|---|
| 58 |
foreach (arr::remove('options', $base_data) as $val => $opt) |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
$data = $base_data; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
list ($title, $checked) = $opt; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
$data['value'] = $val; |
|---|
| 68 |
$data['checked'] = $checked; |
|---|
| 69 |
|
|---|
| 70 |
$checklist .= '<li><label>'.form::checkbox($data).' '.$title.'</label></li>'.$nl; |
|---|
| 71 |
} |
|---|
| 72 |
$checklist .= '</ul>'; |
|---|
| 73 |
|
|---|
| 74 |
return $checklist; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
protected function load_value() |
|---|
| 78 |
{ |
|---|
| 79 |
foreach ($this->data['options'] as $val => $checked) |
|---|
| 80 |
{ |
|---|
| 81 |
if ($input = $this->input_value($this->data['name'])) |
|---|
| 82 |
{ |
|---|
| 83 |
$this->data['options'][$val][1] = in_array($val, $input); |
|---|
| 84 |
} |
|---|
| 85 |
else |
|---|
| 86 |
{ |
|---|
| 87 |
$this->data['options'][$val][1] = FALSE; |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
} |
|---|