-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathitem.php
More file actions
82 lines (79 loc) · 3.37 KB
/
Copy pathitem.php
File metadata and controls
82 lines (79 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/report/lp/lib.php');
require_once($CFG->libdir . '/formslib.php');
$id = optional_param('id', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$shortname = optional_param('shortname', null, PARAM_ALPHAEXT);
// If id given, get existing item object
if ($id) {
$itemconfiguration = new report_lp\local\persistents\item_configuration($id);
$courseid = $itemconfiguration->get('courseid');
} else { // If id not given, courseid and shortname required for new item.
if ($courseid <= 0) {
throw new moodle_exception('missingparam', null, null, 'courseid');
}
if (empty($shortname)) {
throw new moodle_exception('missingparam', null, null, 'shortname');
}
}
$course = get_course($courseid);
$systemcontext = context_system::instance();
$itemtypelist = new report_lp\local\item_type_list();
$itemfactory = new report_lp\local\factories\item($course, $itemtypelist);
if (isset($itemconfiguration)) {
$item = $itemfactory->get_item_from_persistent($itemconfiguration);
} else if (!is_null($shortname)){
$item = $itemfactory->get_item_from_shortname($shortname);
} else {
throw new moodle_exception('itemnotloaded', 'report_lp');
}
$configurl = report_lp\local\factories\url::get_config_url($course);
$pageurl = report_lp\local\factories\url::get_item_url($course, $id, $shortname);
require_capability('report/lp:configure', $systemcontext);
$PAGE->set_context($systemcontext);
$PAGE->set_url($pageurl);
$mform = new report_lp\local\forms\item(
null,
[
'course' => $course,
'item' => $item
]
);
$renderer = $PAGE->get_renderer('report_lp');
if ($mform->is_cancelled()) {
redirect($configurl);
}
if ($mform->is_submitted()) {
$data = $mform->get_data();
if ($data) {
$item->get_configuration()->set('usecustomlabel', $data->usecustomlabel);
$item->get_configuration()->set('customlabel', isset($data->customlabel) ? $data->customlabel : '');
$item->get_configuration()->set('parentitemid', $data->parentitemid);
$item->get_configuration()->set('visibletosummary', $data->visibletosummary);
$item->get_configuration()->set('visibletoinstance', $data->visibletoinstance);
$item->get_configuration()->set('visibletolearner', $data->visibletolearner);
$extradata = $mform->get_extra_configuration_data();
$item->get_configuration()->set('extraconfigurationdata', $extradata);
$item->get_configuration()->save();
redirect($configurl);
}
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('configure', 'report_lp', $item->get_name()));
$mform->display();
echo $OUTPUT->footer($course);