blob: 4536d39630bed42c7653ef0e6d1d03c16d278bb0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<?php defined("SYSPATH") or die("No direct script access.");
/**
* FORGE checklist input library.
*
* $Id: Form_Checklist.php 3326 2008-08-09 21:24:30Z Shadowhand $
*
* @package Forge
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Form_Checklist_Core extends Form_Input {
protected $data = array
(
'name' => '',
'type' => 'checkbox',
'class' => 'checklist',
'options' => array(),
);
protected $protect = array('name', 'type');
public function __construct($name)
{
$this->data['name'] = $name;
}
public function __get($key)
{
if ($key == 'value')
{
// Return the currently checked values
$array = array();
foreach ($this->data['options'] as $id => $opt)
{
// Return the options that are checked
($opt[1] === TRUE) and $array[] = $id;
}
return $array;
}
return parent::__get($key);
}
public function render()
{
// Import base data
$base_data = $this->data;
// Make it an array
$base_data['name'] .= '[]';
// Newline
$nl = "\n";
$checklist = '<ul class="'.arr::remove('class', $base_data).'">'.$nl;
foreach (arr::remove('options', $base_data) as $val => $opt)
{
// New set of input data
$data = $base_data;
// Get the title and checked status
list ($title, $checked) = $opt;
// Set the name, value, and checked status
$data['value'] = $val;
$data['checked'] = $checked;
$checklist .= '<li><label>'.form::checkbox($data).' '.html::purify($title).'</label></li>'.$nl;
}
$checklist .= '</ul>';
return $checklist;
}
protected function load_value()
{
foreach ($this->data['options'] as $val => $checked)
{
if ($input = $this->input_value($this->data['name']))
{
$this->data['options'][$val][1] = in_array($val, $input);
}
else
{
$this->data['options'][$val][1] = FALSE;
}
}
}
} // End Form Checklist
|