Skip to content

Commit ea8f418

Browse files
author
Laur0r
authored
Merge pull request #76 from learnweb/feature/automatic-eval-request-search-and-select-all-courses
Feature/automatic eval request search and select all courses
2 parents 49145f9 + b3b746a commit ea8f418

12 files changed

+487
-36
lines changed

amd/src/tablebulkactions.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 21 additions & 4 deletions
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']);
@@ -166,9 +170,22 @@ public function wrap_html_finish() {
166170
['data-evasys-action' => 'clearerror']
167171
));
168172

169-
/*echo $OUTPUT->render(new \single_button(new moodle_url(''),
170-
get_string('set_default_eval_for_all', 'block_evasys_sync'), 'post', false,
171-
['data-evasys-action' => 'sseteval', 'data_evasys-forall' => 1]
172-
));*/
173+
echo $OUTPUT->render(new \single_button(new moodle_url(''),
174+
get_string('clear_all_errors', 'block_evasys_sync'), 'post', false,
175+
['data-evasys-action' => 'clearerror', 'data-evasys-forall' => 1]
176+
));
177+
}
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;
173190
}
174191
}

classes/local/table/manual_courses_table.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
class manual_courses_table extends \table_sql {
4242

43+
private $allcourseids;
44+
4345
/**
4446
* Constructor for course_manager_table.
4547
*/
@@ -93,7 +95,10 @@ public function __construct($categoryids, $semester, $coursefullname = null) {
9395
}
9496
$where = join(" AND ", $where);
9597

98+
$this->allcourseids = $DB->get_records_sql('SELECT c.id as id FROM ' . $from . ' WHERE ' . $where, $params);
99+
96100
$this->set_sql($fields, $from, $where, $params);
101+
97102
$this->column_nosort = ['teacher', 'evalinfo', 'tools'];
98103
$this->define_columns(['course', 'teacher', 'evalinfo', 'tools']);
99104
$this->define_headers([
@@ -167,4 +172,41 @@ public function col_evalinfo($row) {
167172
public function col_tools($row) {
168173
return '';
169174
}
175+
176+
/**
177+
* Returns all courses that are displayed in this table by courseid => coursename
178+
*
179+
* @return array
180+
*/
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+
186+
$courses = array();
187+
foreach ($allcourses as $course) {
188+
$courses[$course->courseid] = $course->coursename;
189+
}
190+
return $courses;
191+
}
192+
193+
/**
194+
* Filters the table by using set_sql()
195+
*
196+
* @param $courses array of type courseid => coursename
197+
* @return void
198+
* @throws \coding_exception
199+
* @throws \dml_exception
200+
*/
201+
public function filter_courses($courses) {
202+
203+
global $DB;
204+
205+
list($insql, $inparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
206+
$where = "c.id $insql";
207+
$params = array_merge($this->sql->params, $inparams);
208+
209+
$where = $this->sql->where . ' AND ' . $where;
210+
$this->set_sql($this->sql->fields, $this->sql->from, $where, $params);
211+
}
170212
}

classes/local/table/remaining_courses_table.php

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class remaining_courses_table extends \table_sql {
4444

4545
private bool $showbuttons;
4646

47+
private $allcourseids;
48+
4749
/**
4850
* Constructor for course_manager_table.
4951
*/
@@ -83,7 +85,10 @@ public function __construct($categoryids, $semester, evasys_category $evasyscate
8385
}
8486
$where = join(" AND ", $where);
8587

88+
$this->allcourseids = $DB->get_records_sql('SELECT c.id as id FROM ' . $from . ' WHERE ' . $where, $params);
89+
8690
$this->set_sql($fields, $from, $where, $params);
91+
8792
$this->column_nosort = ['select', 'teacher', 'tools'];
8893
$this->define_columns(['select', 'courseid', 'teacher', 'tools']);
8994
$this->define_headers([
@@ -140,7 +145,7 @@ public function col_tools($row) {
140145
if (!$this->evasyscategory->default_period_set() || !$this->showbuttons) {
141146
return '';
142147
}
143-
return $OUTPUT->render(new \single_button(new moodle_url($PAGE->url, ['action' => 'seteval', 'ids[]' => $row->courseid]),
148+
return $OUTPUT->render(new \single_button(new moodle_url($PAGE->url, ['action' => 'seteval', 'ids[]' => $row->courseid, 'id' => $this->evasyscategory->get('course_category')]),
144149
get_string('set_default_eval', 'block_evasys_sync')));
145150
}
146151

@@ -154,22 +159,73 @@ public function wrap_html_start() {
154159
}
155160

156161
public function wrap_html_finish() {
157-
global $OUTPUT;
162+
global $OUTPUT, $PAGE;
158163
parent::wrap_html_finish();
159164
echo "<br>";
160165

161166
if (!$this->evasyscategory->default_period_set() || !$this->showbuttons) {
162167
return;
163168
}
164169

165-
echo $OUTPUT->render(new \single_button(new moodle_url(''),
170+
echo $OUTPUT->render(new \single_button(new moodle_url($PAGE->url),
166171
get_string('set_default_eval_for_selected', 'block_evasys_sync'), 'post', false,
167172
['data-evasys-action' => 'seteval']
168173
));
169174

170-
/*echo $OUTPUT->render(new \single_button(new moodle_url(''),
171-
get_string('set_default_eval_for_all', 'block_evasys_sync'), 'post', false,
172-
['data-evasys-action' => 'sseteval', 'data_evasys-forall' => 1]
173-
));*/
175+
echo $OUTPUT->render(new \single_button(new moodle_url($PAGE->url),
176+
get_string('set_default_eval_for_all', 'block_evasys_sync'), 'post', false,
177+
['data-evasys-action' => 'seteval', 'data-evasys-forall' => 1]
178+
));
179+
}
180+
181+
/**
182+
* Returns all courses that are displayed in this table by courseid => coursename
183+
*
184+
* @return array
185+
*/
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+
191+
$courses = array();
192+
foreach ($allcourses as $course) {
193+
$courses[$course->courseid] = $course->coursename;
194+
}
195+
return $courses;
196+
}
197+
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+
212+
/**
213+
* Filters the table by using set_sql()
214+
*
215+
* @param $courses array of type courseid => coursename
216+
* @return void
217+
* @throws \coding_exception
218+
* @throws \dml_exception
219+
*/
220+
public function filter_courses($courses) {
221+
222+
global $DB;
223+
224+
list($insql, $inparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
225+
$where = "c.id $insql";
226+
$params = array_merge($this->sql->params, $inparams);
227+
228+
$where = $this->sql->where . ' AND ' . $where;
229+
$this->set_sql($this->sql->fields, $this->sql->from, $where, $params);
174230
}
175231
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
namespace block_evasys_sync;
18+
19+
use moodleform;
20+
use stdClass;
21+
22+
defined('MOODLE_INTERNAL') || die;
23+
24+
require_once($CFG->libdir . '/formslib.php');
25+
26+
/**
27+
* Filter moodle form for course manager overview table.
28+
*
29+
* @package block_evasys_sync
30+
* @copyright 2023 Irina Hoppe Uni Muenster
31+
* @license http://www.gnu.org/copyleft/gpl.htmlGNUGPLv3 or later
32+
*/
33+
34+
class managecategory_filter_table_form extends moodleform {
35+
36+
/**
37+
* Defines formelements.
38+
*/
39+
protected function definition(){
40+
global $DB;
41+
$mform = $this->_form;
42+
43+
$courses = $this->_customdata['table']->get_all_displayed_courses();
44+
$mform->addElement('autocomplete', 'coursesearches', get_string('searcharea','search'), $courses, array('multiple' => true));
45+
46+
$searchbutton = $mform->createElement('submit', 'search', get_string('search', 'block_evasys_sync'));
47+
$mform->addElement($searchbutton);
48+
}
49+
50+
public function get_data() {
51+
52+
$mform = $this->_form;
53+
$data = parent::get_data();
54+
55+
// Function is_array is neccessary to avoid filtering if no course is selected.
56+
if ($submit = $mform->getSubmitValue('coursesearches')) {
57+
if (is_array($submit)) {
58+
$data->searchcourse = $submit;
59+
return $data;
60+
} else {
61+
$data = new stdClass();
62+
$data->searchcourse = null;
63+
return $data;
64+
}
65+
}
66+
return null;
67+
}
68+
}

0 commit comments

Comments
 (0)