Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 * A checkbox ui 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 namespace gradereport_singleview\local\ui; 25 26 use html_writer; 27 28 defined('MOODLE_INTERNAL') || die; 29 30 /** 31 * A checkbox ui element. 32 * 33 * @package gradereport_singleview 34 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class checkbox_attribute extends element { 38 39 /** @var bool $ischecked Is it checked? */ 40 private $ischecked; 41 42 /** 43 * Constructor 44 * 45 * @param string $name The element name 46 * @param string $label The label for the form element 47 * @param bool $ischecked Is this thing on? 48 * @param int $locked Is this element locked either 0 or a time. 49 */ 50 public function __construct($name, $label, $ischecked = false, $locked=0) { 51 $this->ischecked = $ischecked; 52 $this->locked = $locked; 53 parent::__construct($name, 1, $label); 54 } 55 56 /** 57 * Nasty function allowing checkbox logic to escape the class. 58 * @return bool 59 */ 60 public function is_checkbox() { 61 return true; 62 } 63 64 /** 65 * Generate the HTML 66 * 67 * @return string 68 */ 69 public function html() { 70 71 $attributes = array( 72 'type' => 'checkbox', 73 'name' => $this->name, 74 'value' => 1, 75 'id' => $this->name 76 ); 77 78 // UCSB fixed user should not be able to override locked grade. 79 if ( $this->locked) { 80 $attributes['disabled'] = 'DISABLED'; 81 } 82 83 $hidden = array( 84 'type' => 'hidden', 85 'name' => 'old' . $this->name 86 ); 87 88 if ($this->ischecked) { 89 $attributes['checked'] = 'CHECKED'; 90 $hidden['value'] = 1; 91 } 92 93 $type = "override"; 94 if (preg_match("/^exclude/", $this->name)) { 95 $type = "exclude"; 96 } 97 98 return ( 99 html_writer::tag('label', 100 get_string($type . 'for', 'gradereport_singleview', $this->label), 101 array('for' => $this->name, 'class' => 'accesshide')) . 102 html_writer::empty_tag('input', $attributes) . 103 html_writer::empty_tag('input', $hidden) 104 ); 105 } 106 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body