Skip to content

Commit d4903b6

Browse files
Add table for manual evaluations
1 parent 9ce6752 commit d4903b6

6 files changed

+256
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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\local\entity\evaluation_state;
28+
use moodle_url;
29+
30+
defined('MOODLE_INTERNAL') || die;
31+
32+
require_once($CFG->libdir . '/tablelib.php');
33+
34+
/**
35+
* Table listing all courses to manage for the evasys course manager.
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 manual_courses_table extends \table_sql {
42+
43+
/**
44+
* Constructor for course_manager_table.
45+
*/
46+
public function __construct($categoryids, $semester, $coursefullname = null) {
47+
parent::__construct('block_evasys_sync-course_manager_table');
48+
global $DB;
49+
50+
$fields = 'c.id as courseid, c.fullname as course, ' .
51+
'cfd.intvalue as semester,' .
52+
'eval.id as evalid, ' .
53+
'evalccount.coursecount, ' .
54+
'evalvcount.veranstcount, ' .
55+
'evalv.veranstid, evalv.veransttitle, evalv.starttime, evalv.endtime';
56+
57+
$semesterfield = $DB->get_record('customfield_field',
58+
['shortname' => 'semester', 'type' => 'semester'], '*', MUST_EXIST);
59+
60+
$from = '{course} c ' .
61+
'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
62+
'JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ' .
63+
'LEFT JOIN {' . dbtables::EVAL . '} eval ON evalc.evalid = eval.id ' .
64+
'LEFT JOIN (' .
65+
'SELECT evalid, COUNT(courseid) as coursecount FROM {' . dbtables::EVAL_COURSES . '} ' .
66+
'GROUP BY evalid' .
67+
') evalccount ON evalccount.evalid = eval.id ' .
68+
'LEFT JOIN (' .
69+
'SELECT evalid, MIN(id) as minveranstid, COUNT(veranstid) as veranstcount FROM {' . dbtables::EVAL_VERANSTS . '} ' .
70+
'GROUP BY evalid' .
71+
') evalvcount ON evalvcount.evalid = eval.id ' .
72+
'LEFT JOIN {' . dbtables::EVAL_VERANSTS . '} evalv ON evalv.id = evalvcount.minveranstid';
73+
$params = ['semesterfieldid' => $semesterfield->id];
74+
75+
list($insql, $inparams) = $DB->get_in_or_equal(evaluation_state::MANUAL_STATES, SQL_PARAMS_NAMED);
76+
$params = array_merge($params, $inparams);
77+
$where = ['evalv.state ' . $insql];
78+
79+
if ($categoryids != null) {
80+
list($insql, $inparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
81+
$where[] = "c.category $insql";
82+
$params = array_merge($params, $inparams);
83+
}
84+
85+
if ($semester != null) {
86+
$where[] = 'cfd.intvalue = :semester';
87+
$params['semester'] = $semester;
88+
}
89+
90+
if ($coursefullname) {
91+
$where[] = 'c.fullname LIKE :cname';
92+
$params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%';
93+
}
94+
$where = join(" AND ", $where);
95+
96+
$this->set_sql($fields, $from, $where, $params);
97+
$this->column_nosort = ['teacher', 'evalinfo', 'tools'];
98+
$this->define_columns(['course', 'teacher', 'evalinfo', 'tools']);
99+
$this->define_headers([
100+
get_string('course'),
101+
get_string('teachers'),
102+
get_string('status'),
103+
''
104+
]);
105+
}
106+
107+
public function col_course($row) {
108+
global $DB;
109+
$output = \html_writer::link(course_get_url($row->courseid), $row->course);
110+
if (!$row->coursecount || $row->coursecount == 1) {
111+
return $output;
112+
}
113+
114+
$othercourses = $DB->get_records_sql('SELECT c.id, c.fullname FROM {course} c ' .
115+
'JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id ' .
116+
'WHERE evalc.evalid = :evalid', ['evalid' => $row->evalid]);
117+
foreach ($othercourses as $othercourse) {
118+
if ($othercourse->id == $row->courseid) {
119+
continue;
120+
}
121+
$output .= '<br>' . \html_writer::link(course_get_url($othercourse->id), $othercourse->fullname, ['class' => 'ml-3 small']);
122+
}
123+
return $output;
124+
}
125+
126+
public function col_teacher($row) {
127+
$users = get_users_by_capability(\context_course::instance($row->courseid), 'moodle/course:update');
128+
$users = array_map(function($user) {
129+
return \html_writer::link(new moodle_url('/user/profile.php', ['id' => $user->id]), fullname($user));
130+
}, $users);
131+
return join(', ', $users);
132+
}
133+
134+
public function col_evalinfo($row) {
135+
global $DB;
136+
137+
if (!$row->evalid) {
138+
return '';
139+
}
140+
$output = '';
141+
/*if ($row->state == 0) {
142+
$output .= 'Pending your approval:<br>';
143+
} else {
144+
$output .= 'Pending the teachers approval:<br>';
145+
}*/
146+
147+
if ($row->veranstcount > 1) {
148+
$evaluations = $DB->get_records(dbtables::EVAL_VERANSTS, ['evalid' => $row->erequestid]);
149+
} else {
150+
$evaluations = [$row];
151+
}
152+
153+
foreach ($evaluations as $evaluation) {
154+
$output .= $evaluation->veransttitle . '<br><span class="d-inline-block small ml-3">' .
155+
userdate($evaluation->starttime) . ' - ' . userdate($evaluation->endtime) . '</span><br>';
156+
}
157+
158+
return $output;
159+
}
160+
161+
/**
162+
* Render tools column.
163+
*
164+
* @param object $row Row data.
165+
* @return string
166+
*/
167+
public function col_tools($row) {
168+
return '';
169+
}
170+
}

