Línea 26... |
Línea 26... |
26 |
|
26 |
|
Línea 27... |
Línea 27... |
27 |
defined('MOODLE_INTERNAL') || die();
|
27 |
defined('MOODLE_INTERNAL') || die();
|
28 |
|
28 |
|
- |
|
29 |
use core_course\local\exporters\course_content_items_exporter;
|
Línea 29... |
Línea 30... |
29 |
use core_course\local\exporters\course_content_items_exporter;
|
30 |
use core_course\local\repository\content_item_readonly_repository_interface;
|
30 |
use core_course\local\repository\content_item_readonly_repository_interface;
|
31 |
use core_courseformat\sectiondelegate;
|
31 |
|
32 |
|
32 |
/**
|
33 |
/**
|
Línea 232... |
Línea 233... |
232 |
* Return a representation of the available content items, for a user in a course.
|
233 |
* Return a representation of the available content items, for a user in a course.
|
233 |
*
|
234 |
*
|
234 |
* @param \stdClass $user the user to check access for.
|
235 |
* @param \stdClass $user the user to check access for.
|
235 |
* @param \stdClass $course the course to scope the content items to.
|
236 |
* @param \stdClass $course the course to scope the content items to.
|
236 |
* @param array $linkparams the desired section to return to.
|
237 |
* @param array $linkparams the desired section to return to.
|
- |
|
238 |
* @param \section_info|null $section_info the section we want to fetch the modules for.
|
237 |
* @return \stdClass[] the content items, scoped to a course.
|
239 |
* @return \stdClass[] the content items, scoped to a course.
|
238 |
*/
|
240 |
*/
|
239 |
public function get_content_items_for_user_in_course(\stdClass $user, \stdClass $course, array $linkparams = []): array {
|
241 |
public function get_content_items_for_user_in_course(\stdClass $user, \stdClass $course, array $linkparams = [], ?\section_info $sectioninfo = null): array {
|
240 |
global $PAGE;
|
242 |
global $PAGE;
|
Línea 241... |
Línea 243... |
241 |
|
243 |
|
242 |
if (!has_capability('moodle/course:manageactivities', \context_course::instance($course->id), $user)) {
|
244 |
if (!has_capability('moodle/course:manageactivities', \context_course::instance($course->id), $user)) {
|
243 |
return [];
|
245 |
return [];
|
Línea 273... |
Línea 275... |
273 |
$availablecontentitems = array_filter($allcontentitems, function($contentitem) use ($course, $user, $parents) {
|
275 |
$availablecontentitems = array_filter($allcontentitems, function($contentitem) use ($course, $user, $parents) {
|
274 |
// Check the parent module access for the user.
|
276 |
// Check the parent module access for the user.
|
275 |
return course_allowed_module($course, explode('_', $parents[$contentitem->get_component_name()])[1], $user);
|
277 |
return course_allowed_module($course, explode('_', $parents[$contentitem->get_component_name()])[1], $user);
|
276 |
});
|
278 |
});
|
Línea -... |
Línea 279... |
- |
|
279 |
|
- |
|
280 |
$format = course_get_format($course);
|
- |
|
281 |
$maxsectionsreached = ($format->get_last_section_number() >= $format->get_max_sections());
|
- |
|
282 |
|
- |
|
283 |
// Now, check there is no delegated section into a delegated section.
|
- |
|
284 |
if (is_null($sectioninfo) || $sectioninfo->is_delegated() || $maxsectionsreached) {
|
- |
|
285 |
$availablecontentitems = array_filter($availablecontentitems, function($contentitem){
|
- |
|
286 |
return !sectiondelegate::has_delegate_class($contentitem->get_component_name());
|
- |
|
287 |
});
|
- |
|
288 |
}
|
277 |
|
289 |
|
278 |
// Add the link params to the link, if any have been provided.
|
290 |
// Add the link params to the link, if any have been provided.
|
279 |
if (!empty($linkparams)) {
|
291 |
if (!empty($linkparams)) {
|
280 |
$availablecontentitems = array_map(function ($item) use ($linkparams) {
|
292 |
$availablecontentitems = array_map(function ($item) use ($linkparams) {
|
281 |
$item->get_link()->params($linkparams);
|
293 |
$item->get_link()->params($linkparams);
|