Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace mod_feedback\courseformat;
18
 
19
use core_courseformat\local\overview\overviewitem;
20
use core\output\action_link;
21
use core\output\local\properties\button;
22
use core\output\local\properties\text_align;
23
use core\url;
24
use core\output\pix_icon;
25
 
26
/**
27
 * Class overview
28
 *
29
 * @package    mod_feedback
30
 * @copyright  2025 Ferran Recio <ferran@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class overview extends \core_courseformat\activityoverviewbase {
34
    #[\Override]
35
    public function get_extra_overview_items(): array {
36
        return [
37
            'submitted' => $this->get_extra_submitted_overview(),
38
        ];
39
    }
40
 
41
    #[\Override]
42
    public function get_actions_overview(): ?overviewitem {
43
        global $CFG, $USER;
44
 
45
        if (!has_capability('mod/feedback:viewreports', $this->context)) {
46
            return null;
47
        }
48
 
49
        require_once($CFG->dirroot . '/mod/feedback/lib.php');
50
 
51
        $submissions = feedback_get_completeds_group_count(
52
            $this->cm->get_instance_record()
53
        );
54
        // Normalize the value.
55
        if (!$submissions) {
56
            $submissions = 0;
57
        }
58
        $total = $submissions + feedback_count_incomplete_users($this->cm);
59
 
60
        $content = new action_link(
61
            url: new url('/mod/feedback/show_entries.php', ['id' => $this->cm->id]),
62
            text: get_string(
63
                'count_of_total',
64
                'core',
65
                ['count' => $submissions, 'total' => $total]
66
            ),
67
            attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
68
        );
69
 
70
        return new overviewitem(
71
            name: get_string('responses', 'mod_feedback'),
72
            value: $submissions,
73
            content: $content,
74
            textalign: text_align::CENTER,
75
        );
76
    }
77
 
78
    #[\Override]
79
    public function get_due_date_overview(): ?overviewitem {
80
        $duedate = null;
81
        if (isset($this->cm->customdata['timeclose'])) {
82
            $duedate = $this->cm->customdata['timeclose'];
83
        }
84
 
85
        if (empty($duedate)) {
86
            return new overviewitem(
87
                name: get_string('feedbackclose', 'mod_feedback'),
88
                value: null,
89
                content: '-',
90
            );
91
        }
92
        return new overviewitem(
93
            name: get_string('feedbackclose', 'mod_feedback'),
94
            value: $duedate,
95
            content: userdate($duedate),
96
        );
97
    }
98
 
99
    /**
100
     * Get the submitted status overview item.
101
     *
102
     * @return overviewitem|null The overview item (or null if the user cannot complete the feedback).
103
     */
104
    private function get_extra_submitted_overview(): ?overviewitem {
105
        global $USER;
106
 
107
        if (!has_capability('mod/feedback:complete', $this->context)) {
108
            return null;
109
        }
110
 
111
        $structure = new \mod_feedback_structure(
112
            feedback: $this->cm->get_instance_record(),
113
            cm: $this->cm,
114
            courseid: $this->course->id,
115
            userid: $USER->id,
116
        );
117
 
118
        $value = false;
119
        $content = '-';
120
 
121
        if ($structure->is_already_submitted()) {
122
            $value = true;
123
            $content = new pix_icon(
124
                'i/checkedcircle',
125
                alt: get_string('this_feedback_is_already_submitted', 'mod_feedback'),
126
                attributes: ['class' => 'text-success'],
127
            );
128
        }
129
 
130
        return new overviewitem(
131
            name: get_string('responded', 'mod_feedback'),
132
            value: $value,
133
            content: $content,
134
            textalign: text_align::CENTER,
135
        );
136
    }
137
}