CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

HtmlRadioButtonSet.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: HtmlRadioButtonSet.php
4 #
5 # Part of the ScoutLib application support library
6 # Copyright 2017 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu
8 #
9
13 class HtmlRadioButtonSet
14 {
15
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
26 public function __construct($ResultVar, $Options, $SelectedValue = NULL)
27 {
28 $this->ResultVar = $ResultVar;
29 $this->Options = $Options;
30 $this->SelectedValue = $SelectedValue;
31 }
32
36 public function PrintHtml()
37 {
38 print $this->GetHtml();
39 }
40
45 public function GetHtml()
46 {
47 # start out with empty HTML
48 $Html = "";
49
50 # if there are options or we are supposed to print even if no options
51 if (count($this->Options) || $this->PrintIfEmpty)
52 {
53 # for each option
54 foreach ($this->Options as $Value => $Label)
55 {
56 # generate ID for elements
57 $Id = $this->ResultVar."_"
58 .preg_replace("%[^a-z0-9]%i", "", $Value);
59
60 # start input element
61 $Html .= " <input type=\"radio\""
62 ." id=\"".htmlspecialchars($Id)."\""
63 ." name=\"".htmlspecialchars($this->ResultVar)."\""
64 ." value=\"".htmlspecialchars($Value)."\"";
65
66 # add in selected attribute if appropriate
67 if ((is_array($this->SelectedValue)
68 && in_array($Value, $this->SelectedValue))
69 || ($Value == $this->SelectedValue))
70 {
71 $Html .= " checked";
72 }
73
74 # add in disabled attribute if appropriate
75 if ($this->Disabled
76 || array_key_exists($Value, $this->DisabledOptions))
77 {
78 $Html .= " disabled";
79 }
80
81 # end input element
82 $Html .= ">";
83
84 # add label
85 $Html .= " <label for=\"".$Id."\">"
86 .htmlspecialchars($Label)."</label>\n";
87 }
88 }
89
90 # return generated HTML to caller
91 return $Html;
92 }
93
102 public function DisabledOptions($Options = NULL)
103 {
104 if ($Options !== NULL)
105 {
106 if (is_array($Options))
107 {
108 $this->DisabledOptions = $Options;
109 }
110 else
111 {
112 $this->DisabledOptions[$Options] = "X";
113 }
114 }
115 return $this->DisabledOptions;
116 }
117
124 public function SelectedValue($NewValue = NULL)
125 {
126 if ($NewValue !== NULL)
127 {
128 $this->SelectedValue = $NewValue;
129 }
130 return $this->SelectedValue;
131 }
132
142 public function PrintIfEmpty($NewValue = NULL)
143 {
144 if ($NewValue !== NULL)
145 {
146 $this->PrintIfEmpty = $NewValue ? TRUE : FALSE;
147 }
148 return $this->PrintIfEmpty;
149 }
150
158 public function Disabled($NewValue = NULL)
159 {
160 if ($NewValue !== NULL)
161 {
162 $this->Disabled = $NewValue ? TRUE : FALSE;
163 }
164 return $this->Disabled;
165 }
166
167
168 # ---- PRIVATE INTERFACE -------------------------------------------------
169
170 private $Options;
171 private $ResultVar;
172
173 private $Disabled = FALSE;
174 private $DisabledOptions = array();
175 private $PrintIfEmpty = TRUE;
176 private $SelectedValue;
177 }
HtmlRadioButtonSet\DisabledOptions
DisabledOptions($Options=NULL)
Get/set disabled options.
Definition: HtmlRadioButtonSet.php:102
HtmlRadioButtonSet\SelectedValue
SelectedValue($NewValue=NULL)
Get/set currently selected value or array of currently selected values.
Definition: HtmlRadioButtonSet.php:124
PHP
PHP
Definition: RSSClient--Test.php:12
HtmlRadioButtonSet
Convenience class for generating a set of HTML radio button form elements.
Definition: HtmlRadioButtonSet.php:13
HtmlRadioButtonSet\PrintIfEmpty
PrintIfEmpty($NewValue=NULL)
Get/set whether list should be output even if there are no items.
Definition: HtmlRadioButtonSet.php:142
HtmlRadioButtonSet\GetHtml
GetHtml()
Get HTML for set.
Definition: HtmlRadioButtonSet.php:45
HtmlRadioButtonSet\Disabled
Disabled($NewValue=NULL)
Get/set whether the whole option list is editable.
Definition: HtmlRadioButtonSet.php:158
HtmlRadioButtonSet\__construct
__construct($ResultVar, $Options, $SelectedValue=NULL)
Class constructor.
Definition: HtmlRadioButtonSet.php:26
HtmlRadioButtonSet\PrintHtml
PrintHtml()
Print HTML for set.
Definition: HtmlRadioButtonSet.php:36