|
| 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 | +} |
0 commit comments