|
| 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\evasys_category; |
| 28 | +use moodle_url; |
| 29 | + |
| 30 | +defined('MOODLE_INTERNAL') || die; |
| 31 | + |
| 32 | +require_once($CFG->libdir . '/tablelib.php'); |
| 33 | + |
| 34 | +/** |
| 35 | + * Table listing all invalid courses (without idnumber). |
| 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 invalid_courses_table extends \table_sql { |
| 42 | + |
| 43 | + private evasys_category $evasyscategory; |
| 44 | + |
| 45 | + /** |
| 46 | + * Constructor for course_manager_table. |
| 47 | + */ |
| 48 | + public function __construct($categoryids, $semester, evasys_category $evasyscategory, $coursefullname = null) { |
| 49 | + parent::__construct('block_evasys_sync-course_manager_table'); |
| 50 | + global $DB, $PAGE, $OUTPUT; |
| 51 | + |
| 52 | + $this->evasyscategory = $evasyscategory; |
| 53 | + |
| 54 | + $fields = 'c.id as courseid, c.fullname as coursename, cfd.intvalue as semester'; |
| 55 | + |
| 56 | + $semesterfield = $DB->get_record('customfield_field', |
| 57 | + ['shortname' => 'semester', 'type' => 'semester'], '*', MUST_EXIST); |
| 58 | + |
| 59 | + $from = '{course} c ' . |
| 60 | + 'JOIN {customfield_data} cfd ON cfd.instanceid = c.id AND cfd.fieldid = :semesterfieldid ' . |
| 61 | + 'LEFT JOIN {' . dbtables::EVAL_COURSES . '} evalc ON evalc.courseid = c.id '; |
| 62 | + $params = ['semesterfieldid' => $semesterfield->id]; |
| 63 | + $where = ["c.idnumber = ''"]; |
| 64 | + |
| 65 | + if ($categoryids != null) { |
| 66 | + list($insql, $inparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED); |
| 67 | + $where[] = "c.category $insql"; |
| 68 | + $params = array_merge($params, $inparams); |
| 69 | + } |
| 70 | + |
| 71 | + if ($semester != null) { |
| 72 | + $where[] = 'cfd.intvalue = :semester'; |
| 73 | + $params['semester'] = $semester; |
| 74 | + } |
| 75 | + |
| 76 | + if ($coursefullname) { |
| 77 | + $where[] = 'c.fullname LIKE :cname'; |
| 78 | + $params['cname'] = '%' . $DB->sql_like_escape($coursefullname) . '%'; |
| 79 | + } |
| 80 | + $where = join(" AND ", $where); |
| 81 | + |
| 82 | + $this->set_sql($fields, $from, $where, $params); |
| 83 | + $this->column_nosort = ['select', 'teacher', 'tools']; |
| 84 | + $this->define_columns(['select', 'courseid', 'teacher', 'tools']); |
| 85 | + $this->define_headers([ |
| 86 | + $OUTPUT->render(new \core\output\checkbox_toggleall('evasys-remaining', true, [ |
| 87 | + 'id' => 'select-all-evasys-remaining', |
| 88 | + 'name' => 'select-all-evasys-remaining', |
| 89 | + 'label' => get_string('selectall'), |
| 90 | + 'labelclasses' => 'sr-only', |
| 91 | + 'classes' => 'm-1', |
| 92 | + 'checked' => false, |
| 93 | + ])), |
| 94 | + get_string('course'), |
| 95 | + get_string('teachers'), |
| 96 | + '' |
| 97 | + ]); |
| 98 | + |
| 99 | + $PAGE->requires->js_call_amd('block_evasys_sync/tablebulkactions', 'init'); |
| 100 | + } |
| 101 | + |
| 102 | + public function col_select($row) { |
| 103 | + global $OUTPUT; |
| 104 | + $checkbox = new \core\output\checkbox_toggleall('evasys-remaining', false, [ |
| 105 | + 'classes' => 'usercheckbox m-1', |
| 106 | + 'id' => 'evasys-remaining' . $row->courseid, |
| 107 | + 'name' => 'bulkcheckbox-select', |
| 108 | + 'value' => $row->courseid, |
| 109 | + 'checked' => false, |
| 110 | + 'label' => get_string('selectitem', 'moodle', $row->courseid), |
| 111 | + 'labelclasses' => 'accesshide', |
| 112 | + ]); |
| 113 | + return $OUTPUT->render($checkbox); |
| 114 | + } |
| 115 | + |
| 116 | + public function col_courseid($row) { |
| 117 | + return \html_writer::link(course_get_url($row->courseid), $row->coursename); |
| 118 | + } |
| 119 | + |
| 120 | + public function col_teacher($row) { |
| 121 | + $users = get_users_by_capability(\context_course::instance($row->courseid), 'block/evasys_sync:teacherforcourse'); |
| 122 | + $users = array_map(function($user) { |
| 123 | + return \html_writer::link(new moodle_url('/user/profile.php', ['id' => $user->id]), fullname($user)); |
| 124 | + }, $users); |
| 125 | + return join(', ', $users); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Render tools column. |
| 130 | + * |
| 131 | + * @param object $row Row data. |
| 132 | + * @return string |
| 133 | + */ |
| 134 | + public function col_tools($row) { |
| 135 | + global $PAGE, $OUTPUT; |
| 136 | + return ''; |
| 137 | + } |
| 138 | + |
| 139 | + public function wrap_html_finish() { |
| 140 | + global $OUTPUT; |
| 141 | + parent::wrap_html_finish(); |
| 142 | + } |
| 143 | +} |
0 commit comments