Skip to content

Commit af9743d

Browse files
committed
added button in remaining_courses_table.php to start evaluations for all courses
1 parent b71a5a3 commit af9743d

8 files changed

+123
-84
lines changed

amd/src/tablebulkactions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export function init() {
5454
{k: 'action', v: a.getAttribute('data-evasys-action')},
5555
{k: 'sesskey', v: M.cfg.sesskey}
5656
];
57-
if (a.getAttribute('data-evasys-forall') === '1') {
58-
data.push({k: 'all', v: '1'});
57+
if (a.getAttribute('data-evasys-forall') === 1) {
58+
data.push({k: 'all', v: 1});
5959
redirectPost(window.location, data);
6060
} else {
6161
checkboxes.forEach((c) => {

classes/local/table/error_courses_table.php

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class error_courses_table extends \table_sql {
4444

4545
private array $str;
4646

47+
private array $allcourseids;
48+
4749
/**
4850
* Constructor for course_manager_table.
4951
*/
@@ -86,6 +88,8 @@ public function __construct($categoryids, $semester, evasys_category $evasyscate
8688
}
8789
$where = join(" AND ", $where);
8890

91+
$this->allcourseids = $DB->get_records_sql('SELECT c.id as id FROM ' . $from . ' WHERE ' . $where, $params);
92+
8993
$this->set_sql($fields, $from, $where, $params);
9094
$this->column_nosort = ['select', 'teacher', 'tools'];
9195
$this->define_columns(['select', 'courseid', 'teacher', 'lsfid', 'text', 'time', 'tools']);
@@ -171,4 +175,17 @@ public function wrap_html_finish() {
171175
['data-evasys-action' => 'clearerror', 'data-evasys-forall' => 1]
172176
));
173177
}
178+
179+
/**
180+
* Returns all ids of courses that do not have an evaluation yet
181+
*
182+
* @return array
183+
*/
184+
public function get_all_error_courseids() {
185+
$ids = array();
186+
foreach ($this->allcourseids as $courseid) {
187+
$ids[] = $courseid->id;
188+
}
189+
return $ids;
190+
}
174191
}

classes/local/table/manual_courses_table.php

+15-20
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@
4040
*/
4141
class manual_courses_table extends \table_sql {
4242

43-
private array $allcourses;
44-
45-
private string $where;
46-
47-
private string $fields;
48-
49-
private string $from;
50-
51-
private $params;
43+
private $allcourseids;
5244

5345
/**
5446
* Constructor for course_manager_table.
@@ -57,7 +49,7 @@ public function __construct($categoryids, $semester, $coursefullname = null) {
5749
parent::__construct('block_evasys_sync-course_manager_table');
5850
global $DB;
5951

60-
$this->fields = 'c.id as courseid, c.fullname as course, ' .
52+
$fields = 'c.id as courseid, c.fullname as course, ' .
6153
'cfd.intvalue as semester,' .
6254
'eval.id as evalid, ' .
6355
'evalccount.coursecount, ' .
@@ -67,7 +59,7 @@ public function __construct($categoryids, $semester, $coursefullname = null) {
6759
$semesterfield = $DB->get_record('customfield_field',
6860
['shortname' => 'semester', 'type' => 'semester'], '*', MUST_EXIST);
6961

70-
$this->from = '{course} c ' .
62+
$from = '{course} c ' .
7163
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
7264
'JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ' .
7365
'LEFT JOIN {' . dbtables::EVAL . '} eval ON evalc.evalid = eval.id ' .
@@ -101,12 +93,11 @@ public function __construct($categoryids, $semester, $coursefullname = null) {
10193
$where[] = 'c.fullname LIKE :cname';
10294
$params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%';
10395
}
104-
$this->where = join(" AND ", $where);
105-
$this->params = $params;
96+
$where = join(" AND ", $where);
10697

107-
$this->set_sql($this->fields, $this->from, $this->where, $this->params);
98+
$this->allcourseids = $DB->get_records_sql('SELECT c.id as id FROM ' . $from . ' WHERE ' . $where, $params);
10899

109-
$this->allcourses = $DB->get_records_sql('SELECT c.id as courseid, c.fullname as coursename FROM ' . $this->from . ' WHERE ' . $this->where, $this->params);
100+
$this->set_sql($fields, $from, $where, $params);
110101

111102
$this->column_nosort = ['teacher', 'evalinfo', 'tools'];
112103
$this->define_columns(['course', 'teacher', 'evalinfo', 'tools']);
@@ -187,9 +178,13 @@ public function col_tools($row) {
187178
*
188179
* @return array
189180
*/
190-
public function get_all_courses() {
181+
public function get_all_displayed_courses() {
182+
global $DB;
183+
184+
$allcourses = $DB->get_records_sql('SELECT c.id as courseid, c.fullname as coursename FROM ' . $this->sql->from . ' WHERE ' . $this->sql->where, $this->sql->params);
185+
191186
$courses = array();
192-
foreach ($this->allcourses as $course) {
187+
foreach ($allcourses as $course) {
193188
$courses[$course->courseid] = $course->coursename;
194189
}
195190
return $courses;
@@ -209,9 +204,9 @@ public function filter_courses($courses) {
209204

210205
list($insql, $inparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
211206
$where = "c.id $insql";
212-
$params = array_merge($this->params, $inparams);
207+
$params = array_merge($this->sql->params, $inparams);
213208

214-
$where = $this->where . ' AND ' . $where;
215-
$this->set_sql($this->fields, $this->from, $where, $params);
209+
$where = $this->sql->where . ' AND ' . $where;
210+
$this->set_sql($this->sql->fields, $this->sql->from, $where, $params);
216211
}
217212
}

classes/local/table/remaining_courses_table.php

+29-20
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,7 @@ class remaining_courses_table extends \table_sql {
4444

4545
private bool $showbuttons;
4646

47-
private array $allcourses;
48-
49-
private string $where;
50-
51-
private string $fields;
52-
53-
private string $from;
54-
55-
private $params;
47+
private $allcourseids;
5648

5749
/**
5850
* Constructor for course_manager_table.
@@ -64,12 +56,12 @@ public function __construct($categoryids, $semester, evasys_category $evasyscate
6456
$this->evasyscategory = $evasyscategory;
6557
$this->showbuttons = $showbuttons;
6658

67-
$this->fields = 'c.id as courseid, c.fullname as coursename, cfd.intvalue as semester';
59+
$fields = 'c.id as courseid, c.fullname as coursename, cfd.intvalue as semester';
6860

6961
$semesterfield = $DB->get_record('customfield_field',
7062
['shortname' => 'semester', 'type' => 'semester'], '*', MUST_EXIST);
7163

72-
$this->from = '{course} c ' .
64+
$from = '{course} c ' .
7365
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
7466
'LEFT JOIN {' . dbtables::EVAL_REQUESTS_COURSES . '} evreqc ON evreqc.courseid = c.id ' .
7567
'LEFT JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ';
@@ -91,12 +83,11 @@ public function __construct($categoryids, $semester, evasys_category $evasyscate
9183
$where[] = 'c.fullname LIKE :cname';
9284
$params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%';
9385
}
94-
$this->where = join(" AND ", $where);
86+
$where = join(" AND ", $where);
9587

96-
$this->params = $params;
97-
$this->set_sql($this->fields, $this->from, $this->where, $this->params);
88+
$this->allcourseids = $DB->get_records_sql('SELECT c.id as id FROM ' . $from . ' WHERE ' . $where, $params);
9889

99-
$this->allcourses = $DB->get_records_sql('SELECT c.id as courseid, c.fullname as coursename FROM ' . $this->from . ' WHERE ' . $this->where, $this->params);
90+
$this->set_sql($fields, $from, $where, $params);
10091

10192
$this->column_nosort = ['select', 'teacher', 'tools'];
10293
$this->define_columns(['select', 'courseid', 'teacher', 'tools']);
@@ -192,14 +183,32 @@ public function wrap_html_finish() {
192183
*
193184
* @return array
194185
*/
195-
public function get_all_courses() {
186+
public function get_all_displayed_courses() {
187+
global $DB;
188+
189+
$allcourses = $DB->get_records_sql('SELECT c.id as courseid, c.fullname as coursename FROM ' . $this->sql->from . ' WHERE ' . $this->sql->where, $this->sql->params);
190+
196191
$courses = array();
197-
foreach ($this->allcourses as $course) {
192+
foreach ($allcourses as $course) {
198193
$courses[$course->courseid] = $course->coursename;
199194
}
200195
return $courses;
201196
}
202197

198+
/**
199+
* Returns all ids of courses that do not have an evaluation yet
200+
*
201+
* @return array of courseids
202+
*/
203+
public function get_all_remaining_courseids(): array
204+
{
205+
$ids = array();
206+
foreach ($this->allcourseids as $courseid) {
207+
$ids[] = $courseid->id;
208+
}
209+
return $ids;
210+
}
211+
203212
/**
204213
* Filters the table by using set_sql()
205214
*
@@ -214,9 +223,9 @@ public function filter_courses($courses) {
214223

215224
list($insql, $inparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
216225
$where = "c.id $insql";
217-
$params = array_merge($this->params, $inparams);
226+
$params = array_merge($this->sql->params, $inparams);
218227

219-
$where = $this->where . ' AND ' . $where;
220-
$this->set_sql($this->fields, $this->from, $where, $params);
228+
$where = $this->sql->where . ' AND ' . $where;
229+
$this->set_sql($this->sql->fields, $this->sql->from, $where, $params);
221230
}
222231
}

classes/managecategory_filter_table_form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function definition(){
4040
global $DB;
4141
$mform = $this->_form;
4242

43-
$courses = $this->_customdata['table']->get_all_courses();
43+
$courses = $this->_customdata['table']->get_all_displayed_courses();
4444
$mform->addElement('autocomplete', 'coursesearches', get_string('searcharea','search'), $courses, array('multiple' => true));
4545

4646
$searchbutton = $mform->createElement('submit', 'search', get_string('search', 'block_evasys_sync'));

coursesearch.php

+40-27
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,43 @@
5151

5252
$data = $cache->get('manageroverview');
5353

54+
$field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'), '*', MUST_EXIST);
55+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
56+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
57+
58+
if (!$data) {
59+
$data = new stdClass();
60+
$data->semester = $datacontroller->get_default_value();
61+
}
62+
63+
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
64+
65+
$errtable = new error_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
66+
$errtable->define_baseurl($PAGE->url);
67+
68+
$reqtable = new course_manager_table($catids, $data->semester ?? null, $search);
69+
$reqtable->define_baseurl($PAGE->url);
70+
71+
$remtable = new remaining_courses_table($catids, $data->semester ?? null, $evasyscategory,$search);
72+
$remtable->define_baseurl($PAGE->url);
73+
74+
$mantable = new manual_courses_table($catids, $data->semester ?? null, $search);
75+
$mantable->define_baseurl($PAGE->url);
76+
77+
$invtable = new invalid_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
78+
$invtable->define_baseurl($PAGE->url);
79+
5480
$action = optional_param('action', null, PARAM_ALPHAEXT);
5581
$forall = optional_param('all', 0, PARAM_INT);
82+
5683
switch ($action) {
5784
case 'clearerror':
5885
require_sesskey();
59-
$ids = required_param_array('ids', PARAM_INT);
86+
if ($forall === 1) {
87+
$ids = $errtable->get_all_error_courseids();
88+
} else {
89+
$ids = required_param_array('ids', PARAM_INT);
90+
}
6091
list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
6192
$params['time'] = time();
6293
$params['evasyscat'] = $evasyscategory->get('id');
@@ -67,7 +98,7 @@
6798
case 'seteval':
6899
require_sesskey();
69100
if ($forall === 1) {
70-
// $courses = array_keys(array_keys($table->get_all_courses()));
101+
$courses = $remtable->get_all_remaining_courseids();
71102
} else {
72103
$courses = required_param_array('ids', PARAM_INT);
73104
}
@@ -87,18 +118,6 @@
87118
redirect($PAGE->url);
88119
}
89120

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-
102121
$PAGE->navigation->add('EvaSys', new moodle_url('/blocks/evasys_sync/manageroverview.php'))
103122
->add(
104123
get_string('evaluations', 'block_evasys_sync') . ' in ' . data_controller::get_name_for_semester($data->semester),
@@ -120,27 +139,28 @@
120139
'extraclasses' => 'mb-3',
121140
'inform' => false,
122141
'searchstring' => get_string('search_for_courses', 'block_evasys_sync'),
142+
// Id as url param doesn't work, so set as hidden field.
123143
'hiddenfields' => [
124144
(object) ['type' => 'hidden', 'name' => 'id', 'value' => $id]
125145
],
126146
'query' => $search
127147
]);
128148

129-
$errtable = new error_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
130-
$errtable->define_baseurl($PAGE->url);
149+
150+
// Output search results ordered by tables the courses are in.
151+
152+
$somethingfound = false;
153+
131154
$errtable->setup();
132155
$errtable->query_db(48, false);
133156
$errtable->build_table();
134157
$errtable->close_recordset();
135158
if ($errtable->started_output) {
136159
echo $OUTPUT->heading('<br>' . get_string('courses_with_errors', 'block_evasys_sync') . '<br>');
137160
$errtable->finish_output();
161+
$somethingfound = true;
138162
}
139163

140-
$somethingfound = false;
141-
142-
$reqtable = new course_manager_table($catids, $data->semester ?? null, $search);
143-
$reqtable->define_baseurl($PAGE->url);
144164
$reqtable->setup();
145165
$reqtable->query_db(48, false);
146166
$reqtable->build_table();
@@ -151,8 +171,6 @@
151171
$somethingfound = true;
152172
}
153173

154-
$remtable = new remaining_courses_table($catids, $data->semester ?? null, $evasyscategory,$search);
155-
$remtable->define_baseurl($PAGE->url);
156174
$remtable->setup();
157175
$remtable->query_db(48, false);
158176
$remtable->build_table();
@@ -163,21 +181,16 @@
163181
$somethingfound = true;
164182
}
165183

166-
$mantable = new manual_courses_table($catids, $data->semester ?? null, $search);
167-
$mantable->define_baseurl($PAGE->url);
168184
$mantable->setup();
169185
$mantable->query_db(48, false);
170186
$mantable->build_table();
171187
$mantable->close_recordset();
172188
if ($mantable->started_output) {
173-
//echo $OUTPUT->heading('');
174189
echo $OUTPUT->heading('<br>' . get_string('courses_with_manual_evals', 'block_evasys_sync') . '<br>');
175190
$mantable->finish_output();
176191
$somethingfound = true;
177192
}
178193

179-
$invtable = new invalid_courses_table($catids, $data->semester ?? null, $evasyscategory, $search);
180-
$invtable->define_baseurl($PAGE->url);
181194
$invtable->setup();
182195
$invtable->query_db(48, false);
183196
$invtable->build_table();

0 commit comments

Comments
 (0)