Skip to content

Commit b71a5a3

Browse files
committed
added search bar for courses in managecategory.php
1 parent e96d773 commit b71a5a3

File tree

4 files changed

+209
-5
lines changed

4 files changed

+209
-5
lines changed

coursesearch.php

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
* Category page displaying search results from managecategory.php for evasys course managers
19+
*
20+
* @package block_evasys_sync
21+
* @copyright 2023 Irina Hoppe Uni Münster
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
use block_evasys_sync\course_manager_table;
26+
use block_evasys_sync\local\table\error_courses_table;
27+
use block_evasys_sync\local\table\invalid_courses_table;
28+
use block_evasys_sync\local\table\manual_courses_table;
29+
use block_evasys_sync\local\table\remaining_courses_table;
30+
use block_evasys_sync\task\evasys_bulk_task;
31+
use customfield_semester\data_controller;
32+
33+
require_once(__DIR__ . '/../../config.php');
34+
global $CFG, $DB, $USER, $OUTPUT, $PAGE;
35+
require_once($CFG->libdir . '/tablelib.php');
36+
37+
require_login();
38+
$id = required_param('id', PARAM_INT);
39+
$search = optional_param('search', null, PARAM_ALPHAEXT);
40+
41+
$category = core_course_category::get($id);
42+
$evasyscategory = \block_evasys_sync\evasys_category::for_category($id);
43+
44+
$PAGE->set_url(new moodle_url('/blocks/evasys_sync/coursesearch.php', ['id' => $id]));
45+
$PAGE->set_context(context_system::instance());
46+
$PAGE->set_title(get_string('evasys_sync', 'block_evasys_sync'));
47+
48+
require_capability('block/evasys_sync:managecourses', $category->get_context());
49+
50+
$cache = cache::make('block_evasys_sync', 'mformdata');
51+
52+
$data = $cache->get('manageroverview');
53+
54+
$action = optional_param('action', null, PARAM_ALPHAEXT);
55+
$forall = optional_param('all', 0, PARAM_INT);
56+
switch ($action) {
57+
case 'clearerror':
58+
require_sesskey();
59+
$ids = required_param_array('ids', PARAM_INT);
60+
list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
61+
$params['time'] = time();
62+
$params['evasyscat'] = $evasyscategory->get('id');
63+
$DB->execute('DELETE FROM {' . \block_evasys_sync\dbtables::ERRORS . '} ' .
64+
" WHERE evasyscategoryid = :evasyscat AND id $insql", $params);
65+
redirect($PAGE->url);
66+
break;
67+
case 'seteval':
68+
require_sesskey();
69+
if ($forall === 1) {
70+
// $courses = array_keys(array_keys($table->get_all_courses()));
71+
} else {
72+
$courses = required_param_array('ids', PARAM_INT);
73+
}
74+
$queuedtasks = \core\task\manager::get_adhoc_tasks(evasys_bulk_task::class);
75+
$tasksofcurrentmodule = array_filter($queuedtasks, fn($task) => $task->get_custom_data()->categoryid === $id);
76+
if(empty($tasksofcurrentmodule)){
77+
$task = new evasys_bulk_task();
78+
$data = new stdClass();
79+
$data->courses = (array) $courses;
80+
$data->categoryid = $id;
81+
$task->set_custom_data($data);
82+
$task->set_userid($USER->id);
83+
\core\task\manager::queue_adhoc_task($task, true);
84+
} else {
85+
\core\notification::warning(get_string("running_crontask", "block_evasys_sync"));
86+
}
87+
redirect($PAGE->url);
88+
}
89+
90+
$field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'), '*', MUST_EXIST);
91+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
92+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
93+
94+
if (!$data) {
95+
$data = new stdClass();
96+
$data->semester = $datacontroller->get_default_value();
97+
}
98+
99+
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
100+
101+
102+
$PAGE->navigation->add('EvaSys', new moodle_url('/blocks/evasys_sync/manageroverview.php'))
103+
->add(
104+
get_string('evaluations', 'block_evasys_sync') . ' in ' . data_controller::get_name_for_semester($data->semester),
105+
new moodle_url('/blocks/evasys_sync/managecategory.php', ['id' => $category->id])
106+
)->add(
107+
get_string('searchresults', 'block_evasys_sync'), new moodle_url('/blocks/evasys_sync/coursesearch.php', ['id' => $category->id, 'search' => $search])
108+
)->make_active();
109+
110+
echo $OUTPUT->header();
111+
112+
/* @var \block_evasys_sync\output\renderer $renderer */
113+
$renderer = $PAGE->get_renderer('block_evasys_sync');
114+
$renderer->print_evasys_category_header($evasyscategory);
115+
116+
echo $OUTPUT->render_from_template('core/search_input', [
117+
'action' => (new moodle_url('/blocks/evasys_sync/coursesearch.php', array('id' => $id)))->out(false),
118+
'uniqid' => 'block_evasys_sync-search-courses',
119+
'inputname' => 'search',
120+
'extraclasses' => 'mb-3',
121+
'inform' => false,
122+
'searchstring' => get_string('search_for_courses', 'block_evasys_sync'),
123+
'hiddenfields' => [
124+
(object) ['type' => 'hidden', 'name' => 'id', 'value' => $id]
125+
],
126+
'query' => $search
127+
]);
128+
129+
$errtable = new error_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
130+
$errtable->define_baseurl($PAGE->url);
131+
$errtable->setup();
132+
$errtable->query_db(48, false);
133+
$errtable->build_table();
134+
$errtable->close_recordset();
135+
if ($errtable->started_output) {
136+
echo $OUTPUT->heading('<br>' . get_string('courses_with_errors', 'block_evasys_sync') . '<br>');
137+
$errtable->finish_output();
138+
}
139+
140+
$somethingfound = false;
141+
142+
$reqtable = new course_manager_table($catids, $data->semester ?? null, $search);
143+
$reqtable->define_baseurl($PAGE->url);
144+
$reqtable->setup();
145+
$reqtable->query_db(48, false);
146+
$reqtable->build_table();
147+
$reqtable->close_recordset();
148+
if ($reqtable->started_output) {
149+
echo $OUTPUT->heading('<br>' . get_string('courses_with_requests', 'block_evasys_sync') . '<br>');
150+
$reqtable->finish_output();
151+
$somethingfound = true;
152+
}
153+
154+
$remtable = new remaining_courses_table($catids, $data->semester ?? null, $evasyscategory,$search);
155+
$remtable->define_baseurl($PAGE->url);
156+
$remtable->setup();
157+
$remtable->query_db(48, false);
158+
$remtable->build_table();
159+
$remtable->close_recordset();
160+
if ($remtable->started_output) {
161+
echo $OUTPUT->heading('<br>' . get_string('courses_without_evals', 'block_evasys_sync') . '<br>');
162+
$remtable->finish_output();
163+
$somethingfound = true;
164+
}
165+
166+
$mantable = new manual_courses_table($catids, $data->semester ?? null, $search);
167+
$mantable->define_baseurl($PAGE->url);
168+
$mantable->setup();
169+
$mantable->query_db(48, false);
170+
$mantable->build_table();
171+
$mantable->close_recordset();
172+
if ($mantable->started_output) {
173+
//echo $OUTPUT->heading('');
174+
echo $OUTPUT->heading('<br>' . get_string('courses_with_manual_evals', 'block_evasys_sync') . '<br>');
175+
$mantable->finish_output();
176+
$somethingfound = true;
177+
}
178+
179+
$invtable = new invalid_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
180+
$invtable->define_baseurl($PAGE->url);
181+
$invtable->setup();
182+
$invtable->query_db(48, false);
183+
$invtable->build_table();
184+
$invtable->close_recordset();
185+
if ($invtable->started_output) {
186+
echo $OUTPUT->heading('<br>' . get_string('courses_without_idnumber', 'block_evasys_sync') . '<br>');
187+
echo html_writer::tag('p', get_string('courses_without_idnumber_help', 'block_evasys_sync'));
188+
$invtable->finish_output();
189+
$somethingfound = true;
190+
}
191+
192+
if (!$somethingfound) {
193+
echo $OUTPUT->heading(get_string('no_searchresults_found', 'block_evasys_sync'));
194+
}
195+
196+
echo $OUTPUT->footer();

