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 |
* File containing the class activity information renderable.
|
|
|
19 |
*
|
|
|
20 |
* @package core_course
|
|
|
21 |
* @copyright 2021 Jun Pataleta <jun@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
namespace core_course\output;
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
use cm_info;
|
|
|
29 |
use completion_info;
|
|
|
30 |
use context;
|
|
|
31 |
use core\activity_dates;
|
|
|
32 |
use core_availability\info;
|
|
|
33 |
use core_completion\cm_completion_details;
|
|
|
34 |
use core_user;
|
|
|
35 |
use core_user\fields;
|
|
|
36 |
use renderable;
|
|
|
37 |
use renderer_base;
|
|
|
38 |
use stdClass;
|
|
|
39 |
use templatable;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* The activity information renderable class.
|
|
|
43 |
*
|
|
|
44 |
* @deprecated since Moodle 4.3 MDL-78744
|
|
|
45 |
* @todo MDL-78926 This class will be deleted in Moodle 4.7
|
|
|
46 |
*
|
|
|
47 |
* @package core_course
|
|
|
48 |
* @copyright 2021 Jun Pataleta <jun@moodle.com>
|
|
|
49 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
50 |
*/
|
|
|
51 |
class activity_information implements renderable, templatable {
|
|
|
52 |
|
|
|
53 |
/** @var cm_info The course module information. */
|
|
|
54 |
protected $cminfo = null;
|
|
|
55 |
|
|
|
56 |
/** @var array The array of relevant dates for this activity. */
|
|
|
57 |
protected $activitydates = [];
|
|
|
58 |
|
|
|
59 |
/** @var cm_completion_details The user's completion details for this activity. */
|
|
|
60 |
protected $cmcompletion = null;
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Constructor.
|
|
|
64 |
*
|
|
|
65 |
* @deprecated since Moodle 4.3
|
|
|
66 |
*
|
|
|
67 |
* @param cm_info $cminfo The course module information.
|
|
|
68 |
* @param cm_completion_details $cmcompletion The course module information.
|
|
|
69 |
* @param array $activitydates The activity dates.
|
|
|
70 |
*/
|
|
|
71 |
public function __construct(cm_info $cminfo, cm_completion_details $cmcompletion, array $activitydates) {
|
|
|
72 |
debugging('activity_information class is deprecated. Use activity_completion and activity_dates instead.', DEBUG_DEVELOPER);
|
|
|
73 |
$this->cminfo = $cminfo;
|
|
|
74 |
$this->cmcompletion = $cmcompletion;
|
|
|
75 |
$this->activitydates = $activitydates;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
80 |
*
|
|
|
81 |
* @deprecated since Moodle 4.3
|
|
|
82 |
*
|
|
|
83 |
* @param renderer_base $output Renderer base.
|
|
|
84 |
* @return stdClass
|
|
|
85 |
*/
|
|
|
86 |
public function export_for_template(renderer_base $output): stdClass {
|
|
|
87 |
debugging('activity_information class is deprecated. Use activity_completion and activity_dates instead.', DEBUG_DEVELOPER);
|
|
|
88 |
|
|
|
89 |
$data = $this->build_completion_data();
|
|
|
90 |
|
|
|
91 |
$data->cmid = $this->cminfo->id;
|
|
|
92 |
$data->activityname = $this->cminfo->get_formatted_name();
|
|
|
93 |
$this->build_dates_data($data);
|
|
|
94 |
$data->hasdates = !empty($this->activitydates);
|
|
|
95 |
|
|
|
96 |
return $data;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Builds the dates data for export.
|
|
|
101 |
*
|
|
|
102 |
* @param stdClass $data
|
|
|
103 |
*/
|
|
|
104 |
protected function build_dates_data(stdClass $data): void {
|
|
|
105 |
foreach ($this->activitydates as $date) {
|
|
|
106 |
if (empty($date['relativeto'])) {
|
|
|
107 |
$date['datestring'] = userdate($date['timestamp'], get_string('strftimedaydatetime', 'core_langconfig'));
|
|
|
108 |
} else {
|
|
|
109 |
$diffstr = get_time_interval_string($date['timestamp'], $date['relativeto']);
|
|
|
110 |
if ($date['timestamp'] >= $date['relativeto']) {
|
|
|
111 |
$date['datestring'] = get_string('relativedatessubmissionduedateafter', 'core_course',
|
|
|
112 |
['datediffstr' => $diffstr]);
|
|
|
113 |
} else {
|
|
|
114 |
$date['datestring'] = get_string('relativedatessubmissionduedatebefore', 'core_course',
|
|
|
115 |
['datediffstr' => $diffstr]);
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
$data->activitydates[] = $date;
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* Builds the completion data for export.
|
|
|
124 |
*
|
|
|
125 |
* @return stdClass
|
|
|
126 |
*/
|
|
|
127 |
protected function build_completion_data(): stdClass {
|
|
|
128 |
global $CFG;
|
|
|
129 |
|
|
|
130 |
$data = new stdClass();
|
|
|
131 |
|
|
|
132 |
$data->hascompletion = $this->cmcompletion->has_completion();
|
|
|
133 |
$data->isautomatic = $this->cmcompletion->is_automatic();
|
|
|
134 |
$data->ismanual = $this->cmcompletion->is_manual();
|
|
|
135 |
$data->showmanualcompletion = $this->cmcompletion->show_manual_completion();
|
|
|
136 |
|
|
|
137 |
// Get the name of the user overriding the completion condition, if available.
|
|
|
138 |
$data->overrideby = null;
|
|
|
139 |
$overrideby = $this->cmcompletion->overridden_by();
|
|
|
140 |
$overridebyname = null;
|
|
|
141 |
if (!empty($overrideby)) {
|
|
|
142 |
$userfields = fields::for_name();
|
|
|
143 |
$overridebyrecord = core_user::get_user($overrideby, 'id ' . $userfields->get_sql()->selects, MUST_EXIST);
|
|
|
144 |
$data->overrideby = fullname($overridebyrecord);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// We'll show only the completion conditions and not the completion status if we're not tracking completion for this user
|
|
|
148 |
// (e.g. a teacher, admin).
|
|
|
149 |
$data->istrackeduser = $this->cmcompletion->is_tracked_user();
|
|
|
150 |
|
|
|
151 |
// Overall completion states.
|
|
|
152 |
$overallcompletion = $this->cmcompletion->get_overall_completion();
|
|
|
153 |
$data->overallcomplete = $overallcompletion == COMPLETION_COMPLETE;
|
|
|
154 |
$data->overallincomplete = $overallcompletion == COMPLETION_INCOMPLETE;
|
|
|
155 |
|
|
|
156 |
// Set an accessible description for manual completions with overridden completion state.
|
|
|
157 |
if (!$data->isautomatic && $data->overrideby) {
|
|
|
158 |
$setbydata = (object)[
|
|
|
159 |
'activityname' => $this->cminfo->get_formatted_name(),
|
|
|
160 |
'setby' => $data->overrideby,
|
|
|
161 |
];
|
|
|
162 |
$setbylangkey = $data->overallcomplete ? 'completion_setby:manual:done' : 'completion_setby:manual:markdone';
|
|
|
163 |
$data->accessibledescription = get_string($setbylangkey, 'course', $setbydata);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
// Whether the completion of this activity controls the availability of other activities/sections in the course.
|
|
|
167 |
$data->withavailability = false;
|
|
|
168 |
$course = $this->cminfo->get_course();
|
|
|
169 |
// An activity with manual completion tracking which is used to enable access to other activities/sections in
|
|
|
170 |
// the course needs to refresh the page after having its completion state toggled. This withavailability flag will enable
|
|
|
171 |
// this functionality on the course homepage. Otherwise, the completion toggling will just happen normally via ajax.
|
|
|
172 |
if ($this->cmcompletion->has_completion() && !$this->cmcompletion->is_automatic()) {
|
|
|
173 |
$data->withavailability = !empty($CFG->enableavailability) && info::completion_value_used($course, $this->cminfo->id);
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
// Whether this activity is visible to the user. If not, completion information will not be shown.
|
|
|
177 |
$data->uservisible = $this->cminfo->uservisible;
|
|
|
178 |
|
|
|
179 |
// Build automatic completion details.
|
|
|
180 |
$details = [];
|
|
|
181 |
foreach ($this->cmcompletion->get_details() as $key => $detail) {
|
|
|
182 |
// Set additional attributes for the template.
|
|
|
183 |
$detail->key = $key;
|
|
|
184 |
$detail->statuscomplete = in_array($detail->status, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]);
|
|
|
185 |
$detail->statuscompletefail = $detail->status == COMPLETION_COMPLETE_FAIL;
|
|
|
186 |
// This is not used by core themes but may be needed in custom themes.
|
|
|
187 |
$detail->statuscompletepass = $detail->status == COMPLETION_COMPLETE_PASS;
|
|
|
188 |
$detail->statusincomplete = $detail->status == COMPLETION_INCOMPLETE;
|
|
|
189 |
|
|
|
190 |
// Add an accessible description to be used for title and aria-label attributes for overridden completion details.
|
|
|
191 |
if ($data->overrideby) {
|
|
|
192 |
$setbydata = (object)[
|
|
|
193 |
'condition' => $detail->description,
|
|
|
194 |
'setby' => $data->overrideby,
|
|
|
195 |
];
|
|
|
196 |
$overridestatus = $detail->statuscomplete ? 'done' : 'todo';
|
|
|
197 |
$detail->accessibledescription = get_string('completion_setby:auto:' . $overridestatus, 'course', $setbydata);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
// We don't need the status in the template.
|
|
|
201 |
unset($detail->status);
|
|
|
202 |
|
|
|
203 |
$details[] = $detail;
|
|
|
204 |
}
|
|
|
205 |
$data->completiondetails = $details;
|
|
|
206 |
|
|
|
207 |
return $data;
|
|
|
208 |
}
|
|
|
209 |
}
|