-
Notifications
You must be signed in to change notification settings - Fork 0
/
material.php
116 lines (87 loc) · 3.12 KB
/
material.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?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/>.
/**
*
* @package block_cps
* @copyright 2014 Louisiana State University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once '../../config.php';
require_once 'classes/lib.php';
require_once 'material_form.php';
require_login();
if (!cps_material::is_enabled()) {
print_error('not_enabled', 'block_cps', '', cps_material::name());
}
if (!ues_user::is_teacher()) {
print_error('not_teacher', 'block_cps');
}
$teacher = ues_teacher::get(array('userid' => $USER->id));
$non_primaries = (bool) get_config('block_cps', 'material_nonprimary');
$sections = $teacher->sections(!$non_primaries);
if (empty($sections)) {
print_error('no_section', 'block_cps');
}
$_s = ues::gen_str('block_cps');
$blockname = $_s('pluginname');
$heading = cps_material::name();
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_heading($blockname . ': '. $heading);
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($heading);
$PAGE->set_title($heading);
$PAGE->set_url('/blocks/cps/material.php');
$form = new material_form(null, array('sections' => $sections));
if ($form->is_cancelled()) {
redirect(new moodle_url('/my'));
} else if ($data = $form->get_data()) {
$fields = get_object_vars($data);
$current_selections = cps_material::get_all(array('userid' => $USER->id));
foreach ($fields as $name => $value) {
if (!preg_match('/^material_(\d+)/', $name, $matches)) {
continue;
}
$params = array('userid' => $USER->id, 'courseid' => $matches[1]);
$material = cps_material::get($params);
if (!$material) {
$material = new cps_material();
$material->fill_params($params);
}
$material->save();
$material->apply();
unset($current_selections[$material->id]);
}
// Remove deselected
foreach ($current_selections as $material) {
$material->unapply();
$material->delete($material->id);
}
$success = true;
}
$all_materials = cps_material::get_all(array('userid' => $USER->id));
$data = array();
foreach ($all_materials as $material) {
$data['material_' . $material->courseid] = 1;
}
$form->set_data($data);
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help($heading, 'material', 'block_cps');
if (isset($success) and $success) {
echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
}
$form->display();
echo $OUTPUT->footer();