Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace core;
17
namespace core;
18
 
-
 
19
use context_course;
18
 
Línea 20... Línea 19...
20
use moodle_url;
19
use context_course;
21
use stdClass;
20
use stdClass;
22
 
21
 
Línea 69... Línea 68...
69
                    $activeurl = $check;
68
                    $activeurl = $check;
70
                }
69
                }
Línea 71... Línea 70...
71
 
70
 
72
            }
71
            }
73
            $selectmenu = new \core\output\select_menu('reporttype', $menuarray, $activeurl);
72
            $selectmenu = new \core\output\select_menu('reporttype', $menuarray, $activeurl);
74
            $selectmenu->set_label(get_string('reporttype'), ['class' => 'sr-only']);
73
            $selectmenu->set_label(get_string('reporttype'), ['class' => 'visually-hidden']);
75
            $options = \html_writer::tag(
74
            $options = \html_writer::tag(
76
                'div',
75
                'div',
77
                $OUTPUT->render_from_template('core/tertiary_navigation_selector', $selectmenu->export_for_template($OUTPUT)),
76
                $OUTPUT->render_from_template('core/tertiary_navigation_selector', $selectmenu->export_for_template($OUTPUT)),
78
                ['class' => 'navitem']
77
                ['class' => 'navitem']
Línea 84... Línea 83...
84
            }
83
            }
Línea 85... Línea 84...
85
 
84
 
86
            echo \html_writer::tag(
85
            echo \html_writer::tag(
87
                'div',
86
                'div',
88
                $options,
87
                $options,
89
                ['class' => 'tertiary-navigation full-width-bottom-border ml-0 d-flex', 'id' => 'tertiary-navigation']);
88
                ['class' => 'tertiary-navigation full-width-bottom-border ms-0 d-flex', 'id' => 'tertiary-navigation']);
90
        } else {
89
        } else {
91
            echo $OUTPUT->heading($pluginname, 2, 'mb-3');
90
            echo $OUTPUT->heading($pluginname, 2, 'mb-3');
92
        }
91
        }
Línea 93... Línea 92...
93
    }
92
    }
94
 
-
 
95
    /**
-
 
96
     * Save the last selected report in the session
93
 
97
     *
-
 
98
     * @deprecated since Moodle 4.0
-
 
99
     * @param int $id The course id
-
 
100
     * @param moodle_url $url The moodle url
94
    /**
101
     * @return void
-
 
102
     */
-
 
103
    public static function save_selected_report(int $id, moodle_url $url): void {
-
 
104
        global $USER;
95
     * @deprecated since Moodle 4.0
105
 
-
 
106
        debugging('save_selected_report() has been deprecated because it is no longer used and will be '.
-
 
107
            'removed in future versions of Moodle', DEBUG_DEVELOPER);
-
 
108
 
96
     */
109
        // Last selected report.
97
    #[\core\attribute\deprecated(null, reason: 'It is no longer used', since: '4.0', final: true)]
110
        if (!isset($USER->course_last_report)) {
-
 
111
            $USER->course_last_report = [];
-
 
112
        }
98
    public static function save_selected_report() {
Línea 113... Línea 99...
113
        $USER->course_last_report[$id] = $url;
99
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
114
    }
100
    }
115
 
101
 
Línea 131... Línea 117...
131
        $courseid = $filterparams->courseid ?? SITEID;
117
        $courseid = $filterparams->courseid ?? SITEID;
132
        $courseid = $courseid ?: SITEID; // Make sure that if courseid is set to 0 we use SITEID.
118
        $courseid = $courseid ?: SITEID; // Make sure that if courseid is set to 0 we use SITEID.
133
        $course = get_course($courseid);
119
        $course = get_course($courseid);
134
        $groupmode = groups_get_course_groupmode($course);
120
        $groupmode = groups_get_course_groupmode($course);
135
        $groupid = $filterparams->groupid ?? 0;
121
        $groupid = $filterparams->groupid ?? 0;
