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