Skip to content

Commit 6c6ffa6

Browse files
Add table listing courses without idnumber
1 parent 28bc9af commit 6c6ffa6

5 files changed

+238
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
* Table listing all courses to manage for the evasys course manager.
19+
*
20+
* @package block_evasys_sync
21+
* @copyright 2022 Justus Dieckmann WWU
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace block_evasys_sync\local\table;
25+
26+
use block_evasys_sync\dbtables;
27+
use block_evasys_sync\evasys_category;
28+
use moodle_url;
29+
30+
defined('MOODLE_INTERNAL') || die;
31+
32+
require_once($CFG->libdir . '/tablelib.php');
33+
34+
/**
35+
* Table listing all invalid courses (without idnumber).
36+
*
37+
* @package block_evasys_sync
38+
* @copyright 2022 Justus Dieckmann WWU
39+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40+
*/
41+
class invalid_courses_table extends \table_sql {
42+
43+
private evasys_category $evasyscategory;
44+
45+
/**
46+
* Constructor for course_manager_table.
47+
*/
48+
public function __construct($categoryids, $semester, evasys_category $evasyscategory, $coursefullname = null) {
49+
parent::__construct('block_evasys_sync-course_manager_table');
50+
global $DB, $PAGE, $OUTPUT;
51+
52+
$this->evasyscategory = $evasyscategory;
53+
54+
$fields = 'c.id as courseid, c.fullname as coursename, cfd.intvalue as semester';
55+
56+
$semesterfield = $DB->get_record('customfield_field',
57+
['shortname' => 'semester', 'type' => 'semester'], '*', MUST_EXIST);
58+
59+
$from = '{course} c ' .
60+
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
61+
'LEFT JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ';
62+
$params = ['semesterfieldid' => $semesterfield->id];
63+
$where = ["c.idnumber = ''"];
64+
65+
if ($categoryids != null) {
66+
list($insql, $inparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
67+
$where[] = "c.category $insql";
68+
$params = array_merge($params, $inparams);
69+
}
70+
71+
if ($semester != null) {
72+
$where[] = 'cfd.intvalue = :semester';
73+
$params['semester'] = $semester;
74+
}
75+
76+
if ($coursefullname) {
77+
$where[] = 'c.fullname LIKE :cname';
78+
$params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%';
79+
}
80+
$where = join(" AND ", $where);
81+
82+
$this->set_sql($fields, $from, $where, $params);
83+
$this->column_nosort = ['select', 'teacher', 'tools'];
84+
$this->define_columns(['select', 'courseid', 'teacher', 'tools']);
85+
$this->define_headers([
86+
$OUTPUT->render(new \core\output\checkbox_toggleall('evasys-remaining', true, [
87+
'id' => 'select-all-evasys-remaining',
88+
'name' => 'select-all-evasys-remaining',
89+
'label' => get_string('selectall'),
90+
'labelclasses' => 'sr-only',
91+
'classes' => 'm-1',
92+
'checked' => false,
93+
])),
94+
get_string('course'),
95+
get_string('teachers'),
96+
''
97+
]);
98+
99+
$PAGE->requires->js_call_amd('block_evasys_sync/tablebulkactions', 'init');
100+
}
101+
102+
public function col_select($row) {
103+
global $OUTPUT;
104+
$checkbox = new \core\output\checkbox_toggleall('evasys-remaining', false, [
105+
'classes' => 'usercheckbox m-1',
106+
'id' => 'evasys-remaining' . $row->courseid,
107+
'name' => 'bulkcheckbox-select',
108+
'value' => $row->courseid,
109+
'checked' => false,
110+
'label' => get_string('selectitem', 'moodle', $row->courseid),
111+
'labelclasses' => 'accesshide',
112+
]);
113+
return $OUTPUT->render($checkbox);
114+
}
115+
116+
public function col_courseid($row) {
117+
return \html_writer::link(course_get_url($row->courseid), $row->coursename);
118+
}
119+
120+
public function col_teacher($row) {
121+
$users = get_users_by_capability(\context_course::instance($row->courseid), 'block/evasys_sync:teacherforcourse');
122+
$users = array_map(function($user) {
123+
return \html_writer::link(new moodle_url('/user/profile.php', ['id' => $user->id]), fullname($user));
124+
}, $users);
125+
return join(', ', $users);
126+
}
127+
128+
/**
129+
* Render tools column.
130+
*
131+
* @param object $row Row data.
132+
* @return string
133+
*/
134+
public function col_tools($row) {
135+
global $PAGE, $OUTPUT;
136+
return '';
137+
}
138+
139+
public function wrap_html_finish() {
140+
global $OUTPUT;
141+
parent::wrap_html_finish();
142+
}
143+
}

lang/de/block_evasys_sync.php

+2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@
258258
$string['courses_with_automatic_evals'] = 'Kurse mit automatischen Evaluationen';
259259
$string['courses_with_manual_evals'] = 'Kurse mit bereits beantragten Evaluationen';
260260
$string['courses_without_evals'] = 'Kurse ohne Evaluationen';
261+
$string['courses_without_idnumber'] = 'Kurse, bei denen keine Evaluation möglich ist (fehlende Kurs-ID)';
262+
$string['courses_without_idnumber_help'] = 'Diese Kurse haben keine ID gesetzt. Jeder Kurs, der evaluiert werden soll, braucht auch eine Kurs-ID, um im EvaSys-System identifiziert werden zu können. Falls Sie Kurs-IDs nicht bearbeiten können, wenden Sie sich bitte an den Support!';
261263

262264
$string['set_default_eval'] = 'Standardevaluation planen';
263265
$string['set_default_eval_for_selected'] = 'Standardevaluation für alle ausgewählten planen';

lang/en/block_evasys_sync.php

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@
269269
$string['courses_with_automatic_evals'] = 'Courses with automatic evaluations';
270270
$string['courses_with_manual_evals'] = 'Courses with already requested evaluations';
271271
$string['courses_without_evals'] = 'Courses without evaluations';
272+
$string['courses_without_idnumber'] = 'Courses for which no evaluation is possible (missing Course ID)';
273+
$string['courses_without_idnumber_help'] = 'These courses have no ID set. Any to-be-evaluated courses have to have an ID in order to be able to be identified in EvaSys. If you can\'t edit course IDs, please reach out to the support!';
272274

273275
$string['set_default_eval'] = 'Set default evaluation';
274276
$string['set_default_eval_for_selected'] = 'Set default evaluation for selected';

managecategory.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
$params = array_merge($params, $incatparams);
8282

8383
$courseamounts = $DB->get_record_sql('SELECT (COUNT(evalc.id) - COUNT(evalmanualc.id)) as autoevalcourses, ' .
84-
'COUNT(evalmanualc.id) as manualevalcourses, COUNT(ereqc.id) as requestcourses, ' .
84+
'COUNT(evalmanualc.id) as manualevalcourses, COUNT(ereqc.id) as requestcourses, COUNT(*) as allcourses, ' .
8585
'(COUNT(*) - COUNT(COALESCE(ereqc.id, evalc.id))) as remainingcourses ' .
8686
'FROM {course} c ' .
8787
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
@@ -97,7 +97,7 @@
9797
"c.category $incatsql ", array_merge(['semesterfieldid' => $field->id, 'semester' => $data->semester], $params)
9898
);
9999

100-
$courseamountswithidnumber = $DB->get_record_sql('SELECT COUNT(errors.id) as errorcourses ' .
100+
$courseamountsall = $DB->get_record_sql('SELECT COUNT(errors.id) as errorcourses, COUNT(*) as allcourses ' .
101101
'FROM {course} c ' .
102102
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
103103
'LEFT JOIN {' . dbtables::ERRORS . '} errors ON errors.courseid = c.id AND errors.timehandled IS NULL ' .
@@ -133,10 +133,10 @@
133133

134134
$table->setup();
135135

136-
if ($courseamountswithidnumber->errorcourses) {
136+
if ($courseamountsall->errorcourses) {
137137
$table->add_data([
138138
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_errors.php', ['id' => $id]),
139-
get_string('courses_with_errors', 'block_evasys_sync')), $courseamountswithidnumber->errorcourses
139+
get_string('courses_with_errors', 'block_evasys_sync')), $courseamountsall->errorcourses
140140
], 'table-warning');
141141
}
142142

@@ -166,6 +166,14 @@
166166
get_string('courses_without_evals', 'block_evasys_sync')), $courseamounts->remainingcourses
167167
]);
168168

