本文整理汇总了PHP中coursecat::get_courses_count方法的典型用法代码示例。如果您正苦于以下问题:PHP coursecat::get_courses_count方法的具体用法?PHP coursecat::get_courses_count怎么用?PHP coursecat::get_courses_count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coursecat
的用法示例。
在下文中一共展示了coursecat::get_courses_count方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listing_pagination
/**
* Renders pagination for a course listing.
*
* @param coursecat $category The category to produce pagination for.
* @param int $page The current page.
* @param int $perpage The number of courses to display per page.
* @param bool $showtotals Set to true to show the total number of courses and what is being displayed.
* @return string
*/
protected function listing_pagination(coursecat $category, $page, $perpage, $showtotals = false)
{
$html = '';
$totalcourses = $category->get_courses_count();
$totalpages = ceil($totalcourses / $perpage);
if ($showtotals) {
if ($totalpages == 0) {
$str = get_string('nocoursesyet');
} else {
if ($totalpages == 1) {
$str = get_string('showingacourses', 'moodle', $totalcourses);
} else {
$a = new stdClass();
$a->start = $page * $perpage + 1;
$a->end = min(($page + 1) * $perpage, $totalcourses);
$a->total = $totalcourses;
$str = get_string('showingxofycourses', 'moodle', $a);
}
}
$html .= html_writer::div($str, 'listing-pagination-totals dimmed');
}
if ($totalcourses <= $perpage) {
return $html;
}
$aside = 2;
$span = $aside * 2 + 1;
$start = max($page - $aside, 0);
$end = min($page + $aside, $totalpages - 1);
if ($end - $start < $span) {
if ($start == 0) {
$end = min($totalpages - 1, $span - 1);
} else {
if ($end == $totalpages - 1) {
$start = max(0, $end - $span + 1);
}
}
}
$items = array();
$baseurl = new moodle_url('/course/management.php', array('categoryid' => $category->id));
if ($page > 0) {
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => 0)), get_string('first'));
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $page - 1)), get_string('prev'));
$items[] = '...';
}
for ($i = $start; $i <= $end; $i++) {
$class = '';
if ($page == $i) {
$class = 'active-page';
}
$pageurl = new moodle_url($baseurl, array('page' => $i));
$items[] = $this->action_button($pageurl, $i + 1, null, $class, get_string('pagea', 'moodle', $i + 1));
}
if ($page < $totalpages - 1) {
$items[] = '...';
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $page + 1)), get_string('next'));
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $totalpages - 1)), get_string('last'));
}
$html .= html_writer::div(join('', $items), 'listing-pagination');
return $html;
}
示例2: coursecat_category
/**
* Returns HTML to display a course category as a part of a tree
*
* This is an internal function, to display a particular category and all its contents
* use {@link core_course_renderer::course_category()}
*
* @param coursecat_helper $chelper various display options
* @param coursecat $coursecat
* @param int $depth depth of this category in the current tree
* @return string
*/
protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth)
{
global $CFG, $OUTPUT;
// open category tag
$classes = array('category');
if (empty($coursecat->visible)) {
$classes[] = 'dimmed_category';
}
if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
// do not load content
$categorycontent = '';
$classes[] = 'notloaded';
if ($coursecat->get_children_count() || $chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count()) {
$classes[] = 'with_children';
$classes[] = 'collapsed';
}
} else {
// load category content
$categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
$classes[] = 'loaded';
if (!empty($categorycontent)) {
$classes[] = 'with_children';
}
}
$classes[] = 'essentialcats';
if (intval($CFG->version) >= 2013111800) {
// Make sure JS file to expand category content is included.
$this->coursecat_include_js();
}
$content = html_writer::start_tag('div', array('class' => join(' ', $classes), 'data-categoryid' => $coursecat->id, 'data-depth' => $depth, 'data-showcourses' => $chelper->get_show_courses(), 'data-type' => self::COURSECAT_TYPE_CATEGORY));
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT) {
$coursescount = $coursecat->get_courses_count();
$content .= html_writer::tag('span', ' (' . $coursescount . ')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
}
// category name
$categoryname = html_writer::tag('span', $coursecat->get_formatted_name());
$categoryiconnum = 'categoryicon' . $coursecat->id;
// Do a settings check to output our icon for the category
if ($OUTPUT->get_setting('enablecategoryicon')) {
if ($OUTPUT->get_setting($categoryiconnum) && $OUTPUT->get_setting('enablecustomcategoryicon')) {
// User has set a value for the category
$val = $OUTPUT->get_setting($categoryiconnum);
} else {
// User hasn't set a value for the category, get the default
$val = $OUTPUT->get_setting('defaultcategoryicon');
}
}
if (!empty($val)) {
$icon = html_writer::tag('i', '', array('class' => 'fa fa-' . $val));
} else {
$icon = '';
}
$categoryname = html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id)), $icon . $categoryname);
$content .= html_writer::start_tag('div', array('class' => 'info'));
$content .= html_writer::tag($depth > 1 ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname'));
$content .= html_writer::end_tag('div');
// .info
// add category content to the output
$content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
$content .= html_writer::end_tag('div');
// .category
return $content;
}
示例3: coursecat_category
/**
* Returns HTML to display a course category as a part of a tree
*
* This is an internal function, to display a particular category and all its contents
* use {@link core_course_renderer::course_category()}
*
* @param coursecat_helper $chelper various display options
* @param coursecat $coursecat
* @param int $depth depth of this category in the current tree
* @return string
*/
protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth)
{
// open category tag
$classes = array('category');
if (empty($coursecat->visible)) {
$classes[] = 'dimmed_category';
}
if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
// do not load content
$categorycontent = '';
$classes[] = 'notloaded';
if ($coursecat->get_children_count() || $chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count()) {
$classes[] = 'with_children';
$classes[] = 'collapsed';
}
} else {
// load category content
$categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
$classes[] = 'loaded';
if (!empty($categorycontent)) {
$classes[] = 'with_children';
}
}
// Make sure JS file to expand category content is included.
$this->coursecat_include_js();
$content = html_writer::start_tag('div', array('class' => join(' ', $classes), 'data-categoryid' => $coursecat->id, 'data-depth' => $depth, 'data-showcourses' => $chelper->get_show_courses(), 'data-type' => self::COURSECAT_TYPE_CATEGORY));
// category name
$categoryname = $coursecat->get_formatted_name();
$categoryname = html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id)), $categoryname);
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT && ($coursescount = $coursecat->get_courses_count())) {
$categoryname .= html_writer::tag('span', ' (' . $coursescount . ')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
}
$content .= html_writer::start_tag('div', array('class' => 'info'));
$content .= html_writer::tag($depth > 1 ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname'));
$content .= html_writer::end_tag('div');
// .info
// add category content to the output
$content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
$content .= html_writer::end_tag('div');
// .category
// Return the course category tree HTML
return $content;
}
示例4: coursecat_category_content
/**
* Returns HTML to display the subcategories and courses in the given category
*
* This method is re-used by AJAX to expand content of not loaded category
*
* @param coursecat_helper $chelper various display options
* @param coursecat $coursecat
* @param int $depth depth of the category in the current tree
* @return string
*/
protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth)
{
$content = '';
// Subcategories
//$content .= $this->coursecat_subcategories($chelper, $coursecat, $depth);
// AUTO show courses: Courses will be shown expanded if this is not nested category,
// and number of courses no bigger than $CFG->courseswithsummarieslimit.
$showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO;
if ($showcoursesauto && $depth) {
// this is definitely collapsed mode
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
}
// Courses
if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) {
$courses = array();
if (!$chelper->get_courses_display_option('nodisplay')) {
$courses = $coursecat->get_courses($chelper->get_courses_display_options());
}
if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
// the option for 'View more' link was specified, display more link (if it is link to category view page, add category id)
if ($viewmoreurl->compare(new moodle_url('/local/template_course/index.php'), URL_MATCH_BASE)) {
$chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id)));
}
}
$content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count());
}
if ($showcoursesauto) {
// restore the show_courses back to AUTO
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO);
}
return $content;
}