Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/form/selectwithlink.php
Go to the documentation of this file.
00001 <?php
00002 require_once('HTML/QuickForm/select.php');
00003 
00010 class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{
00016     var $_helpbutton='';
00017     var $_hiddenLabel=false;
00018     var $_link=null;
00019     var $_linklabel=null;
00020     var $_linkreturn=null;
00021 
00022     function MoodleQuickForm_selectwithlink($elementName=null, $elementLabel=null, $options=null, $attributes=null, $linkdata=null)
00023     {
00024         if (!empty($linkdata['link']) && !empty($linkdata['label'])) {
00025             $this->_link = $linkdata['link'];
00026             $this->_linklabel = $linkdata['label'];
00027         }
00028 
00029         if (!empty($linkdata['return'])) {
00030             $this->_linkreturn = $linkdata['return'];
00031         }
00032 
00033         parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
00034     } //end constructor
00035 
00036     function setHiddenLabel($hiddenLabel){
00037         $this->_hiddenLabel = $hiddenLabel;
00038     }
00039     function toHtml(){
00040         $retval = '';
00041         if ($this->_hiddenLabel){
00042             $this->_generateId();
00043             $retval = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
00044                         $this->getLabel().'</label>'.parent::toHtml();
00045         } else {
00046              $retval = parent::toHtml();
00047         }
00048 
00049         if (!empty($this->_link)) {
00050             if (!empty($this->_linkreturn) && is_array($this->_linkreturn)) {
00051                 $appendchar = '?';
00052                 if (strstr($this->_link, '?')) {
00053                     $appendchar = '&amp;';
00054                 }
00055 
00056                 foreach ($this->_linkreturn as $key => $val) {
00057                     $this->_link .= $appendchar."$key=$val";
00058                     $appendchar = '&amp;';
00059                 }
00060             }
00061 
00062             $retval .= '<a style="margin-left: 5px" href="'.$this->_link.'">'.$this->_linklabel.'</a>';
00063         }
00064 
00065         return $retval;
00066     }
00067 
00075     function setHelpButton($helpbuttonargs, $function='helpbutton'){
00076         debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
00077     }
00084     function getHelpButton(){
00085         return $this->_helpbutton;
00086     }
00095     function removeOption($value)
00096     {
00097         $key=array_search($value, $this->_values);
00098         if ($key!==FALSE and $key!==null) {
00099             unset($this->_values[$key]);
00100         }
00101         foreach ($this->_options as $key=>$option){
00102             if ($option['attr']['value']==$value){
00103                 unset($this->_options[$key]);
00104                 return;
00105             }
00106         }
00107     } // end func removeOption
00116     function removeOptions()
00117     {
00118         $this->_options = array();
00119     } // end func removeOption
00127     function getElementTemplateType(){
00128         if ($this->_flagFrozen){
00129             return 'static';
00130         } else {
00131             return 'default';
00132         }
00133     }
00138     function exportValue(&$submitValues, $assoc = false)
00139     {
00140         if (empty($this->_options)) {
00141             return $this->_prepareValue(null, $assoc);
00142         }
00143 
00144         $value = $this->_findValue($submitValues);
00145         if (is_null($value)) {
00146             $value = $this->getValue();
00147         }
00148         $value = (array)$value;
00149 
00150         $cleaned = array();
00151         foreach ($value as $v) {
00152             foreach ($this->_options as $option) {
00153                 if ((string)$option['attr']['value'] === (string)$v) {
00154                     $cleaned[] = (string)$option['attr']['value'];
00155                     break;
00156                 }
00157             }
00158         }
00159 
00160         if (empty($cleaned)) {
00161             return $this->_prepareValue(null, $assoc);
00162         }
00163         if ($this->getMultiple()) {
00164             return $this->_prepareValue($cleaned, $assoc);
00165         } else {
00166             return $this->_prepareValue($cleaned[0], $assoc);
00167         }
00168     }
00169 }
 All Data Structures Namespaces Files Functions Variables Enumerations