Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Checkbox element used for bulk inserting values in the gradebook.
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
/**
30
 * Checkbox element used for bulk inserting values in the gradebook.
31
 *
32
 * @package   gradereport_singleview
33
 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class bulk_insert extends element {
37
 
38
    /** @var string $applyname To store the "apply" suffix. */
39
    protected $applyname;
40
 
41
    /** @var string $selectname To store the "type" suffix. */
42
    protected $selectname;
43
 
44
    /** @var string $insertname To store the "value" suffix. */
45
    protected $insertname;
46
 
47
    /**
48
     * Constructor
49
     *
50
     * @param mixed $item The grade item or user.
51
     */
52
    public function __construct($item) {
53
        $this->name = 'bulk_' . $item->id;
54
        $this->applyname = $this->name_for('apply');
55
        $this->selectname = $this->name_for('type');
56
        $this->insertname = $this->name_for('value');
57
    }
58
 
59
    /**
60
     * Is this checkbox checked?
61
     *
62
     * @param array|object $data The form data
63
     * @return bool
64
     */
65
    public function is_applied($data): bool {
66
        return isset($data->{$this->applyname});
67
    }
68
 
69
    /**
70
     * Get the type of this input (user or grade)
71
     *
72
     * @param array|object $data The form data
73
     * @return string
74
     */
75
    public function get_type($data): string {
76
        return $data->{$this->selectname};
77
    }
78
 
79
    /**
80
     * Get the value from either the user or grade.
81
     *
82
     * @param array|object $data The form data
83
     * @return string
84
     */
85
    public function get_insert_value($data): string {
86
        return $data->{$this->insertname};
87
    }
88
 
89
    /**
90
     * Generate the html for this form element.
91
     *
92
     * @return string HTML
93
     */
94
    public function html(): string {
95
        global $OUTPUT;
96
 
97
        $text = new text_attribute($this->insertname, "0", 'bulk');
98
        $context = (object) [
99
            'label' => get_string('bulklegend', 'gradereport_singleview'),
100
            'applylabel' => get_string('bulkperform', 'gradereport_singleview'),
101
            'applyname' => $this->applyname,
102
            'menuname' => $this->selectname,
103
            'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'),
104
            'menuoptions' => [
105
                ['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')],
106
                ['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true],
107
            ],
108
            'valuename' => $this->insertname,
109
            'valuefield' => $text->html()
110
        ];
111
 
112
        return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context);
113
    }
114
 
115
    /**
116
     * This form element has 3 elements with different suffixes.
117
     * Generate the name with the suffix.
118
     *
119
     * @param string $extend The suffix.
120
     * @return string
121
     */
122
    private function name_for($extend) {
123
        return "{$this->name}_$extend";
124
    }
125
}