1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace tool_courserating\output;
|
|
|
18 |
|
|
|
19 |
use tool_courserating\helper;
|
|
|
20 |
use tool_courserating\permission;
|
|
|
21 |
|
|
|
22 |
defined('MOODLE_INTERNAL') || die();
|
|
|
23 |
|
|
|
24 |
require_once($CFG->libdir.'/tablelib.php');
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Course ratings list for Moodle 3.11 (before report builder)
|
|
|
28 |
*
|
|
|
29 |
* TODO remove when the minimum supported version is Moodle 4.0.
|
|
|
30 |
*
|
|
|
31 |
* @package tool_courserating
|
|
|
32 |
* @copyright 2022 Marina Glancy
|
|
|
33 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class report311 extends \table_sql {
|
|
|
36 |
/** @var \context */
|
|
|
37 |
protected $context;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructor for the task_log table.
|
|
|
41 |
*
|
|
|
42 |
* @param \moodle_url $url
|
|
|
43 |
*/
|
|
|
44 |
public function __construct(\moodle_url $url) {
|
|
|
45 |
parent::__construct('courseratings');
|
|
|
46 |
$this->define_baseurl($url);
|
|
|
47 |
$courseid = $url->get_param('id');
|
|
|
48 |
|
|
|
49 |
$this->context = \context_course::instance($courseid);
|
|
|
50 |
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
|
|
|
51 |
$userfields = $userfieldsapi->get_sql('u', false, '', 'userid', false)->selects;
|
|
|
52 |
$extrauserfields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
|
|
|
53 |
$fields = $userfields . ',
|
|
|
54 |
tool_courserating_rating.timemodified AS timemodified,
|
|
|
55 |
tool_courserating_rating.rating AS rating,
|
|
|
56 |
tool_courserating_rating.review AS review,
|
|
|
57 |
(SELECT count(1) FROM {tool_courserating_flag} f WHERE f.ratingid = tool_courserating_rating.id) AS flags,
|
|
|
58 |
tool_courserating_rating.id AS id,
|
|
|
59 |
tool_courserating_rating.courseid AS courseid';
|
|
|
60 |
|
|
|
61 |
$columns = $headers = [];
|
|
|
62 |
$columns[] = 'fullname';
|
|
|
63 |
$headers[] = get_string('fullname');
|
|
|
64 |
foreach ($extrauserfields as $extrafield) {
|
|
|
65 |
$columns[] = $extrafield;
|
|
|
66 |
$headers[] = \core_user\fields::get_display_name($extrafield);
|
|
|
67 |
}
|
|
|
68 |
$columns = array_merge($columns, ['timemodified', 'rating', 'review', 'flags', 'actions']);
|
|
|
69 |
$headers = array_merge($headers, [
|
|
|
70 |
get_string('rating_timemodified', 'tool_courserating'),
|
|
|
71 |
get_string('rating_rating', 'tool_courserating'),
|
|
|
72 |
get_string('rating_review', 'tool_courserating'),
|
|
|
73 |
get_string('rating_nofflags', 'tool_courserating'),
|
|
|
74 |
get_string('rating_actions', 'tool_courserating'),
|
|
|
75 |
]);
|
|
|
76 |
|
|
|
77 |
$from = '{tool_courserating_rating} tool_courserating_rating
|
|
|
78 |
JOIN {user} u ON u.id = tool_courserating_rating.userid';
|
|
|
79 |
|
|
|
80 |
$where = 'tool_courserating_rating.courseid = :rbparam0';
|
|
|
81 |
$params = ['rbparam0' => $courseid];
|
|
|
82 |
|
|
|
83 |
$this->set_sql($fields, $from, $where, $params);
|
|
|
84 |
$this->define_columns($columns);
|
|
|
85 |
$this->define_headers($headers);
|
|
|
86 |
|
|
|
87 |
$this->no_sorting('actions');
|
|
|
88 |
$this->no_sorting('review');
|
|
|
89 |
|
|
|
90 |
$this->sortable(true, 'timemodified', SORT_DESC);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Magic formatter for the column actions
|
|
|
95 |
*
|
|
|
96 |
* @param \stdClass $row
|
|
|
97 |
* @return string
|
|
|
98 |
*/
|
|
|
99 |
public function col_actions($row) {
|
|
|
100 |
return helper::format_actions($row->id ?? 0, $row);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Magic formatter for the column timemodified
|
|
|
105 |
*
|
|
|
106 |
* @param \stdClass $row
|
|
|
107 |
* @return string
|
|
|
108 |
*/
|
|
|
109 |
public function col_timemodified($row) {
|
|
|
110 |
return helper::format_date($row->timemodified);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Magic formatter for the column review
|
|
|
115 |
*
|
|
|
116 |
* @param \stdClass $row
|
|
|
117 |
* @return string
|
|
|
118 |
*/
|
|
|
119 |
public function col_review($row) {
|
|
|
120 |
return helper::format_review($row->review, $row);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* Magic formatter for the column rating
|
|
|
125 |
*
|
|
|
126 |
* @param \stdClass $row
|
|
|
127 |
* @return string
|
|
|
128 |
*/
|
|
|
129 |
public function col_rating($row) {
|
|
|
130 |
return helper::format_rating_in_course_report($row->rating, $row);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
/**
|
|
|
134 |
* Magic formatter for the column flags
|
|
|
135 |
*
|
|
|
136 |
* @param \stdClass $row
|
|
|
137 |
* @return string
|
|
|
138 |
*/
|
|
|
139 |
public function col_flags($row) {
|
|
|
140 |
return helper::format_flags_in_course_report($row->flags, $row);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
/**
|
|
|
144 |
* Get the column fullname value.
|
|
|
145 |
*
|
|
|
146 |
* @param \stdClass $row
|
|
|
147 |
* @return string
|
|
|
148 |
*/
|
|
|
149 |
public function col_fullname($row) {
|
|
|
150 |
global $OUTPUT;
|
|
|
151 |
$row = fullclone($row);
|
|
|
152 |
$row->id = $row->userid;
|
|
|
153 |
if ($this->download) {
|
|
|
154 |
return parent::col_fullname($row);
|
|
|
155 |
}
|
|
|
156 |
return $OUTPUT->user_picture($row, ['courseid' => $this->context->instanceid, 'includefullname' => true]);
|
|
|
157 |
}
|
|
|
158 |
}
|