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 |
namespace report_progress\local;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Helper for report progress.
|
|
|
21 |
*
|
|
|
22 |
* @package report_progress
|
|
|
23 |
* @copyright 2021 The Open University
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL Juv3 or later
|
|
|
25 |
*/
|
|
|
26 |
class helper {
|
|
|
27 |
|
|
|
28 |
/** The default number of results to be shown per page. */
|
|
|
29 |
const COMPLETION_REPORT_PAGE = 25;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Get activities information by the activity include and activity order option.
|
|
|
33 |
*
|
|
|
34 |
* @param \completion_info $completion Completion information of course.
|
|
|
35 |
* @param string $activityinclude Activity type for filtering.
|
|
|
36 |
* @param string $activityorder Activity sort option.
|
|
|
37 |
* @param int $activitysection Section number for filtering.
|
|
|
38 |
* @return array The available activity types and activities array after filtering and sorting.
|
|
|
39 |
* @throws \coding_exception
|
|
|
40 |
*/
|
|
|
41 |
public static function get_activities_to_show(\completion_info $completion, string $activityinclude,
|
|
|
42 |
string $activityorder, int $activitysection = -1): array {
|
|
|
43 |
// Get all activity types.
|
|
|
44 |
$activities = $completion->get_activities();
|
|
|
45 |
$availableactivitytypes = [];
|
|
|
46 |
|
|
|
47 |
foreach ($activities as $activity) {
|
|
|
48 |
if ($activity->modname == $activityinclude || $activitysection == -1 || $activity->sectionnum == $activitysection) {
|
|
|
49 |
$availableactivitytypes[$activity->modname] = $activity->get_module_type_name(true);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
asort($availableactivitytypes);
|
|
|
54 |
$availableactivitytypes = ['all' => get_string('allactivitiesandresources', 'report_progress')] +
|
|
|
55 |
$availableactivitytypes;
|
|
|
56 |
|
|
|
57 |
// Filter activities by section.
|
|
|
58 |
if ($activitysection > -1) {
|
|
|
59 |
$activities = array_filter($activities, function($activity) use ($activitysection) {
|
|
|
60 |
return $activity->sectionnum == $activitysection;
|
|
|
61 |
});
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Filter activities by type.
|
|
|
65 |
if (!empty($activityinclude) && $activityinclude !== 'all') {
|
|
|
66 |
$activities = array_filter($activities, function($activity) use ($activityinclude) {
|
|
|
67 |
return $activity->modname === $activityinclude;
|
|
|
68 |
});
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// The activities are sorted by activity order on course page by default.
|
|
|
72 |
if ($activityorder === 'alphabetical') {
|
|
|
73 |
usort($activities, function($a, $b) {
|
|
|
74 |
return strcmp($a->name, $b->name);
|
|
|
75 |
});
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return [$availableactivitytypes, $activities];
|
|
|
79 |
}
|
|
|
80 |
}
|