1 |
efrain |
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 |
* List of groups table. List of groups the current user and selected users are assigned.
|
|
|
19 |
*
|
|
|
20 |
* @package block_dash
|
|
|
21 |
* @copyright 2022 bdecent gmbh <https://bdecent.de>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace block_dash\table;
|
|
|
26 |
|
|
|
27 |
use html_writer;
|
|
|
28 |
|
|
|
29 |
defined('MOODLE_INTERNAL') || die('No direct access');
|
|
|
30 |
|
|
|
31 |
require_once($CFG->dirroot.'/lib/tablelib.php');
|
|
|
32 |
/**
|
|
|
33 |
* List of groups table.
|
|
|
34 |
*/
|
|
|
35 |
class groups_totara extends \table_sql {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Define table field definitions and filter data
|
|
|
39 |
*
|
|
|
40 |
* @param int $pagesize
|
|
|
41 |
* @param bool $useinitialsbar
|
|
|
42 |
* @param string $downloadhelpbutton
|
|
|
43 |
* @return void
|
|
|
44 |
*/
|
|
|
45 |
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
|
|
|
46 |
|
|
|
47 |
$this->set_tabledata();
|
|
|
48 |
|
|
|
49 |
$columns = ['groupname', 'course'];
|
|
|
50 |
$headers = [
|
|
|
51 |
get_string('groupname', 'group'),
|
|
|
52 |
get_string('course'),
|
|
|
53 |
];
|
|
|
54 |
|
|
|
55 |
$this->define_columns($columns);
|
|
|
56 |
$this->define_headers($headers);
|
|
|
57 |
|
|
|
58 |
if (isset($this->filterset) && $this->filterset->has_filter('contactuser')) {
|
|
|
59 |
$values = $this->filterset->get_filter('contactuser')->get_filter_values();
|
|
|
60 |
$this->contactuser = isset($values[0]) ? current($values) : '';
|
|
|
61 |
}
|
|
|
62 |
$this->collapsible(false);
|
|
|
63 |
$this->guess_base_url();
|
|
|
64 |
parent::out($pagesize, $useinitialsbar, $downloadhelpbutton);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Set the html data attributes in the table tag for the dynamic paginations.
|
|
|
69 |
*
|
|
|
70 |
* @return void
|
|
|
71 |
*/
|
|
|
72 |
public function set_tabledata() {
|
|
|
73 |
$attrs = [
|
|
|
74 |
'handler' => 'groups_totara',
|
|
|
75 |
'component' => 'block_dash',
|
|
|
76 |
'uniqueid' => $this->uniqueid,
|
|
|
77 |
'context' => $this->get_context()->id,
|
|
|
78 |
'filter' => isset($this->contactuser) ? $this->contactuser : '',
|
|
|
79 |
];
|
|
|
80 |
|
|
|
81 |
foreach ($attrs as $key => $val) {
|
|
|
82 |
$this->set_attribute('data-table-'.$key, $val);
|
|
|
83 |
}
|
|
|
84 |
$this->set_attribute('data-table-dynamic', 'true');
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Setup the filter data for pagination.
|
|
|
89 |
*
|
|
|
90 |
* @param int $contactuser
|
|
|
91 |
* @return void
|
|
|
92 |
*/
|
|
|
93 |
public function set_filterset($contactuser) {
|
|
|
94 |
$this->contactuser = $contactuser;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Set default sort column.
|
|
|
99 |
*
|
|
|
100 |
* @param string $field
|
|
|
101 |
* @return void
|
|
|
102 |
*/
|
|
|
103 |
public function set_sort_column($field) {
|
|
|
104 |
$this->sort_default_column = $field;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Set the context of the current block.
|
|
|
109 |
*
|
|
|
110 |
* @return void
|
|
|
111 |
*/
|
|
|
112 |
public function get_context(): \context {
|
|
|
113 |
return \context_block::instance($this->uniqueid);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* Set the base url of the table, used in the ajax data update.
|
|
|
118 |
*
|
|
|
119 |
* @return void
|
|
|
120 |
*/
|
|
|
121 |
public function guess_base_url(): void {
|
|
|
122 |
global $PAGE;
|
|
|
123 |
$this->baseurl = $PAGE->url;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Set the sql query to fetch same user groups.
|
|
|
128 |
*
|
|
|
129 |
* @param int $pagesize
|
|
|
130 |
* @param boolean $useinitialsbar
|
|
|
131 |
* @return void
|
|
|
132 |
*/
|
|
|
133 |
public function query_db($pagesize, $useinitialsbar = true) {
|
|
|
134 |
global $USER;
|
|
|
135 |
|
|
|
136 |
if (isset($this->currentpage)) {
|
|
|
137 |
$this->currpage = $this->currentpage;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
$select = '*';
|
|
|
141 |
$from = ' {groups_members} gm JOIN {groups} g ON g.id = gm.groupid ';
|
|
|
142 |
$where = ' gm.userid = :userid AND gm.groupid IN (
|
|
|
143 |
SELECT groupid from {groups_members} WHERE userid = :contactuserid
|
|
|
144 |
)';
|
|
|
145 |
$this->set_sql($select, $from, $where, ['userid' => $USER->id, 'contactuserid' => $this->contactuser]);
|
|
|
146 |
|
|
|
147 |
parent::query_db($pagesize, $useinitialsbar);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* Returns group name in user readable.
|
|
|
152 |
*
|
|
|
153 |
* @param \stdclass $row
|
|
|
154 |
* @return void
|
|
|
155 |
*/
|
|
|
156 |
public function col_groupname($row) {
|
|
|
157 |
return format_string($row->name);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* Return course name from courseid.
|
|
|
162 |
*
|
|
|
163 |
* @param \stdclass $row
|
|
|
164 |
* @return void
|
|
|
165 |
*/
|
|
|
166 |
public function col_course($row) {
|
|
|
167 |
return format_string(get_course($row->courseid)->fullname);
|
|
|
168 |
}
|
|
|
169 |
}
|