本文整理汇总了PHP中coursecat::count_all方法的典型用法代码示例。如果您正苦于以下问题:PHP coursecat::count_all方法的具体用法?PHP coursecat::count_all怎么用?PHP coursecat::count_all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coursecat
的用法示例。
在下文中一共展示了coursecat::count_all方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tagged_courses
/**
* Renders html to print list of courses tagged with particular tag
*
* @param int $tagid id of the tag
* @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
* are displayed on the page and the per-page limit may be bigger
* @param int $fromctx context id where the link was displayed, may be used by callbacks
* to display items in the same context first
* @param int $ctx context id where to search for records
* @param bool $rec search in subcontexts as well
* @param array $displayoptions
* @return string empty string if no courses are marked with this tag or rendered list of courses
*/
public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null)
{
global $CFG;
require_once $CFG->libdir . '/coursecatlib.php';
if (empty($displayoptions)) {
$displayoptions = array();
}
$showcategories = coursecat::count_all() > 1;
$displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0);
$chelper = new coursecat_helper();
$searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec);
$chelper->set_show_courses($showcategories ? self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT : self::COURSECAT_SHOW_COURSES_EXPANDED)->set_search_criteria($searchcriteria)->set_courses_display_options($displayoptions)->set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
// (we set the same css class as in search results by tagid)
if ($totalcount = coursecat::search_courses_count($searchcriteria)) {
$courses = coursecat::search_courses($searchcriteria, $chelper->get_courses_display_options());
if ($exclusivemode) {
return $this->coursecat_courses($chelper, $courses, $totalcount);
} else {
$tagfeed = new core_tag\output\tagfeed();
$img = $this->output->pix_icon('i/course', '');
foreach ($courses as $course) {
$url = course_get_url($course);
$imgwithlink = html_writer::link($url, $img);
$coursename = html_writer::link($url, $course->get_formatted_name());
$details = '';
if ($showcategories && ($cat = coursecat::get($course->category, IGNORE_MISSING))) {
$details = 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'));
}
$tagfeed->add($imgwithlink, $coursename, $details);
}
return $this->output->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($this->output));
}
}
return '';
}
示例2: get_course_categories
/**
* Get the list of categories leading to this course.
*
* This function is used by {@link navbar::get_items()} to add back the "courses"
* node and category chain leading to the current course. Note that this is only ever
* called for the current course, so we don't need to bother taking in any parameters.
*
* @return array
*/
private function get_course_categories()
{
global $CFG;
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->libdir . '/coursecatlib.php';
$categories = array();
$cap = 'moodle/category:viewhiddencategories';
$showcategories = coursecat::count_all() > 1;
if ($showcategories) {
foreach ($this->page->categories as $category) {
if (!$category->visible && !has_capability($cap, get_category_or_system_context($category->parent))) {
continue;
}
$url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
$name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
$categorynode = breadcrumb_navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
if (!$category->visible) {
$categorynode->hidden = true;
}
$categories[] = $categorynode;
}
}
// Don't show the 'course' node if enrolled in this course.
if (!is_enrolled(context_course::instance($this->page->course->id, null, '', true))) {
$courses = $this->page->navigation->get('courses');
if (!$courses) {
// Courses node may not be present.
$courses = breadcrumb_navigation_node::create(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_CONTAINER);
}
$categories[] = $courses;
}
return $categories;
}
示例3: course_category
/**
* 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 = '';
$this->page->set_button($this->course_search_form('', 'navbar'));
if (!$coursecat->id) {
if (can_edit_in_category()) {
// add 'Manage' button instead of course search form
$managebutton = $this->single_button(new moodle_url('/course/management.php'), get_string('managecourses'), 'get');
$this->page->set_button($managebutton);
}
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);
// 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)) {
// 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();
//.........这里部分代码省略.........
示例4: test_count_all
/**
* Test the countall function
*/
public function test_count_all()
{
global $DB;
// Dont assume there is just one. An add-on might create a category as part of the install.
$numcategories = $DB->count_records('course_categories');
$this->assertEquals($numcategories, coursecat::count_all());
$category1 = coursecat::create(array('name' => 'Cat1'));
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category2->id, 'visible' => 0));
// Now we've got three more.
$this->assertEquals($numcategories + 3, coursecat::count_all());
cache_helper::purge_by_event('changesincoursecat');
// We should still have 4.
$this->assertEquals($numcategories + 3, coursecat::count_all());
}
示例5: optional_param
*/
require_once "../config.php";
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->libdir . '/coursecatlib.php';
$categoryid = optional_param('categoryid', 0, PARAM_INT);
// Category id
$site = get_site();
if ($categoryid) {
$PAGE->set_category_by_id($categoryid);
$PAGE->set_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
$PAGE->set_pagetype('course-index-category');
// And the object has been loaded for us no need for another DB call
$category = $PAGE->category;
} else {
// Check if there is only one category, if so use that.
if (coursecat::count_all() == 1) {
$category = coursecat::get_default();
$categoryid = $category->id;
$PAGE->set_category_by_id($categoryid);
$PAGE->set_pagetype('course-index-category');
} else {
$PAGE->set_context(context_system::instance());
}
$PAGE->set_url('/course/index.php');
}
$PAGE->set_pagelayout('coursecategory');
$courserenderer = $PAGE->get_renderer('core', 'course');
if ($CFG->forcelogin) {
require_login();
}
if ($categoryid && !$category->visible && !has_capability('moodle/category:viewhiddencategories', $PAGE->context)) {
示例6: course_category
/**
* 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;
}
示例7: test_count_all
/**
* Test the countall function
*/
public function test_count_all()
{
// There should be just the default category.
$this->assertEquals(1, coursecat::count_all());
$category1 = coursecat::create(array('name' => 'Cat1'));
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category2->id, 'visible' => 0));
// Now we've got four.
$this->assertEquals(4, coursecat::count_all());
cache_helper::purge_by_event('changesincoursecat');
// We should still have 4.
$this->assertEquals(4, coursecat::count_all());
}