[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 18 /** 19 * url type form element 20 * 21 * Contains HTML class for a url type element 22 * 23 * @package core_form 24 * @copyright 2009 Dongsheng Cai <[email protected]> 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 28 require_once("HTML/QuickForm/text.php"); 29 30 /** 31 * url type form element 32 * 33 * HTML class for a url type element 34 * @package core_form 35 * @category form 36 * @copyright 2009 Dongsheng Cai <[email protected]> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class MoodleQuickForm_url extends HTML_QuickForm_text{ 40 /** @var string html for help button, if empty then no help */ 41 var $_helpbutton=''; 42 43 /** @var bool if true label will be hidden */ 44 var $_hiddenLabel=false; 45 46 /** 47 * Constructor 48 * 49 * @param string $elementName Element name 50 * @param mixed $elementLabel Label(s) for an element 51 * @param mixed $attributes Either a typical HTML attribute string or an associative array. 52 * @param array $options data which need to be posted. 53 */ 54 function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) { 55 global $CFG; 56 require_once("$CFG->dirroot/repository/lib.php"); 57 $options = (array)$options; 58 foreach ($options as $name=>$value) { 59 $this->_options[$name] = $value; 60 } 61 if (!isset($this->_options['usefilepicker'])) { 62 $this->_options['usefilepicker'] = true; 63 } 64 parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes); 65 } 66 67 /** 68 * Sets label to be hidden 69 * 70 * @param bool $hiddenLabel sets if label should be hidden 71 */ 72 function setHiddenLabel($hiddenLabel){ 73 $this->_hiddenLabel = $hiddenLabel; 74 } 75 76 /** 77 * Returns HTML for this form element. 78 * 79 * @return string 80 */ 81 function toHtml(){ 82 global $PAGE, $OUTPUT; 83 84 $id = $this->_attributes['id']; 85 $elname = $this->_attributes['name']; 86 87 if ($this->_hiddenLabel) { 88 $this->_generateId(); 89 $str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'. 90 $this->getLabel().'</label>'.parent::toHtml(); 91 } else { 92 $str = parent::toHtml(); 93 } 94 if (empty($this->_options['usefilepicker'])) { 95 return $str; 96 } 97 98 $client_id = uniqid(); 99 100 $args = new stdClass(); 101 $args->accepted_types = '*'; 102 $args->return_types = FILE_EXTERNAL; 103 $args->context = $PAGE->context; 104 $args->client_id = $client_id; 105 $args->env = 'url'; 106 $fp = new file_picker($args); 107 $options = $fp->options; 108 109 if (count($options->repositories) > 0) { 110 $straddlink = get_string('choosealink', 'repository'); 111 $str .= <<<EOD 112 <button id="filepicker-button-{$client_id}" class="visibleifjs"> 113 $straddlink 114 </button> 115 EOD; 116 } 117 118 // print out file picker 119 $str .= $OUTPUT->render($fp); 120 121 $module = array('name'=>'form_url', 'fullpath'=>'/lib/form/url.js', 'requires'=>array('core_filepicker')); 122 $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module); 123 124 return $str; 125 } 126 127 /** 128 * get html for help button 129 * 130 * @return string html for help button 131 */ 132 function getHelpButton(){ 133 return $this->_helpbutton; 134 } 135 136 /** 137 * Slightly different container template when frozen. Don't want to use a label tag 138 * with a for attribute in that case for the element label but instead use a div. 139 * Templates are defined in renderer constructor. 140 * 141 * @return string 142 */ 143 function getElementTemplateType(){ 144 if ($this->_flagFrozen){ 145 return 'static'; 146 } else { 147 return 'default'; 148 } 149 } 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |