-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkboxhelper.class.php
executable file
·55 lines (51 loc) · 1.36 KB
/
checkboxhelper.class.php
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
<?php
/**
* CheckboxHelper
*
* @package default
* @author Ryan Abbott
*/
class CheckboxHelper extends FormHelper
{
/**
* __construct
*
* @param string $data
* @author Ryan Abbott
*/
public function __construct($data = null) {
if(isEmpty($data)) {
return false;
}
parent::__construct($data);
if(isset($data['checked'])) {
$this->checked = (($data['checked'] === true || $data['checked'] == "true") ? true : false);
}
}
/**
* toString
*
* @return void
* @author Ryan Abbott
*/
public function toString($version = TOSTRING_FULL) {
// determine which version of the object to dislay
if($version == TOSTRING_FULL) {
$html = "<input type=\"checkbox\" ".
((isset($this->id) && isNotEmpty($this->id)) ? "id=\"$this->id\" " : "") .
((isset($this->name) && isNotEmpty($this->name)) ? "name=\"$this->name\" " : "") .
((isset($this->class) && isNotEmpty($this->class)) ? "class=\"$this->class\" " : "") .
((isset($this->value) && isNotEmpty($this->value)) ? "value=\"$this->value\" " : "") .
((isset($this->checked) && isNotEmpty($this->checked) && $this->checked === true) ? "checked=\"checked\" " : "") .
" />\n";
return $html;
}
else if($version == TOSTRING_MEDIUM) {
return $this->toString(TOSTRING_FULL);
}
else if($version == TOSTRING_SHORT) {
return $this->toString(TOSTRING_FULL);
}
}
}
?>