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_assign\courseformat;
18
 
19
use assign;
20
use cm_info;
21
use core_courseformat\local\overview\overviewitem;
22
use core\output\action_link;
23
use core\output\local\properties\text_align;
24
use core\output\local\properties\button;
25
use core\url;
26
use mod_assign\dates;
27
 
28
/**
29
 * Assignment overview integration.
30
 *
31
 * @package    mod_assign
32
 * @copyright  2025 Ferran Recio <ferran@moodle.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class overview extends \core_courseformat\activityoverviewbase {
36
    /** @var assign $assign the assign instance. */
37
    private assign $assign;
38
 
39
    /**
40
     * Constructor.
41
     *
42
     * @param cm_info $cm the course module instance.
43
     * @param \core\output\renderer_helper $rendererhelper the renderer helper.
44
     */
45
    public function __construct(
46
        cm_info $cm,
47
        /** @var \core\output\renderer_helper $rendererhelper the renderer helper */
48
        protected readonly \core\output\renderer_helper $rendererhelper,
49
    ) {
50
        global $CFG;
51
        require_once($CFG->dirroot . '/mod/assign/locallib.php');
52
        parent::__construct($cm);
53
        $this->assign = new assign($this->context, $this->cm, $this->cm->get_course());
54
    }
55
 
56
    #[\Override]
57
    public function get_due_date_overview(): ?overviewitem {
58
        global $USER;
59
 
60
        $dates = new dates($this->cm, $USER->id);
61
        $duedate = $dates->get_due_date();
62
 
63
        if (empty($duedate)) {
64
            return new overviewitem(
65
                name: get_string('duedate', 'assign'),
66
                value: null,
67
                content: '-',
68
            );
69
        }
70
 
71
        $content = userdate($duedate);
72
 
73
        return new overviewitem(
74
            name: get_string('duedate', 'assign'),
75
            value: $duedate,
76
            content: $content,
77
        );
78
    }
79
 
80
    #[\Override]
81
    public function get_actions_overview(): ?overviewitem {
82
        if (!has_capability('mod/assign:grade', $this->context)) {
83
            return null;
84
        }
85
        $needgrading = $this->assign->count_submissions_need_grading();
86
 
87
        $alertlabel = get_string('numberofsubmissionsneedgrading', 'assign');
88
        $name = get_string('gradeverb');
89
 
90
        $badge = '';
91
        if ($needgrading > 0) {
92
            $renderer = $this->rendererhelper->get_core_renderer();
93
            $badge = $renderer->notice_badge(
94
                contents: $needgrading,
95
                title: $alertlabel,
96
            );
97
        }
98
 
99
        $content = new action_link(
100
            url: new url('/mod/assign/view.php', ['id' => $this->cm->id, 'action' => 'grading']),
101
            text: $name . $badge,
102
            attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
103
        );
104
 
105
        return new overviewitem(
106
            name: get_string('actions'),
107
            value: $name,
108
            content: $content,
109
            textalign: text_align::CENTER,
110
            alertcount: $needgrading,
111
            alertlabel: $alertlabel,
112
        );
113
    }
114
 
115
    #[\Override]
116
    public function get_extra_overview_items(): array {
117
        return [
118
            'submissions' => $this->get_extra_submissions_overview(),
119
            'submissionstatus' => $this->get_extra_submission_status_overview(),
120
        ];
121
    }
122
 
123
    /**
124
     * Retrieves an overview of submissions for the assignment.
125
     *
126
     * @return overviewitem|null An overview item c, or null if the user lacks the required capability.
127
     */
128
    private function get_extra_submissions_overview(): ?overviewitem {
129
        global $USER;
130
 
131
        if (!has_capability('mod/assign:grade', $this->cm->context)) {
132
            return null;
133
        }
134
 
135
        $activitygroup = groups_get_activity_group($this->cm);
136
        $submissions = $this->assign->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
137
        $total = $this->assign->count_participants($activitygroup);
138
 
139
        $content = new action_link(
140
            url: new url('/mod/assign/view.php', ['id' => $this->cm->id, 'action' => 'grading']),
141
            text: get_string(
142
                'count_of_total',
143
                'core',
144
                ['count' => $submissions, 'total' => $total]
145
            ),
146
            attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
147
        );
148
 
149
        return new overviewitem(
150
            name: get_string('submissions', 'assign'),
151
            value: $submissions,
152
            content: $content,
153
            textalign: text_align::CENTER,
154
        );
155
    }
156
 
157
    /**
158
     * Retrieves the submission status overview for the current user.
159
     *
160
     * @return overviewitem|null The overview item, or null if the user does not have the required capabilities.
161
     */
162
    private function get_extra_submission_status_overview(): ?overviewitem {
163
        global $USER;
164
 
165
        if (
166
            !has_capability('mod/assign:submit', $this->context)
167
            || has_capability('moodle/site:config', $this->context)
168
        ) {
169
            return null;
170
        }
171
 
172
        if ($this->assign->get_instance()->teamsubmission) {
173
            $usersubmission = $this->assign->get_group_submission($USER->id, 0, false);
174
        } else {
175
            $usersubmission = $this->assign->get_user_submission($USER->id, false);
176
        }
177
 
178
        if (!empty($usersubmission->status)) {
179
            $submittedstatus = get_string('submissionstatus_' . $usersubmission->status, 'assign');
180
        } else {
181
            $submittedstatus = get_string('submissionstatus_', 'assign');
182
        }
183
 
184
        return new overviewitem(
185
            name: get_string('submissionstatus', 'assign'),
186
            value: $submittedstatus,
187
            content: $submittedstatus,
188
        );
189
    }
190
}