Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Table class that cntains the list of memebrs in the selected group.
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
defined('MOODLE_INTERNAL') || die('No direct access');
28
 
29
use core_table\dynamic as dynamic_table;
30
use html_writer;
31
 
32
require_once($CFG->dirroot.'/lib/tablelib.php');
33
 
34
/**
35
 * List of group memebers table.
36
 */
37
class members extends \table_sql implements dynamic_table {
38
 
39
    /**
40
     * Group filter value.
41
     *
42
     * @var string
43
     */
44
    protected $group;
45
 
46
    /**
47
     * Define table field definitions and filter data
48
     *
49
     * @param int $pagesize
50
     * @param bool $useinitialsbar
51
     * @param string $downloadhelpbutton
52
     * @return void
53
     */
54
    public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
55
 
56
        $columns = ['fullname', 'roles'];
57
        $headers = [
58
            get_string('fullname'),
59
            get_string('roles'),
60
        ];
61
 
62
        $this->define_columns($columns);
63
        $this->define_headers($headers);
64
 
65
        if ($this->filterset->has_filter('group')) {
66
            $this->group = $this->filterset->get_filter('group')->get_filter_values();
67
            $this->group = current($this->group);
68
        }
69
 
70
        $this->collapsible(false);
71
        $this->no_sorting('roles');
72
        $this->guess_base_url();
73
        parent::out($pagesize, $useinitialsbar, $downloadhelpbutton);
74
    }
75
 
76
    /**
77
     * Set the context of the current block.
78
     *
79
     * @return void
80
     */
81
    public function get_context(): \context {
82
        return \context_block::instance($this->uniqueid);
83
    }
84
 
85
    /**
86
     * Set the base url of the table, used in the ajax data update.
87
     *
88
     * @return void
89
     */
90
    public function guess_base_url(): void {
91
        global $PAGE;
92
        $this->baseurl = $PAGE->url;
93
    }
94
 
95
    /**
96
     * Set the sql query to fetch same user groups.
97
     *
98
     * @param int $pagesize
99
     * @param boolean $useinitialsbar
100
     * @return void
101
     */
102
    public function query_db($pagesize, $useinitialsbar = true) {
103
        global $USER;
104
 
105
        $select = '*';
106
        $from = ' {groups_members} gm JOIN {groups} g ON g.id = gm.groupid
107
        JOIN {user} u ON u.id = gm.userid ';
108
        $where = ' gm.userid != :userid AND g.id = :groupid AND g.id IN (
109
            SELECT groupid FROM {groups_members} WHERE userid = :currentuser
110
        )';
111
        $this->set_sql($select, $from, $where, ['userid' => $USER->id, 'groupid' => $this->group, 'currentuser' => $USER->id]);
112
        parent::query_db($pagesize, false);
113
    }
114
 
115
    /**
116
     * Generate the fullname column.
117
     *
118
     * @param \stdClass $row
119
     * @return string
120
     */
121
    public function col_fullname($row) {
122
        global $OUTPUT;
123
 
124
        return $OUTPUT->user_picture($row, ['size' => 35, 'courseid' => $row->courseid, 'includefullname' => true]);
125
    }
126
 
127
    /**
128
     * User lastaccess to the group in the user readable format.
129
     *
130
     * @param stdclass $row
131
     * @return string
132
     */
133
    public function col_roles($row) {
134
        return get_user_roles_in_course($row->userid, $row->courseid);
135
    }
136
}