-
Notifications
You must be signed in to change notification settings - Fork 3
/
managecategory.php
181 lines (146 loc) · 7.57 KB
/
managecategory.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?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/>.
/**
* Category page for evasys course managers.
*
* @package block_evasys_sync
* @copyright 2022 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use block_evasys_sync\dbtables;
use block_evasys_sync\local\entity\evaluation_state;
use customfield_semester\data_controller;
require_once(__DIR__ . '/../../config.php');
global $CFG, $DB, $USER, $OUTPUT, $PAGE;
require_once($CFG->libdir . '/tablelib.php');
require_login();
$id = required_param('id', PARAM_INT);
$category = core_course_category::get($id);
$evasyscategory = \block_evasys_sync\evasys_category::for_category($id);
$PAGE->set_url(new moodle_url('/blocks/evasys_sync/managecategory.php', ['id' => $id]));
$PAGE->set_context(context_system::instance());
$PAGE->set_title(get_string('evasys_sync', 'block_evasys_sync'));
require_capability('block/evasys_sync:managecourses', $category->get_context());
$cachekey = 'manageroverview';
$cache = cache::make('block_evasys_sync', 'mformdata');
$mform = new \block_evasys_sync\course_manager_filter_form($PAGE->url);
if ($data = $mform->get_data()) {
$cache->set($cachekey, $data);
redirect($PAGE->url);
} else if ($mform->is_cancelled()) {
$cache->delete($cachekey);
redirect($PAGE->url);
}
$data = $cache->get($cachekey);
$field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'), '*', MUST_EXIST);
$fieldcontroller = \core_customfield\field_controller::create($field->id);
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
if ($data) {
$mform->set_data($data);
} else {
$data = new stdClass();
$data->semester = $datacontroller->get_default_value();
}
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
$PAGE->navigation->add('EvaSys', new moodle_url('/blocks/evasys_sync/manageroverview.php'))
->add(
get_string('evaluations', 'block_evasys_sync') . ' in ' . data_controller::get_name_for_semester($data->semester),
new moodle_url('/blocks/evasys_sync/managecategory.php', ['id' => $category->id])
)->make_active();
list($inmanualsql, $params) = $DB->get_in_or_equal(evaluation_state::MANUAL_STATES, SQL_PARAMS_NAMED);
list($incatsql, $incatparams) = $DB->get_in_or_equal($catids, SQL_PARAMS_NAMED);
$params = array_merge($params, $incatparams);
$courseamounts = $DB->get_record_sql('SELECT (COUNT(DISTINCT evalc.courseid) - COUNT(DISTINCT evalmanualc.courseid)) as autoevalcourses, ' .
'COUNT(DISTINCT evalmanualc.courseid) as manualevalcourses, COUNT(DISTINCT ereqc.courseid) as requestcourses, COUNT(DISTINCT c.id) as allcourses, ' .
'(COUNT(DISTINCT c.id) - COUNT(DISTINCT COALESCE(ereqc.courseid, evalc.courseid))) as remainingcourses ' .
'FROM {course} c ' .
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
'LEFT JOIN {' . dbtables::EVAL_REQUESTS_COURSES . '} ereqc ON ereqc.courseid = c.id ' .
'LEFT JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ' .
'LEFT JOIN (
SELECT c1.courseid, c1.id FROM {' . dbtables::EVAL_COURSES . '} c1
JOIN {' . dbtables::EVAL_VERANSTS . '} evalver1 ON evalver1.evalid = c1.evalid ' .
"WHERE evalver1.state $inmanualsql " .
') evalmanualc ON evalmanualc.courseid = c.id ' .
"WHERE cfd.intvalue = :semester AND " .
"c.idnumber <> '' AND " .
"c.category $incatsql ", array_merge(['semesterfieldid' => $field->id, 'semester' => $data->semester], $params)
);
$courseamountsall = $DB->get_record_sql('SELECT COUNT(DISTINCT errors.courseid) as errorcourses, COUNT(DISTINCT c.id) as allcourses ' .
'FROM {course} c ' .
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
'LEFT JOIN {' . dbtables::ERRORS . '} errors ON errors.courseid = c.id AND errors.timehandled IS NULL ' .
"WHERE cfd.intvalue = :semester AND " .
"c.category $incatsql ", array_merge(['semesterfieldid' => $field->id, 'semester' => $data->semester], $params)
);
echo $OUTPUT->header();
/* @var \block_evasys_sync\output\renderer $renderer */
$renderer = $PAGE->get_renderer('block_evasys_sync');
$renderer->print_evasys_category_header($evasyscategory);
echo $OUTPUT->render_from_template('core/search_input', [
'action' => (new moodle_url('/blocks/evasys_sync/coursesearch.php', array('id' => $id)))->out(false),
'uniqid' => 'block_evasys_sync-search-courses',
'inputname' => 'search',
'extraclasses' => 'mb-3',
'inform' => false,
'searchstring' => get_string('search_for_courses', 'block_evasys_sync'),
'hiddenfields' => [
(object) ['type' => 'hidden', 'name' => 'id', 'value' => $id]
]
]);
$mform->display();
$table = new flexible_table('block_evasys_sync-categoryoverview');
$table->define_headers(['', 'Amount of courses']);
$table->define_columns(['table', 'courses']);
$table->define_baseurl($PAGE->url);
$table->setup();
if ($courseamountsall->errorcourses) {
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_errors.php', ['id' => $id]),
get_string('courses_with_errors', 'block_evasys_sync')), $courseamountsall->errorcourses
], 'table-warning');
}
if ($evasyscategory->is_automatic() || $courseamounts->requestcourses) {
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_requests.php', ['id' => $id]),
get_string('courses_with_requests', 'block_evasys_sync')), $courseamounts->requestcourses
]);
}
if ($evasyscategory->is_automatic() || $courseamounts->autoevalcourses) {
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_auto.php', ['id' => $id]),
get_string('courses_with_automatic_evals', 'block_evasys_sync')), $courseamounts->autoevalcourses
]);
}
if (!$evasyscategory->is_automatic() || $courseamounts->manualevalcourses) {
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_manual.php', ['id' => $id]),
get_string('courses_with_manual_evals', 'block_evasys_sync')), $courseamounts->manualevalcourses
]);
}
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_remaining.php', ['id' => $id]),
get_string('courses_without_evals', 'block_evasys_sync')), $courseamounts->remainingcourses
]);
$courseswithoutidnumber = $courseamountsall->allcourses - $courseamounts->allcourses;
if ($courseswithoutidnumber) {
$table->add_data([
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_invalid.php', ['id' => $id]),
get_string('courses_without_idnumber', 'block_evasys_sync')), $courseswithoutidnumber
]);
}
$table->finish_output();
echo $OUTPUT->footer();