/** * Renderers actions for the course listing. * * Not to be confused with course_listitem_actions which renderers the actions for individual courses. * * @param coursecat $category * @param course_in_list $course The currently selected course. * @param int $perpage * @return string */ public function course_listing_actions(coursecat $category, course_in_list $course = null, $perpage = 20) { $actions = array(); if ($category->can_create_course()) { $url = new moodle_url('/course/edit.php', array('category' => $category->id, 'returnto' => 'catmanage')); $actions[] = html_writer::link($url, get_string('createnewcourse')); } if ($category->can_request_course()) { // Request a new course. $url = new moodle_url('/course/request.php', array('return' => 'management')); $actions[] = html_writer::link($url, get_string('requestcourse')); } if ($category->can_resort_courses()) { $params = $this->page->url->params(); $params['action'] = 'resortcourses'; $params['sesskey'] = sesskey(); $baseurl = new moodle_url('/course/management.php', $params); $fullnameurl = new moodle_url($baseurl, array('resort' => 'fullname')); $shortnameurl = new moodle_url($baseurl, array('resort' => 'shortname')); $idnumberurl = new moodle_url($baseurl, array('resort' => 'idnumber')); $menu = new action_menu(array(new action_menu_link_secondary($fullnameurl, null, get_string('resortbyfullname')), new action_menu_link_secondary($shortnameurl, null, get_string('resortbyshortname')), new action_menu_link_secondary($idnumberurl, null, get_string('resortbyidnumber')))); $menu->set_menu_trigger(get_string('resortcourses')); $actions[] = $this->render($menu); } $strall = get_string('all'); $menu = new action_menu(array(new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 5)), null, 5), new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 10)), null, 10), new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 20)), null, 20), new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 50)), null, 50), new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 100)), null, 100), new action_menu_link_secondary(new moodle_url($this->page->url, array('perpage' => 999)), null, $strall))); if ((int) $perpage === 999) { $perpage = $strall; } $menu->attributes['class'] .= ' courses-per-page'; $menu->set_menu_trigger(get_string('perpagea', 'moodle', $perpage)); $actions[] = $this->render($menu); return html_writer::div(join(' | ', $actions), 'listing-actions course-listing-actions'); }
/** * Resorts the courses within the given category. * * @param \coursecat $category * @param string $sort One of fullname, shortname or idnumber * @param bool $cleanup If true cleanup will be done, if false you will need to do it manually later. * @return bool * @throws \moodle_exception */ public static function action_category_resort_courses(\coursecat $category, $sort, $cleanup = true) { if (!$category->can_resort_courses()) { throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort'); } return $category->resort_courses($sort, $cleanup); }