|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 require_once('HTML/QuickForm/select.php'); 00003 00010 class MoodleQuickForm_select extends HTML_QuickForm_select{ 00016 var $_helpbutton=''; 00017 var $_hiddenLabel=false; 00018 00019 function MoodleQuickForm_select($elementName=null, $elementLabel=null, $options=null, $attributes=null) { 00020 parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes); 00021 } 00022 function setHiddenLabel($hiddenLabel){ 00023 $this->_hiddenLabel = $hiddenLabel; 00024 } 00025 function toHtml(){ 00026 if ($this->_hiddenLabel){ 00027 $this->_generateId(); 00028 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'. 00029 $this->getLabel().'</label>'.parent::toHtml(); 00030 } else { 00031 return parent::toHtml(); 00032 } 00033 } 00034 00042 function setHelpButton($helpbuttonargs, $function='helpbutton'){ 00043 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead'); 00044 } 00051 function getHelpButton(){ 00052 return $this->_helpbutton; 00053 } 00062 function removeOption($value) 00063 { 00064 $key=array_search($value, $this->_values); 00065 if ($key!==FALSE and $key!==null) { 00066 unset($this->_values[$key]); 00067 } 00068 foreach ($this->_options as $key=>$option){ 00069 if ($option['attr']['value']==$value){ 00070 unset($this->_options[$key]); 00071 // we must reindex the options because the ugly code in quickforms' select.php expects that keys are 0,1,2,3... !?!? 00072 $this->_options = array_merge($this->_options); 00073 return; 00074 } 00075 } 00076 } // end func removeOption 00085 function removeOptions() 00086 { 00087 $this->_options = array(); 00088 } // end func removeOption 00096 function getElementTemplateType(){ 00097 if ($this->_flagFrozen){ 00098 return 'static'; 00099 } else { 00100 return 'default'; 00101 } 00102 } 00107 function exportValue(&$submitValues, $assoc = false) 00108 { 00109 if (empty($this->_options)) { 00110 return $this->_prepareValue(null, $assoc); 00111 } 00112 00113 $value = $this->_findValue($submitValues); 00114 if (is_null($value)) { 00115 $value = $this->getValue(); 00116 } 00117 $value = (array)$value; 00118 00119 $cleaned = array(); 00120 foreach ($value as $v) { 00121 foreach ($this->_options as $option) { 00122 if ((string)$option['attr']['value'] === (string)$v) { 00123 $cleaned[] = (string)$option['attr']['value']; 00124 break; 00125 } 00126 } 00127 } 00128 00129 if (empty($cleaned)) { 00130 return $this->_prepareValue(null, $assoc); 00131 } 00132 if ($this->getMultiple()) { 00133 return $this->_prepareValue($cleaned, $assoc); 00134 } else { 00135 return $this->_prepareValue($cleaned[0], $assoc); 00136 } 00137 } 00138 }