Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Drop down list (select list) element 19 * 20 * @package gradereport_singleview 21 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace gradereport_singleview\local\ui; 26 27 use html_writer; 28 29 defined('MOODLE_INTERNAL') || die; 30 31 /** 32 * Drop down list (select list) element 33 * 34 * @package gradereport_singleview 35 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class dropdown_attribute extends element { 39 40 /** @var string $selected Who is selected ? */ 41 private $selected; 42 43 /** @var array $options List of options ? */ 44 private $options; 45 46 /** @var bool $isdisabled Is this input disabled. */ 47 private $isdisabled; 48 49 /** 50 * Constructor 51 * 52 * @param string $name The first bit of the name of this input. 53 * @param array $options The options list for this select. 54 * @param string $label The form label for this input. 55 * @param string $selected The name of the selected item in this input. 56 * @param bool $isdisabled Are we disabled? 57 */ 58 public function __construct($name, $options, $label, $selected = '', $isdisabled = false) { 59 $this->selected = $selected; 60 $this->options = $options; 61 $this->isdisabled = $isdisabled; 62 parent::__construct($name, $selected, $label); 63 } 64 65 /** 66 * Nasty function spreading dropdown logic around. 67 * 68 * @return bool 69 */ 70 public function is_dropdown() { 71 return true; 72 } 73 74 /** 75 * Render this element as html. 76 * 77 * @return string 78 */ 79 public function html() { 80 global $OUTPUT; 81 82 $options = $this->options; 83 $selected = $this->selected; 84 85 $context = array( 86 'name' => $this->name, 87 'value' => $this->selected, 88 'tabindex' => 1, 89 'disabled' => !empty($this->isdisabled), 90 'options' => array_map(function($option) use ($options, $selected) { 91 return [ 92 'name' => $options[$option], 93 'value' => $option, 94 'selected' => $selected == $option 95 ]; 96 }, array_keys($options)), 97 'label' => get_string('gradefor', 'gradereport_singleview', $this->label), 98 ); 99 100 return $OUTPUT->render_from_template('gradereport_singleview/dropdown_attribute', $context); 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body