if ($for === 'selectedcategories') { // Bulk resort selected categories. $categoryids = optional_param_array('bcat', false, PARAM_INT); $sort = required_param('resortcategoriesby', PARAM_ALPHA); if ($categoryids === false) { break; } $categories = coursecat::get_many($categoryids); } else { if ($for === 'allcategories') { if ($sortcategoriesby && coursecat::get(0)->can_resort_subcategories()) { \core_course\management\helper::action_category_resort_subcategories(coursecat::get(0), $sortcategoriesby); } $categorieslist = coursecat::make_categories_list('moodle/category:manage'); $categoryids = array_keys($categorieslist); $categories = coursecat::get_many($categoryids); unset($categorieslist); } else { break; } } } foreach ($categories as $cat) { if ($sortcategoriesby && $cat->can_resort_subcategories()) { // Don't clean up here, we'll do it once we're all done. \core_course\management\helper::action_category_resort_subcategories($cat, $sortcategoriesby, false); } if ($sortcoursesby && $cat->can_resort_courses()) { \core_course\management\helper::action_category_resort_courses($cat, $sortcoursesby, false); } }
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) { /* * We had to override this renderer to output the full category list for * a course : cat 1 / cat 2 / subcat / etc */ global $CFG; if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { return ''; } if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } $content = ''; // Display course overview files. $contentimages = $contentfiles = ''; foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage); if ($isimage) { $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox')); $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage')); $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images); $contentimages .= html_writer::end_tag('div'); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename')); $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon')); } } $content .= $contentimages . $contentfiles; // Display course summary. if ($course->has_summary()) { $content .= $chelper->get_course_formatted_summary($course); } // Display course contacts. See course_in_list::get_course_contacts(). if ($course->has_course_contacts()) { $content .= html_writer::start_tag('ul', array('class' => 'teachers')); foreach ($course->get_course_contacts() as $userid => $coursecontact) { $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']); $content .= html_writer::tag('li', $name); } $content .= html_writer::end_tag('ul'); // .teachers } // Display course category if necessary (for example in search results). if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) { require_once $CFG->libdir . '/coursecatlib.php'; if ($cat = coursecat::get($course->category, IGNORE_MISSING)) { $content .= html_writer::start_tag('div', array('class' => 'coursecat')); // $content .= get_string('category').': '. // html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), // $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed')); $parents = coursecat::get_many($cat->get_parents()); $linkydink = []; foreach ($parents as $parent) { $linkydink[] = $parent->get_formatted_name(); } $linkydink[] = $cat->get_formatted_name(); $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), implode(" / ", $linkydink), array('class' => $cat->visible ? '' : 'dimmed')); $content .= html_writer::end_tag('div'); // .coursecat } } return $content; }
/** * They've expanded the 'my courses' branch. */ protected function load_courses_enrolled() { global $CFG; $sortorder = 'visible DESC'; // Prevent undefined $CFG->navsortmycoursessort errors. if (empty($CFG->navsortmycoursessort)) { $CFG->navsortmycoursessort = 'sortorder'; } // Append the chosen sortorder. $sortorder = $sortorder . ',' . $CFG->navsortmycoursessort . ' ASC'; $courses = enrol_get_my_courses(null, $sortorder); if (count($courses) && $this->show_my_categories()) { // Generate an array containing unique values of all the courses' categories. $categoryids = array(); foreach ($courses as $course) { if (in_array($course->category, $categoryids)) { continue; } $categoryids[] = $course->category; } // Array of category IDs that include the categories of the user's courses and the related course categories. $fullpathcategoryids = []; // Get the course categories for the enrolled courses' category IDs. require_once 'coursecatlib.php'; $mycoursecategories = coursecat::get_many($categoryids); // Loop over each of these categories and build the category tree using each category's path. foreach ($mycoursecategories as $mycoursecat) { $pathcategoryids = explode('/', $mycoursecat->path); // First element of the exploded path is empty since paths begin with '/'. array_shift($pathcategoryids); // Merge the exploded category IDs into the full list of category IDs that we will fetch. $fullpathcategoryids = array_merge($fullpathcategoryids, $pathcategoryids); } // Fetch all of the categories related to the user's courses. $pathcategories = coursecat::get_many($fullpathcategoryids); // Loop over each of these categories and build the category tree. foreach ($pathcategories as $coursecat) { // No need to process categories that have already been added. if (isset($this->addedcategories[$coursecat->id])) { continue; } // Get this course category's parent node. $parent = null; if ($coursecat->parent && isset($this->addedcategories[$coursecat->parent])) { $parent = $this->addedcategories[$coursecat->parent]; } if (!$parent) { // If it has no parent, then it should be right under the My courses node. $parent = $this->rootnodes['mycourses']; } // Build the category object based from the coursecat object. $mycategory = new stdClass(); $mycategory->id = $coursecat->id; $mycategory->name = $coursecat->name; $mycategory->visible = $coursecat->visible; // Add this category to the nav tree. $this->add_category($mycategory, $parent, self::TYPE_MY_CATEGORY); } } foreach ($courses as $course) { $this->add_course($course, false, self::COURSE_MY); } }