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 * Class that represents the exclude checkbox on a grade_grade. 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 defined('MOODLE_INTERNAL') || die; 28 29 use grade_grade; 30 31 /** 32 * Class that represents the exclude checkbox on a grade_grade. 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 exclude extends grade_attribute_format implements be_checked, be_disabled { 39 40 /** @var string $name The name of the input */ 41 public $name = 'exclude'; 42 43 /** @var bool $disabled Is the checkbox disabled? */ 44 public $disabled = false; 45 46 /** 47 * Is it checked? 48 * 49 * @return bool 50 */ 51 public function is_checked() { 52 return $this->grade->is_excluded(); 53 } 54 55 /** 56 * Is it disabled? 57 * 58 * @return bool 59 */ 60 public function is_disabled() { 61 return $this->disabled; 62 } 63 64 /** 65 * Generate the element used to render the UI 66 * 67 * @return element 68 */ 69 public function determine_format() { 70 return new checkbox_attribute( 71 $this->get_name(), 72 $this->get_label(), 73 $this->is_checked(), 74 $this->is_disabled() 75 ); 76 } 77 78 /** 79 * Get the label for the form input 80 * 81 * @return string 82 */ 83 public function get_label() { 84 if (!isset($this->grade->label)) { 85 $this->grade->label = ''; 86 } 87 return $this->grade->label; 88 } 89 90 /** 91 * Set the value that was changed in the form. 92 * 93 * @param string $value The value to set. 94 * @return mixed string|bool An error message or false. 95 */ 96 public function set($value) { 97 if (empty($this->grade->id)) { 98 if (empty($value)) { 99 return false; 100 } 101 102 $gradeitem = $this->grade->grade_item; 103 104 // Fill in arbitrary grade to be excluded. 105 $gradeitem->update_final_grade( 106 $this->grade->userid, null, 'singleview', null, FORMAT_MOODLE 107 ); 108 109 $gradeparams = array( 110 'userid' => $this->grade->userid, 111 'itemid' => $this->grade->itemid 112 ); 113 114 $this->grade = grade_grade::fetch($gradeparams); 115 $this->grade->grade_item = $gradeitem; 116 } 117 118 $state = $value == 0 ? false : true; 119 120 $this->grade->set_excluded($state); 121 122 $this->grade->grade_item->get_parent_category()->force_regrading(); 123 return false; 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body