169+
$courseswithoutidnumber = $courseamountsall->allcourses - $courseamounts->allcourses;
170+
if ($courseswithoutidnumber) {
171+
$table->add_data([
172+
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_invalid.php', ['id' => $id]),
173+
get_string('courses_without_idnumber', 'block_evasys_sync')), $courseswithoutidnumber
174+
]);
175+
}
176+
169177
$table->finish_output();
170178

171179
echo $OUTPUT->footer();

managecategory_invalid.php

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
* Page listing all invalid courses (without idnumber).
19+
*
20+
* @package block_evasys_sync
21+
* @copyright 2023 Justus Dieckmann WWU
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
use block_evasys_sync\local\table\invalid_courses_table;
26+
use customfield_semester\data_controller;
27+
28+
require_once(__DIR__ . '/../../config.php');
29+
global $DB, $USER, $OUTPUT, $PAGE;
30+
31+
require_login();
32+
33+
$id = required_param('id', PARAM_INT);
34+
35+
$category = core_course_category::get($id);
36+
$evasyscategory = \block_evasys_sync\evasys_category::for_category($id);
37+
38+
$PAGE->set_url(new moodle_url('/blocks/evasys_sync/managecategory_invalid.php', ['id' => $id]));
39+
$PAGE->set_context(context_system::instance());
40+
$PAGE->set_title(get_string('evasys_sync', 'block_evasys_sync'));
41+
42+
require_capability('block/evasys_sync:managecourses', $category->get_context());
43+
44+
$cachekey = 'manageroverview';
45+
$cache = cache::make('block_evasys_sync', 'mformdata');
46+
47+
$data = $cache->get($cachekey);
48+
49+
$field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'), '*', MUST_EXIST);
50+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
51+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
52+
53+
if (!$data) {
54+
$data = new stdClass();
55+
$data->semester = $datacontroller->get_default_value();
56+
}
57+
58+
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
59+
60+
$table = new invalid_courses_table($catids, $data->semester ?? null, $evasyscategory, $data->coursename ?? null);
61+
$table->define_baseurl($PAGE->url);
62+
63+
$PAGE->navigation->add('EvaSys', new moodle_url('/blocks/evasys_sync/manageroverview.php'))
64+
->add(
65+
get_string('evaluations', 'block_evasys_sync') . ' in ' . data_controller::get_name_for_semester($data->semester),
66+
new moodle_url('/blocks/evasys_sync/managecategory.php', ['id' => $category->id])
67+
)->add(get_string('courses_without_idnumber', 'block_evasys_sync'), $PAGE->url)->make_active();
68+
69+
echo $OUTPUT->header();
70+
71+
/* @var \block_evasys_sync\output\renderer $renderer */
72+
$renderer = $PAGE->get_renderer('block_evasys_sync');
73+
$renderer->print_evasys_category_header($evasyscategory);
74+
75+
echo html_writer::tag('p', get_string('courses_without_idnumber_help', 'block_evasys_sync'));
76+
77+
$table->out(48, false);
78+
79+
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)