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 |
* mod_unilabel Activity picker.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_unilabel
|
|
|
21 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
22 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_unilabel\output\component;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Activity picker to choose a internal url to an activity.
|
|
|
30 |
* @package mod_unilabel
|
|
|
31 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
32 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class activity_picker implements \renderable, \templatable {
|
|
|
36 |
/** @var array */
|
|
|
37 |
public $data;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructor.
|
|
|
41 |
*
|
|
|
42 |
* @param \stdClass $course
|
|
|
43 |
* @param string $formid
|
|
|
44 |
*/
|
|
|
45 |
public function __construct(\stdClass $course, $formid) {
|
|
|
46 |
global $OUTPUT;
|
|
|
47 |
|
|
|
48 |
$this->data = [];
|
|
|
49 |
$activities = [];
|
|
|
50 |
$info = get_fast_modinfo($course);
|
|
|
51 |
$strstealthinfo = get_string('hiddenoncoursepage');
|
|
|
52 |
$strhiddeninfo = get_string('hiddenfromstudents');
|
|
|
53 |
$courseformat = course_get_format($course); // Is needed to get a cmdata component object.
|
|
|
54 |
|
|
|
55 |
if ($coursemodules = $info->get_cms()) {
|
|
|
56 |
foreach ($coursemodules as $cm) {
|
|
|
57 |
if ($cm->deletioninprogress || (!$cm->has_view())) {
|
|
|
58 |
continue;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$activityinfo = new \stdClass();
|
|
|
62 |
$activityinfo->activityname = $cm->get_name();
|
|
|
63 |
$activityinfo->url = $cm->get_url();
|
|
|
64 |
if (empty($activityinfo->url)) { // Remove activities without urls like folder showing their content inline.
|
|
|
65 |
continue;
|
|
|
66 |
}
|
|
|
67 |
$activityinfo->modstealth = $cm->is_stealth();
|
|
|
68 |
$activityinfo->stealthinfo = $strstealthinfo;
|
|
|
69 |
|
|
|
70 |
$cmwidget = new \core_courseformat\output\local\content\cm($courseformat, $cm->get_section_info(), $cm);
|
|
|
71 |
$cmdata = $cmwidget->export_for_template($OUTPUT);
|
|
|
72 |
if (!empty($cmdata->modavailability->hasmodavailability)) {
|
|
|
73 |
$activityinfo->availableinfo = $cmdata->modavailability->info;
|
|
|
74 |
$activityinfo->hasavailabilityinfo = 1;
|
|
|
75 |
}
|
|
|
76 |
$activityinfo->hidden = (!$cm->visible) || $cm->is_stealth();
|
|
|
77 |
$activityinfo->hiddeninfo = (!$cm->visible) ? $strhiddeninfo : '';
|
|
|
78 |
|
|
|
79 |
$activityinfo->icon = $cm->get_icon_url();
|
|
|
80 |
$activityinfo->module = $cm->modname;
|
|
|
81 |
$activityinfo->modulename = $cm->get_module_type_name();
|
|
|
82 |
$activityinfo->purpose = plugin_supports('mod', $cm->modname, FEATURE_MOD_PURPOSE, 'none');
|
|
|
83 |
$activityinfo->filterstring = $cm->get_name() . ' ' . $cm->get_module_type_name();
|
|
|
84 |
$activities[] = $activityinfo;
|
|
|
85 |
}
|
|
|
86 |
$this->data['hasactivities'] = true;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
$this->data['activities'] = $activities;
|
|
|
90 |
$this->data['formid'] = $formid;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Export the data for usage in mustache.
|
|
|
95 |
*
|
|
|
96 |
* @param \renderer_base $output
|
|
|
97 |
* @return array
|
|
|
98 |
*/
|
|
|
99 |
public function export_for_template(\renderer_base $output) {
|
|
|
100 |
return $this->data;
|
|
|
101 |
}
|
|
|
102 |
}
|