classes/remaining_courses_table.php classes/local/table/remaining_courses_table.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
* @copyright 2022 Justus Dieckmann WWU
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
24-
namespace block_evasys_sync;
24+
namespace block_evasys_sync\local\table;
2525

26+
use block_evasys_sync\dbtables;
27+
use block_evasys_sync\evasys_category;
2628
use moodle_url;
2729

2830
defined('MOODLE_INTERNAL') || die;

evalrequest.php

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
throw new Exception('Not yet implemented!'); // TODO automatic.
5454
} else {
5555
$evaluation = \block_evasys_sync\evaluation::from_eval_request($data);
56+
foreach ($evaluation->evaluations as $eval) {
57+
$eval->state = \block_evasys_sync\local\entity\evaluation_state::MANUAL;
58+
}
5659
$errors = \block_evasys_sync\evaluation_manager::insert_participants_for_evaluation($evaluation);
5760
if ($errors) {
5861
$erroroutput = '';

managecategory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@
130130
if ($evasyscategory->is_automatic() || $courseamounts->autoevalcourses) {
131131
$table->add_data([
132132
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_auto.php', ['id' => $id]),
133-
get_string('courses_with_auto_evals', 'block_evasys_sync')), $courseamounts->autoevalcourses
133+
get_string('courses_with_automatic_evals', 'block_evasys_sync')), $courseamounts->autoevalcourses
134134
]);
135135
}
136136

137137
if (!$evasyscategory->is_automatic() || $courseamounts->manualevalcourses) {
138138
$table->add_data([
139-
html_writer::link(null, // TODO manual evaluations table!
139+
html_writer::link(new moodle_url('/blocks/evasys_sync/managecategory_manual.php', ['id' => $id]),
140140
get_string('courses_with_manual_evals', 'block_evasys_sync')), $courseamounts->manualevalcourses
141141
]);
142142
}

managecategory_manual.php

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 for evasys course managers.
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+
25+
use customfield_semester\data_controller;
26+
27+
require_once(__DIR__ . '/../../config.php');
28+
global $DB, $USER, $OUTPUT, $PAGE;
29+
30+
require_login();
31+
32+
$id = required_param('id', PARAM_INT);
33+
34+
$category = core_course_category::get($id);
35+
$evasyscategory = \block_evasys_sync\evasys_category::for_category($id);
36+
37+
$PAGE->set_url(new moodle_url('/blocks/evasys_sync/managecategory_manual.php', ['id' => $id]));
38+
$PAGE->set_context(context_system::instance());
39+
$PAGE->set_title(get_string('evasys_sync', 'block_evasys_sync'));
40+
41+
require_capability('block/evasys_sync:managecourses', $category->get_context());
42+
43+
$cachekey = 'manageroverview';
44+
$cache = cache::make('block_evasys_sync', 'mformdata');
45+
46+
$data = $cache->get($cachekey);
47+
48+
$field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'), '*', MUST_EXIST);
49+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
50+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
51+
52+
if (!$data) {
53+
$data = new stdClass();
54+
$data->semester = $datacontroller->get_default_value();
55+
}
56+
57+
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
58+
59+
$table = new \block_evasys_sync\local\table\manual_courses_table($catids, $data->semester ?? null,
60+
$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_with_manual_evals', '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+
$table->out(48, false);
76+
77+
echo $OUTPUT->footer();

managecategory_remaining.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25-
use block_evasys_sync\remaining_courses_table;
25+
use block_evasys_sync\local\table\remaining_courses_table;
2626
use customfield_semester\data_controller;
2727

2828
require_once(__DIR__ . '/../../config.php');

0 commit comments

Comments
 (0)