Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * Class used to render a feedback input box.
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
 
1441 ariadna 27
use context_course;
28
 
1 efrain 29
defined('MOODLE_INTERNAL') || die;
30
 
31
/**
32
 * Class used to render a feedback input box.
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 feedback extends grade_attribute_format implements unique_value, be_disabled, be_readonly {
39
 
40
    /**
41
     * Name of this input
42
     * @var string $name
43
     */
44
    public $name = 'feedback';
45
 
46
    /**
47
     * Get the value for this input.
48
     *
49
     * @return string The value
50
     */
51
    public function get_value(): ?string {
52
        return $this->grade->feedback ? $this->grade->feedback : '';
53
    }
54
 
55
    /**
56
     * Get the string to use in the label for this input.
57
     *
58
     * @return string The label text
59
     */
60
    public function get_label(): string {
61
        if (!isset($this->grade->label)) {
62
            $this->grade->label = '';
63
        }
64
        return $this->grade->label;
65
    }
66
 
67
    /**
68
     * Determine if this input should be disabled based on the other settings.
69
     *
70
     * @return boolean Should this input be disabled when the page loads.
71
     */
72
    public function is_disabled(): bool {
73
        $locked = 0;
74
        $gradeitemlocked = 0;
75
        $overridden = 0;
76
        /* Disable editing if grade item or grade score is locked
77
        * if any of these items are set,  then we will disable editing
78
        * at some point, we might want to show the reason for the lock
79
        * this code could be simplified, but its more readable for steve's little mind
80
        */
81
        if (!empty($this->grade->locked)) {
82
            $locked = 1;
83
        }
84
        if (!empty($this->grade->grade_item->locked)) {
85
            $gradeitemlocked = 1;
86
        }
87
        if ($this->grade->grade_item->is_overridable_item() and !$this->grade->is_overridden()) {
88
            $overridden = 1;
89
        }
90
        return ($locked || $gradeitemlocked || $overridden);
91
    }
92
 
93
    /**
94
     * Return true if this is read-only.
95
     *
96
     * @return bool
97
     */
98
    public function is_readonly(): bool {
99
        global $USER;
100
        return empty($USER->editing);
101
    }
102
 
103
    /**
104
     * Create a text_attribute for this ui element.
105
     *
106
     * @return element
107
     */
108
    public function determine_format(): element {
1441 ariadna 109
        if (($this->grade->is_hidden() || $this->grade->grade_item->is_hidden()) &&
110
            !has_capability('moodle/grade:viewhidden', context_course::instance($this->grade->grade_item->courseid))) {
111
            return new empty_element();
112
        }
1 efrain 113
        return new text_attribute(
114
            $this->get_name(),
115
            $this->get_value(),
116
            $this->get_label(),
117
            $this->is_disabled(),
118
            $this->is_readonly()
119
        );
120
    }
121
 
122
    /**
123
     * Update the value for this input.
124
     *
125
     * @param string $value The new feedback value.
126
     * @return null|string Any error message
127
     */
128
    public function set($value) {
129
        $finalgrade = false;
130
        $trimmed = trim($value);
131
        if (empty($trimmed)) {
132
            $feedback = null;
133
        } else {
134
            $feedback = $value;
135
        }
136
 
137
        $this->grade->grade_item->update_final_grade(
138
            $this->grade->userid, $finalgrade, 'singleview',
139
            $feedback, FORMAT_MOODLE
140
        );
141
    }
142
}