CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

HtmlOptionList.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: HtmlOptionList.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2014 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
13 class HtmlOptionList {
14
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
25 function __construct($ResultVar, $Options, $SelectedValue = NULL)
26 {
27 $this->ResultVar = $ResultVar;
28 $this->Options = $Options;
29 $this->SelectedValue = $SelectedValue;
30 }
31
35 function PrintHtml()
36 {
37 print $this->GetHtml();
38 }
39
44 function GetHtml()
45 {
46 # start out with empty HTML
47 $Html = "";
48
49 # if there are options or we are supposed to print even if no options
50 if (count($this->Options) || $this->PrintIfEmpty)
51 {
52 # begin select element
53 $Html .= '<select name="'.$this->ResultVar.'"'
54 .' size="'.$this->Size.'"'
55 .' id="'.$this->ResultVar.'"';
56 if ($this->SubmitOnChange)
57 {
58 if ($this->OnChangeAction)
59 { $Html .= ' onChange="'.$this->OnChangeAction.'"'; }
60 else
61 { $Html .= ' onChange="submit()"'; }
62 }
63 if ($this->MultipleAllowed) { $Html .= ' multiple'; }
64 $Html .= ">\n";
65
66 # for each option
67 foreach ($this->Options as $Value => $Label)
68 {
69 # start option element
70 $Html .= ' <option value="'.htmlspecialchars($Value).'"';
71
72 # add in selected attribute if appropriate
73 if ((is_array($this->SelectedValue)
74 && in_array($Value, $this->SelectedValue))
75 || ($Value == $this->SelectedValue))
76 {
77 $Html .= ' selected';
78 }
79
80 # add in disabled attribute if appropriate
81 if (array_key_exists($Value, $this->DisabledOptions))
82 {
83 $Html .= ' disabled';
84 }
85
86 # add label and end option element
87 $Html .= ">".htmlspecialchars($Label)."</option>\n";
88 }
89
90 # end select element
91 $Html .= '</select>';
92 }
93
94 # return generated HTML to caller
95 return $Html;
96 }
97
106 function DisabledOptions($Options = NULL)
107 {
108 if ($Options !== NULL)
109 {
110 if (is_array($Options))
111 {
112 $this->DisabledOptions = $Options;
113 }
114 else
115 {
116 $this->DisabledOptions[$Options] = "X";
117 }
118 }
119 return $this->DisabledOptions;
120 }
121
128 function SelectedValue($NewValue = NULL)
129 {
130 if ($NewValue !== NULL)
131 {
132 $this->SelectedValue = $NewValue;
133 }
134 return $this->SelectedValue;
135 }
136
142 function Size($NewValue = NULL)
143 {
144 if ($NewValue !== NULL)
145 {
146 $this->Size = intval($NewValue);
147 }
148 return $this->Size;
149 }
150
157 function MultipleAllowed($NewValue = NULL)
158 {
159 if ($NewValue !== NULL)
160 {
161 $this->MultipleAllowed = $NewValue ? TRUE : FALSE;
162 }
163 return $this->MultipleAllowed;
164 }
165
174 function SubmitOnChange($NewValue = NULL)
175 {
176 if ($NewValue !== NULL)
177 {
178 $this->SubmitOnChange = $NewValue ? TRUE : FALSE;
179 }
180 return $this->SubmitOnChange;
181 }
182
194 function OnChangeAction($NewValue = NULL)
195 {
196 if ($NewValue !== NULL)
197 {
198 $this->OnChangeAction = $NewValue;
199 }
200 return $this->OnChangeAction;
201 }
202
212 function PrintIfEmpty($NewValue = NULL)
213 {
214 if ($NewValue !== NULL)
215 {
216 $this->PrintIfEmpty = $NewValue ? TRUE : FALSE;
217 }
218 return $this->PrintIfEmpty;
219 }
220
221
222 # ---- PRIVATE INTERFACE -------------------------------------------------
223
224 private $Options;
225 private $ResultVar;
226
227 private $DisabledOptions = array();
228 private $MultipleAllowed = FALSE;
229 private $OnChangeAction = "submit()";
230 private $PrintIfEmpty = TRUE;
231 private $SelectedValue;
232 private $Size = 1;
233 private $SubmitOnChange = FALSE;
234 }
235
HtmlOptionList\SubmitOnChange
SubmitOnChange($NewValue=NULL)
Get/set whether to submit the form when the list value is changed.
Definition: HtmlOptionList.php:174
HtmlOptionList\PrintIfEmpty
PrintIfEmpty($NewValue=NULL)
Get/set whether list should be output even if there are no items.
Definition: HtmlOptionList.php:212
HtmlOptionList\__construct
__construct($ResultVar, $Options, $SelectedValue=NULL)
Class constructor.
Definition: HtmlOptionList.php:25
PHP
PHP
Definition: RSSClient--Test.php:12
HtmlOptionList\GetHtml
GetHtml()
Get HTML for list.
Definition: HtmlOptionList.php:44
HtmlOptionList\PrintHtml
PrintHtml()
Print HTML for list.
Definition: HtmlOptionList.php:35
HtmlOptionList\MultipleAllowed
MultipleAllowed($NewValue=NULL)
Get/set whether multiple items may be selected.
Definition: HtmlOptionList.php:157
HtmlOptionList\Size
Size($NewValue=NULL)
Get/set the list size (number of visible items).
Definition: HtmlOptionList.php:142
HtmlOptionList\OnChangeAction
OnChangeAction($NewValue=NULL)
Get/set action to take if form is submitted on change.
Definition: HtmlOptionList.php:194
HtmlOptionList\SelectedValue
SelectedValue($NewValue=NULL)
Get/set currently selected value or array of currently selected values.
Definition: HtmlOptionList.php:128
HtmlOptionList
Convenience class for generating an HTML select/option form element.
Definition: HtmlOptionList.php:13
HtmlOptionList\DisabledOptions
DisabledOptions($Options=NULL)
Get/set disabled options.
Definition: HtmlOptionList.php:106