136
        if ($groupmode == SEPARATEGROUPS || $groupid) {
-
 
137
            $context = context_course::instance($courseid);
122
        $context = context_course::instance($courseid);
-
 
123
        if ($groupid || ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context))) {
138
            if ($groupid) {
124
            if ($groupid) {
139
                $cgroups = [(int) $groupid];
125
                $cgroups = [(int) $groupid];
140
            } else {
126
            } else {
141
                $cgroups = groups_get_all_groups(
127
                $cgroups = groups_get_all_groups($courseid, $USER->id);
142
                    $courseid,
-
 
143
                    has_capability('moodle/site:accessallgroups', $context) ? 0 : $USER->id
-
 
144
                );
-
 
145
                $cgroups = array_keys($cgroups);
128
                $cgroups = array_keys($cgroups);
146
                // If that's the case, limit the users to be in the groups only, defined by the filter.
129
                // If you are not in any groups you can still view users without group. This may
147
                if (has_capability('moodle/site:accessallgroups', $context) || empty($cgroups)) {
130
                // perform poorly because it will list all users in the entire system who do not
-
 
131
                // belong to a group on this course.
-
 
132
                if (empty($cgroups)) {
148
                    $cgroups[] = USERSWITHOUTGROUP;
133
                    $cgroups[] = USERSWITHOUTGROUP;
149
                }
134
                }
150
            }
135
            }
151
            // If that's the case, limit the users to be in the groups only, defined by the filter.
136
            // If that's the case, limit the users to be in the groups only, defined by the filter.
152
            [$groupmembersql, $groupmemberparams] = groups_get_members_ids_sql($cgroups, $context);
137
            [$groupmembersql, $groupmemberparams] = groups_get_members_ids_sql($cgroups, $context);
Línea 169... Línea 154...
169
                }
154
                }
170
            }
155
            }
171
        } else {
156
        } else {
172
            $joins[] = "userid = :userid";
157
            $joins[] = "userid = :userid";
173
            $params['userid'] = $filterparams->userid;
158
            $params['userid'] = $filterparams->userid;
-
 
159
            $useridfilter[$filterparams->userid] = true;
174
        }
160
        }
Línea 175... Línea 161...
175
 
161
 
176
        return [
162
        return [
177
            'joins' => $joins,
163
            'joins' => $joins,
178
            'params' => $params,
164
            'params' => $params,
179
            'useridfilter' => $useridfilter,
165
            'useridfilter' => $useridfilter,
180
        ];
166
        ];
-
 
167
    }
-
 
168
 
-
 
169
    /**
-
 
170
     * Check if the user is in a valid group for the course (i.e. if the user is in a group in SEPARATEGROUPS mode)
-
 
171
     *
-
 
172
     * @param context $context context for the course or module: if context is a course context, the course group mode is used,
-
 
173
     * if it is a module context, the module effective group mode is used (combined with the current user).
-
 
174
     * @param int|null $userid user id to check, if null the current user is used
-
 
175
     * @return bool true if the user is in a valid group (i.e. belongs to a group in SEPARATEGROUPS MODE), false otherwise
-
 
176
     */
-
 
177
    public static function has_valid_group(\context $context, ?int $userid = null): bool {
-
 
178
        global $USER;
-
 
179
 
-
 
180
        $userid = $userid ?? $USER->id;
-
 
181
 
-
 
182
        if ($context instanceof context_course) {
-
 
183
            $courseid = $context->instanceid;
-
 
184
            $course = get_course($courseid);
-
 
185
            $groupmode = $course->groupmode;
-
 
186
        } else if ($context instanceof \context_module) {
-
 
187
            $courseid = $context->get_course_context()->instanceid;
-
 
188
            $modinfo = get_fast_modinfo($courseid);
-
 
189
            $cm = $modinfo->get_cm($context->instanceid);
-
 
190
            $groupmode = $cm->effectivegroupmode;
-
 
191
        } else {
-
 
192
            return true; // No groups in system context.
-
 
193
        }
-
 
194
 
-
 
195
        if ($groupmode != SEPARATEGROUPS) {
-
 
196
            return true; // No groups or visible all groups.
-
 
197
        }
-
 
198
 
-
 
199
        if (!has_capability('moodle/site:accessallgroups', $context, $userid)) {
-
 
200
            $usergroups = groups_get_all_groups($courseid, $userid);
-
 
201
            if (empty($usergroups)) {
-
 
202
                return false;
-
 
203
            }
-
 
204
        }
-
 
205
 
-
 
206
        return true;
181
    }
207
    }