2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Checkbox element used for bulk inserting values in the gradebook.
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
25 namespace gradereport_singleview\local\ui;
29 defined('MOODLE_INTERNAL') || die;
32 * Checkbox element used for bulk inserting values in the gradebook.
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
38 class bulk_insert extends element {
43 * @param mixed $item The grade item or user.
45 public function __construct($item) {
46 $this->name = 'bulk_' . $item->id;
47 $this->applyname = $this->name_for('apply');
48 $this->selectname = $this->name_for('type');
49 $this->insertname = $this->name_for('value');
53 * Is this checkbox checked?
55 * @param array $data The form data
58 public function is_applied($data) {
59 return isset($data->{$this->applyname});
63 * Get the type of this input (user or grade)
65 * @param array $data The form data
68 public function get_type($data) {
69 return $data->{$this->selectname};
73 * Get the value from either the user or grade.
75 * @param array $data The form data
78 public function get_insert_value($data) {
79 return $data->{$this->insertname};
83 * Generate the html for this form element.
87 public function html() {
88 $insertvalue = get_string('bulkinsertvalue', 'gradereport_singleview');
89 $insertappliesto = get_string('bulkappliesto', 'gradereport_singleview');
91 $insertoptions = array(
92 'all' => get_string('all_grades', 'gradereport_singleview'),
93 'blanks' => get_string('blanks', 'gradereport_singleview')
96 $selectlabel = html_writer::label(
98 'menu' . $this->selectname
100 $select = html_writer::select(
106 'id' => 'menu' . $this->selectname
110 $textlabel = html_writer::label(
114 $text = new text_attribute($this->insertname, "0", 'bulk');
116 $inner = implode(' ', array(
123 $fieldset = html_writer::tag(
127 get_string('bulklegend', 'gradereport_singleview'),
129 'class' => 'accesshide'
135 $apply = html_writer::checkbox(
139 get_string('bulkperform', 'gradereport_singleview')
141 $applydiv = html_writer::div($apply, 'enable');
143 return $applydiv . $fieldset;
147 * This form element has 3 elements with different suffixes.
148 * Generate the name with the suffix.
150 * @param string $extend The suffix.
153 private function name_for($extend) {
154 return "{$this->name}_$extend";