lang/de/block_evasys_sync.php

+3
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,6 @@
293293
$string['not_inside_evaluation_category'] = 'Dieser Kurs ist in keiner Evaluationskategorie! Bitte wenden Sie sich an den Learnweb Support.';
294294

295295
$string["running_crontask"] = 'Die Synchronization der ausgewählten Kurse von {$a} zu Evasys wird derzeit durchgeführt. Dies kann evt. einige Minuten dauern. Bitte warten Sie einige Zeit und laden die Seite neu.';
296+
297+
$string['searchresults'] = 'Suchergebnisse';
298+
$string['no_searchresults_found'] = 'Keine Suchergebnisse gefunden';

lang/en/block_evasys_sync.php

+3
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,6 @@
304304
$string['not_inside_evaluation_category'] = 'This course isn\'t inside any evaluation category! Please contact the Learnweb support.';
305305

306306
$string["running_crontask"] = 'The synchronization of the selected courses of {$a} to evasys are currently being processed. This may take a few minutes. Please wait and reload the page.';
307+
308+
$string['searchresults'] = 'Search results';
309+
$string['no_searchresults_found'] = 'No search results found';

managecategory.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,17 @@
113113
$renderer = $PAGE->get_renderer('block_evasys_sync');
114114
$renderer->print_evasys_category_header($evasyscategory);
115115

116-
// TODO course search
117-
/*echo $OUTPUT->render_from_template('core/search_input', [
118-
'action' => (new moodle_url('/blocks/evasys_sync/coursesearch.php', ['id' => $category->id]))->out(false),
116+
echo $OUTPUT->render_from_template('core/search_input', [
117+
'action' => (new moodle_url('/blocks/evasys_sync/coursesearch.php', array('id' => $id)))->out(false),
119118
'uniqid' => 'block_evasys_sync-search-courses',
120119
'inputname' => 'search',
121120
'extraclasses' => 'mb-3',
122121
'inform' => false,
123-
'searchstring' => get_string('search_for_courses', 'block_evasys_sync')
124-
]);*/
122+
'searchstring' => get_string('search_for_courses', 'block_evasys_sync'),
123+
'hiddenfields' => [
124+
(object) ['type' => 'hidden', 'name' => 'id', 'value' => $id]
125+
]
126+
]);
125127

126128
$mform->display();
127129

0 commit comments

Comments
 (0)