function podcaster_get_types() { global $CFG; require_once $CFG->dirroot . '/mod/podcaster/lib/util.php'; $usegroups = false; $types = array(); if (isset($CFG->podcaster_submenus) && $CFG->podcaster_submenus != 'none') { // TODO: adapt for other criteria $subtypes = array(); if (strpos($CFG->podcaster_submenus, 'repository') !== false) { $repositories = get_records('podcaster_repository', 'enabled', '1'); foreach ($repositories as $id => $r) { $t = new object(); $t->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $t->type = 'podcaster&type=repository' . podcaster_util::number2az($r->id); $t->typestr = podcaster_util::get_string('repository_' . $r->name . '_title'); $subtypes[] = $t; unset($t); } } if (strpos($CFG->podcaster_submenus, 'format') !== false) { $formats = explode(',', $CFG->podcaster_formats); $merge = count($subtypes) > 0; $subtypes2 = array(); foreach ($formats as $format) { if (!$merge) { $t = new object(); $t->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $t->type = 'podcaster&type=format' . strtoupper($format); $t->typestr = podcaster_util::get_string('format_' . $format . '_title'); $subtypes2[] = $t; unset($t); } else { foreach ($subtypes as $subtype) { $t = new object(); $t->modclass = $subtype->modclass; $t->type = $subtype->type . 'format' . strtoupper($format); $t->typestr = $subtype->typestr . ', ' . podcaster_util::get_string('format_' . $format . '_title'); $subtypes2[] = $t; unset($t); } } } $subtypes = $subtypes2; } if (strpos($CFG->podcaster_submenus, 'license') !== false) { $licenses = get_records('podcaster_license'); $merge = count($subtypes) > 0; $subtypes2 = array(); foreach ($licenses as $id => $license) { if (!$merge) { $t = new object(); $t->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $t->type = 'podcaster&type=license' . podcaster_util::number2az($license->id); $t->typestr = podcaster_util::get_string('license_' . $license->name . '_title'); $subtypes2[] = $t; unset($t); } else { foreach ($subtypes as $subtype) { $t = new object(); $t->modclass = $subtype->modclass; $t->type = $subtype->type . 'license' . podcaster_util::number2az($license->id); $t->typestr = $subtype->typestr . ', ' . podcaster_util::get_string('license_' . $license->name . '_title'); $subtypes2[] = $t; unset($t); } } } $subtypes = $subtypes2; } if (count($subtypes) > 1) { $usegroups = true; $start = new object(); $start->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $start->type = 'podcaster_group_start'; $start->typestr = '--Podcasts'; $types[] = $start; foreach ($subtypes as $subtype) { $types[] = $subtype; } $end = new object(); $end->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $end->type = 'podcaster_group_end'; $end->typestr = '--'; $types[] = $end; } } if ($usegroups == false) { $type = new object(); $type->modclass = $CFG->podcaster_type == 'resource' ? MOD_CLASS_RESOURCE : MOD_CLASS_ACTIVITY; $type->type = 'podcaster'; $type->typestr = get_string('modulename', 'podcaster'); $types[] = $type; } return $types; }