[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 <dongsheng@moodle.com> 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 <dongsheng@moodle.com> 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 public function __construct($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::__construct($elementName, $elementLabel, $attributes); 65 } 66 67 /** 68 * Old syntax of class constructor. Deprecated in PHP7. 69 * 70 * @deprecated since Moodle 3.1 71 */ 72 public function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) { 73 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); 74 self::__construct($elementName, $elementLabel, $attributes, $options); 75 } 76 77 /** 78 * Sets label to be hidden 79 * 80 * @param bool $hiddenLabel sets if label should be hidden 81 */ 82 function setHiddenLabel($hiddenLabel){ 83 $this->_hiddenLabel = $hiddenLabel; 84 } 85 86 /** 87 * Returns HTML for this form element. 88 * 89 * @return string 90 */ 91 function toHtml(){ 92 global $PAGE, $OUTPUT; 93 94 $id = $this->_attributes['id']; 95 $elname = $this->_attributes['name']; 96 97 if ($this->_hiddenLabel) { 98 $this->_generateId(); 99 $str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'. 100 $this->getLabel().'</label>'.parent::toHtml(); 101 } else { 102 $str = parent::toHtml(); 103 } 104 if (empty($this->_options['usefilepicker'])) { 105 return $str; 106 } 107 108 $client_id = uniqid(); 109 110 $args = new stdClass(); 111 $args->accepted_types = '*'; 112 $args->return_types = FILE_EXTERNAL; 113 $args->context = $PAGE->context; 114 $args->client_id = $client_id; 115 $args->env = 'url'; 116 $fp = new file_picker($args); 117 $options = $fp->options; 118 119 if (count($options->repositories) > 0) { 120 $straddlink = get_string('choosealink', 'repository'); 121 $str .= <<<EOD 122 <button id="filepicker-button-js-{$client_id}" class="visibleifjs"> 123 $straddlink 124 </button> 125 EOD; 126 } 127 128 // print out file picker 129 $str .= $OUTPUT->render($fp); 130 131 $module = array('name'=>'form_url', 'fullpath'=>'/lib/form/url.js', 'requires'=>array('core_filepicker')); 132 $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module); 133 134 return $str; 135 } 136 137 /** 138 * get html for help button 139 * 140 * @return string html for help button 141 */ 142 function getHelpButton(){ 143 return $this->_helpbutton; 144 } 145 146 /** 147 * Slightly different container template when frozen. Don't want to use a label tag 148 * with a for attribute in that case for the element label but instead use a div. 149 * Templates are defined in renderer constructor. 150 * 151 * @return string 152 */ 153 function getElementTemplateType(){ 154 if ($this->_flagFrozen){ 155 return 'static'; 156 } else { 157 return 'default'; 158 } 159 } 160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |