Skip to content

Commit da30588

Browse files
Begin with new manageroverview page
1 parent 9542750 commit da30588

8 files changed

+323
-5
lines changed

addcourse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
$PAGE->set_title(get_string('add_course_header', 'block_evasys_sync'));
2727

2828
$record = $DB->get_record('block_evasys_sync_courseeval', array('course' => $id));
29-
if ($record !== false and ($record->state > \block_evasys_sync\course_evaluation_allocation::STATE_AUTO_NOTOPENED) and
30-
!is_siteadmin() or !get_config('block_evasys_sync', 'default_his_connection')) {
29+
if ($record !== false and (($record->state > \block_evasys_sync\course_evaluation_allocation::STATE_AUTO_NOTOPENED) and
30+
!is_siteadmin() or !get_config('block_evasys_sync', 'default_his_connection'))) {
3131
echo $OUTPUT->header();
3232
echo get_string('forbidden', 'block_evasys_sync');
3333
echo $OUTPUT->footer();
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
* Filter moodle form for course manager overview table.
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;
25+
26+
use moodleform;
27+
28+
defined('MOODLE_INTERNAL') || die;
29+
30+
require_once($CFG->libdir . '/formslib.php');
31+
32+
/**
33+
* Filter moodle form for course manager overview table.
34+
*
35+
* @package block_evasys_sync
36+
* @copyright 2022 Justus Dieckmann WWU
37+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38+
*/
39+
class course_manager_filter_form extends moodleform {
40+
41+
/**
42+
* Defines form elements.
43+
*/
44+
protected function definition () {
45+
global $DB;
46+
$mform = $this->_form;
47+
48+
if ($field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'))) {
49+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
50+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
51+
$datacontroller->instance_form_definition($mform);
52+
}
53+
54+
$mform->addElement('text', 'coursename', get_string('coursename', 'block_evasys_sync'));
55+
$mform->setType('coursename', PARAM_TEXT);
56+
57+
$this->add_action_buttons(true, get_string('apply', 'block_evasys_sync'));
58+
}
59+
60+
}

classes/course_manager_table.php

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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;
25+
26+
use moodle_url;
27+
28+
defined('MOODLE_INTERNAL') || die;
29+
30+
require_once($CFG->libdir . '/tablelib.php');
31+
32+
/**
33+
* Table listing all courses to manage for the evasys course manager.
34+
*
35+
* @package block_evasys_sync
36+
* @copyright 2022 Justus Dieckmann WWU
37+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38+
*/
39+
class course_manager_table extends \table_sql {
40+
41+
/**
42+
* Constructor for course_manager_table.
43+
*/
44+
public function __construct($categoryids, $semester, $coursefullname = null) {
45+
parent::__construct('block_evasys_sync-course_manager_table');
46+
global $DB;
47+
48+
$fields = 'c.id as courseid, c.fullname as coursename, ' .
49+
'cfd.intvalue as semester, ' .
50+
'ce.state as evalstate, ce.startdate as evalstart, ce.enddate as evalend ';
51+
52+
$semesterfield = $DB->get_record('customfield_field',
53+
['shortname' => 'semester', 'type' => 'semester']) ?: -1;
54+
55+
$from = '{course} c ' .
56+
'LEFT JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' .
57+
'LEFT JOIN {block_evasys_sync_courseeval} ce ON ce.course = c.id ';
58+
$params = ['semesterfieldid' => $semesterfield->id];
59+
$where = ['TRUE'];
60+
61+
if ($categoryids != null) {
62+
list($insql, $inparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
63+
$where[] = "c.categoryid $insql";
64+
$params = array_merge($params, $inparams);
65+
}
66+
67+
if ($semester != null) {
68+
$where[] = 'cfd.intvalue = :semester';
69+
$params['semester'] = $semester;
70+
}
71+
72+
if ($coursefullname) {
73+
$where[] = 'c.fullname LIKE :cname';
74+
$params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%';
75+
}
76+
$where = join(" AND ", $where);
77+
78+
$this->set_sql($fields, $from, $where, $params);
79+
$this->column_nosort = ['tools'];
80+
$this->define_columns(['coursename', 'teacher', 'tools']);
81+
$this->define_headers([
82+
get_string('coursename', 'block_evasys_sync'),
83+
get_string('teachers'),
84+
''
85+
]);
86+
}
87+
88+
public function col_coursename($row) {
89+
return \html_writer::link(course_get_url($row->courseid), $row->coursename);
90+
}
91+
92+
public function col_teacher($row) {
93+
$users = get_users_by_capability(\context_course::instance($row->courseid), 'moodle/course:update');
94+
$users = array_map(function($user) {
95+
return \html_writer::link(new moodle_url('/user/profile.php', ['id' => $user->id]), fullname($user));
96+
}, $users);
97+
return join(', ', $users);
98+
}
99+
100+
/**
101+
* Render tools column.
102+
*
103+
* @param object $row Row data.
104+
* @return string pluginname of the subplugin
105+
*/
106+
public function col_tools($row) {
107+
global $PAGE, $OUTPUT;
108+
return '';
109+
$params = array(
110+
'action' => 'delete',
111+
'cid' => $row->courseid,
112+
'sesskey' => sesskey()
113+
);
114+
115+
if ($this->workflow) {
116+
$params['workflow'] = $this->workflow;
117+
}
118+
119+
$button = new \single_button(new \moodle_url($PAGE->url, $params),
120+
get_string('delete_delay', 'tool_lifecycle'));
121+
return $OUTPUT->render($button);
122+
}
123+
}

db/caches.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
* Cache Definition for block_evasys_sync
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+
defined('MOODLE_INTERNAL') || die();
26+
27+
$definitions = array(
28+
'mformdata' => array(
29+
'mode' => cache_store::MODE_SESSION,
30+
'simplekeys' => true
31+
)
32+
);

db/install.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* install.php
1010
*
1111
* @package block_evasys_sync
12-
* @copyright 2022 Justus Dieckmann
12+
* @copyright 2022 Justus Dieckmann WWU
1313
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1414
*/
1515

@@ -24,8 +24,11 @@ function xmldb_block_evasys_sync_create_role() {
2424
return;
2525
}
2626

27+
// Just reload access.php, doesn't happen until later by default.
28+
update_capabilities('block_evasys_sync');
29+
2730
// Set up the course manager role.
2831
$rid = create_role('EvaSys course manager', 'evasysmanager', '');
2932
assign_capability('block/evasys_sync:managecourses', CAP_ALLOW, $rid, context_system::instance());
30-
set_role_contextlevels($rid, [CONTEXT_COURSECAT, CONTEXT_COURSE]);
33+
set_role_contextlevels($rid, [CONTEXT_COURSECAT]);
3134
}

lang/de/block_evasys_sync.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,6 @@
221221

222222
// Notices.
223223
$string['evalperiodsetnotice'] = 'Evaluationszeitraum gesetzt';
224-
$string['emailsentnotice'] = 'Evaluation beauftragt';
224+
$string['emailsentnotice'] = 'Evaluation beauftragt';
225+
226+
$string['apply'] = 'Anwenden';

lang/en/block_evasys_sync.php

+2
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,5 @@
232232
// Notices.
233233
$string['evalperiodsetnotice'] = 'Evaluationperiod has been set';
234234
$string['emailsentnotice'] = 'Evaluation has been requested';
235+
236+
$string['apply'] = 'Apply';

manageroverview.php

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
* Course overview 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+
require_once(__DIR__ . '/../../config.php');
26+
global $DB, $USER, $OUTPUT, $PAGE;
27+
28+
require_login();
29+
30+
if (has_capability('block/evasys_sync:managecourses', context_system::instance())) {
31+
// No filter if user has system-wide capability.
32+
$catids = null;
33+
} else {
34+
// Gets course categories the user can manage.
35+
list ($contextlimitsql, $contextlimitparams) = \core\access\get_user_capability_course_helper::get_sql(
36+
$USER->id, 'block/evasys_sync:managecourses');
37+
if (!$contextlimitsql) {
38+
// No capability in any context => No permission to use this page.
39+
throw new coding_exception('You do not have the permission to manage courses in any course category!');
40+
}
41+
42+
$directcatids = $DB->get_field_sql("
43+
SELECT c.id
44+
FROM {course_categories} c
45+
JOIN {context} x ON c.id = x.instanceid AND x.contextlevel = ?
46+
WHERE $contextlimitsql", array_merge([CONTEXT_COURSECAT], $contextlimitparams));
47+
48+
$catids = [];
49+
50+
foreach($directcatids as $directcatid) {
51+
$catids[] = $directcatid;
52+
$catids = array_merge($catids, core_course_category::get($directcatid)->get_all_children_ids());
53+
}
54+
}
55+
56+
$PAGE->set_url(new moodle_url('/blocks/evasys_sync/manageroverview.php'));
57+
$PAGE->set_context(context_system::instance());
58+
$PAGE->set_title(get_string('evasys_sync', 'block_evasys_sync'));
59+
60+
$cachekey = 'manageroverview';
61+
$cache = cache::make('block_evasys_sync', 'mformdata');
62+
$mform = new \block_evasys_sync\course_manager_filter_form();
63+
64+
if ($data = $mform->get_data()) {
65+
$cache->set($cachekey, $data);
66+
redirect($PAGE->url);
67+
} else if ($mform->is_cancelled()) {
68+
$cache->delete($cachekey);
69+
redirect($PAGE->url);
70+
}
71+
72+
$data = $cache->get($cachekey);
73+
74+
if ($data) {
75+
$mform->set_data($data);
76+
} else {
77+
$data = new stdClass();
78+
if ($field = $DB->get_record('customfield_field', array('shortname' => 'semester', 'type' => 'semester'))) {
79+
$fieldcontroller = \core_customfield\field_controller::create($field->id);
80+
$datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
81+
$data->semester = $datacontroller->get_default_value();
82+
}
83+
$data->coursename = '';
84+
}
85+
86+
$table = new \block_evasys_sync\course_manager_table($catids, $data->semester ?? null,
87+
$data->coursename ?? null);
88+
$table->define_baseurl($PAGE->url);
89+
90+
echo $OUTPUT->header();
91+
92+
$mform->display();
93+
94+
$table->out(48, false);
95+
96+
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)