moodle/course/renderer.php
Petr Skoda df997f841f MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
    MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
    MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
    MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
    MOV [enrolenddate,core],[enrolenddate,enrol_self]
    CPY [welcometocourse,core],[welcometocourse,enrol_self]
    CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
    MOV [notenrollable,core],[notenrollable,core_enrol]
    MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
    MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
    MOV [coursemanager,core_admin],[coursecontact,core_admin]
    MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
    MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
    MOV [enrolme,core],[enrolme,core_enrol]
    MOV [unenrol,core],[unenrol,core_enrol]
    MOV [unenrolme,core],[unenrolme,core_enrol]
    MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
    MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
    MOV [enrolments,core],[enrolments,core_enrol]
    MOV [enrolperiod,core],[enrolperiod,core_enrol]
    MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00

149 lines
6.2 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Renderer for use with the course section and all the goodness that falls
* within it.
*
* This renderer should contain methods useful to courses, and categories.
*
* @package moodlecore
* @copyright 2010 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* The core course renderer
*
* Can be retrieved with the following:
* $renderer = $PAGE->get_renderer('core','course');
*/
class core_course_renderer extends plugin_renderer_base {
/**
* A cache of strings
* @var stdClass
*/
protected $strings;
/**
* Override the constructor so that we can initialise the string cache
*
* @param moodle_page $page
* @param string $target
*/
public function __construct(moodle_page $page, $target) {
$this->strings = new stdClass;
parent::__construct($page, $target);
}
/**
* Renderers a structured array of courses and categories into a nice
* XHTML tree structure.
*
* This method was designed initially to display the front page course/category
* combo view. The structure can be retrieved by get_course_category_tree()
*
* @param array $structure
* @return string
*/
public function course_category_tree(array $structure) {
$this->strings->allowguests = get_string('allowguests');
$this->strings->requireskey = get_string('requireskey');
$this->strings->summary = get_string('summary');
// Generate an id and the required JS call to make this a nice widget
$id = html_writer::random_id('course_category_tree');
$this->page->requires->js_init_call('M.util.init_toggle_class_on_click', array($id, '.category.with_children', 'collapsed'));
// Start content generation
$content = html_writer::start_tag('div', array('class'=>'course_category_tree', 'id'=>$id));
foreach ($structure as $category) {
$content .= $this->course_category_tree_category($category);
}
$content .= html_writer::start_tag('div', array('class'=>'controls'));
$content .= html_writer::tag('div', get_string('collapseall'), array('class'=>'addtoall expandall'));
$content .= html_writer::tag('div', get_string('expandall'), array('class'=>'removefromall collapseall'));
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
// Return the course category tree HTML
return $content;
}
/**
* Renderers a category for use with course_category_tree
*
* @param array $category
* @param int $depth
* @return string
*/
protected function course_category_tree_category(stdClass $category, $depth=1) {
$content = '';
$hassubcategories = (count($category->categories)>0);
$hascourses = (count($category->courses)>0);
$classes = array('category');
if ($category->parent != 0) {
$classes[] = 'subcategory';
}
if ($hassubcategories || $hascourses) {
$classes[] = 'with_children';
if ($depth > 1) {
$classes[] = 'collapsed';
}
}
$content .= html_writer::start_tag('div', array('class'=>join(' ', $classes)));
$content .= html_writer::start_tag('div', array('class'=>'category_label'));
$content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $category->name, array('class'=>'category_link'));
$content .= html_writer::end_tag('div');
if ($hassubcategories) {
$content .= html_writer::start_tag('div', array('class'=>'subcategories'));
foreach ($category->categories as $subcategory) {
$content .= $this->course_category_tree_category($subcategory, $depth+1);
}
$content .= html_writer::end_tag('div');
}
if ($hascourses) {
$content .= html_writer::start_tag('div', array('class'=>'courses'));
$coursecount = 0;
foreach ($category->courses as $course) {
$classes = array('course');
$coursecount ++;
$classes[] = ($coursecount%2)?'odd':'even';
$content .= html_writer::start_tag('div', array('class'=>join(' ', $classes)));
$content .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), $course->fullname, array('class'=>'course_link'));
$content .= html_writer::start_tag('div', array('class'=>'course_info clearfix'));
//TODO: add enrol info
$content .= html_writer::tag('div', '', array('class'=>'course_info_spacer'));
$content .= html_writer::tag('div', '', array('class'=>'course_info_spacer'));
if ($course->summary) {
$image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url('i/info'), 'alt'=>$this->strings->summary));
$content .= html_writer::link(new moodle_url('/course/info.php', array('id'=>$course->id)), $image, array('title'=>$this->strings->summary));
} else {
$content .= html_writer::tag('div', '', array('class'=>'course_info_spacer'));
}
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
}
$content .= html_writer::end_tag('div');
}
$content .= html_writer::end_tag('div');
return $content;
}
}