-
Notifications
You must be signed in to change notification settings - Fork 0
/
radiohelper.class.php
executable file
·85 lines (76 loc) · 2.29 KB
/
radiohelper.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
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
<?php
/**
* RadioHelper
*
* @package default
* @author Ryan Abbott
*/
class RadioHelper extends FormHelper
{
/**
* __construct
*
* @param string $data
* @author Ryan Abbott
*/
public function __construct($data = null) {
parent::__construct($data);
if($data != null) {
if(isset($data['checked']) && $data['checked'] === true) {
$this->checked = "checked";
}
}
}
/**
* addDatabaseOptions
*
* @param string $table
* @param string $keyColumn
* @param string $valueColumn
* @param string $conditions
* @return void
* @author Ryan Abbott
*/
public function addDatabaseOptions($table, $keyColumn, $valueColumn, $conditions = null, $order = null) {
$sql = "SELECT $keyColumn, $valueColumn FROM $table" . (($conditions != null) ? " WHERE $conditions" : "") . (($order != null) ? " ORDER BY $order" : "");
$this->db->query($sql);
if($this->db->numRows() > 0) {
while($row = mysql_fetch_array($this->db->result)) {
$this->options[] = new Option($row[$keyColumn], $row[$valueColumn]);
}
}
}
public function getDatabaseOptions($table, $keyColumn, $valueColumn, $conditions = null, $order = null) {
$sql = "SELECT $keyColumn, $valueColumn FROM $table" . (($conditions != null) ? " WHERE $conditions" : "") . (($order != null) ? " ORDER BY $order" : "");
$this->db->query($sql);
if($this->db->numRows() > 0) {
while($row = mysql_fetch_array($this->db->result)) {
$options[$row[$keyColumn]] = $row[$valueColumn];
}
}
return $options;
}
/**
* toString
*
* @return void
* @author Ryan Abbott
*/
public function toString($selected = "none", $version = TOSTRING_FULL) {
// determine which version of the object to dislay
if($version == TOSTRING_FULL) {
$html = "<input type=\"radio\" ".
(($this->id != "") ? "id=\"$this->id\" " : "") .
(($this->name != "") ? "name=\"$this->name\" " : "") .
(($this->class != "") ? "class=\"$this->class\" " : "") .
(($this->disabled != "" && $this->disabled === true) ? "disabled=\"disabled\" " : "") .
(($this->value != "") ? "value=\"$this->value\" " : "") .
(($this->checked != "") ? "checked=\"checked\" " : "") . " />\n";
if(isset($this->label)) {
$html = "<label for=\"$this->id\">$html $this->label</label>";
}
return $html;
}
}
}
?>