echo '</tr>'; print_category_edit(NULL, $displaylist, $parentlist); echo '</table>'; echo '<div class="buttons">'; if (has_capability('moodle/course:create', $systemcontext)) { // print create course link to first category $options = array('category' => $CFG->defaultrequestcategory); $options['returnto'] = 'topcat'; /* echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');*/ } // Print button for creating new categories if (has_capability('moodle/category:manage', $systemcontext)) { $options = array('parent' => 0); echo $OUTPUT->single_button(new moodle_url('editcategory.php', $options), 'Agregar nueva materia', 'get'); } print_course_request_buttons($systemcontext); echo '</div>'; echo $OUTPUT->footer(); function print_category_edit($category, $displaylist, $parentslist, $depth = -1, $up = false, $down = false) { /// Recursive function to print all the categories ready for editing global $CFG, $USER, $OUTPUT; static $str = NULL; if (is_null($str)) { $str = new stdClass(); $str->edit = get_string('edit'); $str->delete = get_string('delete'); $str->moveup = get_string('moveup'); $str->movedown = get_string('movedown'); $str->edit = 'Editar materia'; $str->hide = get_string('hide');
$PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false)); echo '<input type="hidden" name="id" value="' . $category->id . '" />'; echo '</td></tr>'; } echo '</table>'; echo '</div></form>'; echo '<br />'; } } echo '<div class="buttons">'; if (has_capability('moodle/category:manage', $context) and $numcourses > 1) { /// Print button to re-sort courses by name unset($options); $options['id'] = $category->id; $options['resort'] = 'name'; $options['sesskey'] = sesskey(); echo $OUTPUT->single_button(new moodle_url('category.php', $options), get_string('resortcoursesbyname'), 'get'); } if (has_capability('moodle/course:create', $context)) { /// Print button to create a new course unset($options); $options['category'] = $category->id; $options['returnto'] = 'category'; echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get'); } if (!empty($CFG->enablecourserequests) && $category->id == $CFG->defaultrequestcategory) { print_course_request_buttons(get_context_instance(CONTEXT_SYSTEM)); } echo '</div>'; print_course_search(); echo $OUTPUT->footer();
echo $OUTPUT->single_button($url, get_string('resortcoursesbyname'), 'get'); } if (has_capability('moodle/course:create', $context) && empty($searchcriteria)) { // Print button to create a new course. $url = new moodle_url('/course/edit.php'); if ($coursecat->id) { $url->params(array('category' => $coursecat->id, 'returnto' => 'catmanage')); } else { $url->params(array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcatmanage')); } echo $OUTPUT->single_button($url, get_string('addnewcourse'), 'get'); } if (!empty($CFG->enablecourserequests) && $id == $CFG->defaultrequestcategory) { print_course_request_buttons(context_system::instance()); } echo html_writer::end_tag('div'); echo $courserenderer->course_search_form(); echo $OUTPUT->footer(); /** * Recursive function to print all the categories ready for editing. * * @param html_table $table The table to add data to. * @param coursecat $category The category to render * @param int $depth The depth of the category. * @param bool $up True if this category can be moved up. * @param bool $down True if this category can be moved down.
/** * Renders HTML to display particular course category - list of it's subcategories and courses * * Invoked from /course/index.php * * @param int|stdClass|coursecat $category */ public function course_category($category) { global $CFG; require_once $CFG->libdir . '/coursecatlib.php'; $coursecat = coursecat::get(is_object($category) ? $category->id : $category); $site = get_site(); $output = ''; if (can_edit_in_category($coursecat->id)) { // Add 'Manage' button if user has permissions to edit this category. $managebutton = $this->single_button(new moodle_url('/course/management.php', array('categoryid' => $coursecat->id)), get_string('managecourses'), 'get'); $this->page->set_button($managebutton); } if (!$coursecat->id) { if (coursecat::count_all() == 1) { // There exists only one category in the system, do not display link to it $coursecat = coursecat::get_default(); $strfulllistofcourses = get_string('fulllistofcourses'); $this->page->set_title("{$site->shortname}: {$strfulllistofcourses}"); } else { $strcategories = get_string('categories'); $this->page->set_title("{$site->shortname}: {$strcategories}"); } } else { $this->page->set_title("{$site->shortname}: " . $coursecat->get_formatted_name()); // Print the category selector $output .= html_writer::start_tag('div', array('class' => 'categorypicker')); $select = new single_select(new moodle_url('/course/index.php'), 'categoryid', coursecat::make_categories_list(), $coursecat->id, null, 'switchcategory'); $select->set_label(get_string('categories') . ':'); $output .= $this->render($select); $output .= html_writer::end_tag('div'); // .categorypicker } // Print current category description $chelper = new coursecat_helper(); if ($description = $chelper->get_category_formatted_description($coursecat)) { $output .= $this->box($description, array('class' => 'generalbox info')); } // Prepare parameters for courses and categories lists in the tree $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO)->set_attributes(array('class' => 'category-browse category-browse-' . $coursecat->id)); $coursedisplayoptions = array(); $catdisplayoptions = array(); $browse = optional_param('browse', null, PARAM_ALPHA); $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); $baseurl = new moodle_url('/course/index.php'); if ($coursecat->id) { $baseurl->param('categoryid', $coursecat->id); } if ($perpage != $CFG->coursesperpage) { $baseurl->param('perpage', $perpage); } $coursedisplayoptions['limit'] = $perpage; $catdisplayoptions['limit'] = $perpage; if ($browse === 'courses' || !$coursecat->has_children()) { $coursedisplayoptions['offset'] = $page * $perpage; $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $catdisplayoptions['nodisplay'] = true; $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories'); } else { if ($browse === 'categories' || !$coursecat->has_courses()) { $coursedisplayoptions['nodisplay'] = true; $catdisplayoptions['offset'] = $page * $perpage; $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses'); } else { // we have a category that has both subcategories and courses, display pagination separately $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1)); $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1)); } } $chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions); // Add course search form. $output .= $this->course_search_form(); // Display course category tree. $output .= $this->coursecat_tree($chelper, $coursecat); // Add action buttons $output .= $this->container_start('buttons'); $context = get_category_or_system_context($coursecat->id); if (has_capability('moodle/course:create', $context)) { // Print link to create a new course, for the 1st available category. if ($coursecat->id) { $url = new moodle_url('/course/edit.php', array('category' => $coursecat->id, 'returnto' => 'category')); } else { $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat')); } $output .= $this->single_button($url, get_string('addnewcourse'), 'get'); } ob_start(); if (coursecat::count_all() == 1) { print_course_request_buttons(context_system::instance()); } else { print_course_request_buttons($context); } $output .= ob_get_contents(); ob_end_clean(); $output .= $this->container_end(); return $output; }
/** * Renders HTML to display particular course category - list of it's subcategories and courses * * Invoked from /course/index.php * * @param int|stdClass|coursecat $category */ public function course_category($category) { global $CFG, $USER; require_once $CFG->dirroot . '/lib/pagelib.php'; require_once $CFG->libdir . '/coursecatlib.php'; $coursecat = coursecat::get(is_object($category) ? $category->id : $category); $site = get_site(); $output = '<h2>Matières</h2>'; // Print current category description $chelper = new coursecat_helper(); if ($description = $chelper->get_category_formatted_description($coursecat)) { $output .= $this->box($description, array('class' => 'generalbox info')); } // Prepare parameters for courses and categories lists in the tree $chelper->set_show_courses(10)->set_attributes(array('class' => 'category-browse category-browse-' . $coursecat->id)); $coursedisplayoptions = array(); $catdisplayoptions = array(); $browse = optional_param('browse', null, PARAM_ALPHA); $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); $baseurl = new moodle_url('/local/template_course/index.php'); if ($coursecat->id) { //$baseurl->param('categoryid', $coursecat->id); } if ($perpage != $CFG->coursesperpage) { $baseurl->param('perpage', $perpage); } //PAGINACIO $coursedisplayoptions['limit'] = $perpage; $catdisplayoptions['limit'] = $perpage; if ($browse === 'courses' || !$coursecat->has_children()) { $coursedisplayoptions['offset'] = $page * $perpage; $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $catdisplayoptions['nodisplay'] = true; $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories'); } else { if ($browse === 'categories' || !$coursecat->has_courses()) { $coursedisplayoptions['nodisplay'] = true; $catdisplayoptions['offset'] = $page * $perpage; $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses'); } else { // we have a category that has both subcategories and courses, display pagination separately $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1)); $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1)); } } $chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions); // Display course category tree $output .= $this->coursecat_tree($chelper, $coursecat); // Add course search form (if we are inside category it was already added to the navbar) if (!$coursecat->id) { $output .= $this->course_search_form(); } // Add action buttons $output .= $this->container_start('buttons'); $context = get_category_or_system_context($coursecat->id); if (has_capability('moodle/course:create', $context)) { $url = new moodle_url('/local/template_course/edit.php', array('returnto' => 'category', 'edit' => 'on')); $output .= $this->single_button($url, 'Ajouter une nouvelle matière', 'get'); } ob_start(); if (coursecat::count_all() == 1) { print_course_request_buttons(context_system::instance()); } else { print_course_request_buttons($context); } $output .= ob_get_contents(); ob_end_clean(); $output .= $this->container_end(); return $output; }