Loading the rest of this comparison.

Untitled diff

Created Diff never expires
1 removal
572 lines
1 addition
572 lines
ORIGINAL FILE
MODIFIED FILE
<?php
<?php


// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - http://moodle.org/
//
//
// Moodle is free software: you can redistribute it and/or modify
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.
//
//
// Moodle is distributed in the hope that it will be useful,
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
/**
* Renderer for use with the course section and all the goodness that falls
* Renderer for use with the course section and all the goodness that falls
* within it.
* within it.
*
*
* This renderer should contain methods useful to courses, and categories.
* This renderer should contain methods useful to courses, and categories.
*
*
* @package moodlecore
* @package moodlecore
* @copyright 2010 Sam Hemelryk
* @copyright 2010 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
*/


/**
/**
* The core course renderer
* The core course renderer
*
*
* Can be retrieved with the following:
* Can be retrieved with the following:
* $renderer = $PAGE->get_renderer('core','course');
* $renderer = $PAGE->get_renderer('core','course');
*/
*/
class core_course_renderer extends plugin_renderer_base {
class core_course_renderer extends plugin_renderer_base {
const COURSECAT_SHOW_COURSES_NONE = 0; /* do not show courses at all */
const COURSECAT_SHOW_COURSES_NONE = 0; /* do not show courses at all */
const COURSECAT_SHOW_COURSES_COUNT = 5; /* do not show courses but show number of courses next to category name */
const COURSECAT_SHOW_COURSES_COUNT = 5; /* do not show courses but show number of courses next to category name */
const COURSECAT_SHOW_COURSES_COLLAPSED = 10;
const COURSECAT_SHOW_COURSES_COLLAPSED = 10;
const COURSECAT_SHOW_COURSES_AUTO = 15; /* will choose between collapsed and expanded automatically */
const COURSECAT_SHOW_COURSES_AUTO = 15; /* will choose between collapsed and expanded automatically */
const COURSECAT_SHOW_COURSES_EXPANDED = 20;
const COURSECAT_SHOW_COURSES_EXPANDED = 20;
const COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT = 30;
const COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT = 30;


const COURSECAT_TYPE_CATEGORY = 0;
const COURSECAT_TYPE_CATEGORY = 0;
const COURSECAT_TYPE_COURSE = 1;
const COURSECAT_TYPE_COURSE = 1;


/**
/**
* A cache of strings
* A cache of strings
* @var stdClass
* @var stdClass
*/
*/
protected $strings;
protected $strings;


/**
/**
* Override the constructor so that we can initialise the string cache
* Override the constructor so that we can initialise the string cache
*
*
* @param moodle_page $page
* @param moodle_page $page
* @param string $target
* @param string $target
*/
*/
public function __construct(moodle_page $page, $target) {
public function __construct(moodle_page $page, $target) {
$this->strings = new stdClass;
$this->strings = new stdClass;
parent::__construct($page, $target);
parent::__construct($page, $target);
$this->add_modchoosertoggle();
$this->add_modchoosertoggle();
}
}


/**
/**
* Adds the item in course settings navigation to toggle modchooser
* Adds the item in course settings navigation to toggle modchooser
*
*
* Theme can overwrite as an empty function to exclude it (for example if theme does not
* Theme can overwrite as an empty function to exclude it (for example if theme does not
* use modchooser at all)
* use modchooser at all)
*/
*/
protected function add_modchoosertoggle() {
protected function add_modchoosertoggle() {
global $CFG;
global $CFG;


// Only needs to be done once per page.
// Only needs to be done once per page.
if (!$this->page->requires->should_create_one_time_item_now('core_course_modchoosertoggle')) {
if (!$this->page->requires->should_create_one_time_item_now('core_course_modchoosertoggle')) {
return;
return;
}
}


if ($this->page->state > moodle_page::STATE_PRINTING_HEADER ||
if ($this->page->state > moodle_page::STATE_PRINTING_HEADER ||
$this->page->course->id == SITEID ||
$this->page->course->id == SITEID ||
!$this->page->user_is_editing() ||
!$this->page->user_is_editing() ||
!($context = context_course::instance($this->page->course->id)) ||
!($context = context_course::instance($this->page->course->id)) ||
!has_capability('moodle/course:manageactivities', $context) ||
!has_capability('moodle/course:manageactivities', $context) ||
!course_ajax_enabled($this->page->course) ||
!course_ajax_enabled($this->page->course) ||
!($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) ||
!($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) ||
!($turneditingnode = $coursenode->get('turneditingonoff'))) {
!($turneditingnode = $coursenode->get('turneditingonoff'))) {
// Too late, or we are on site page, or we could not find the
// Too late, or we are on site page, or we could not find the
// adjacent nodes in course settings menu, or we are not allowed to edit.
// adjacent nodes in course settings menu, or we are not allowed to edit.
return;
return;
}
}


if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
// We are on the course page, retain the current page params e.g. section.
// We are on the course page, retain the current page params e.g. section.
$modchoosertoggleurl = clone($this->page->url);
$modchoosertoggleurl = clone($this->page->url);
} else {
} else {
// Edit on the main course page.
// Edit on the main course page.
$modchoosertoggleurl = new moodle_url('/course/view.php', array('id' => $this->page->course->id,
$modchoosertoggleurl = new moodle_url('/course/view.php', array('id' => $this->page->course->id,
'return' => $this->page->url->out_as_local_url(false)));
'return' => $this->page->url->out_as_local_url(false)));
}
}
$modchoosertoggleurl->param('sesskey', sesskey());
$modchoosertoggleurl->param('sesskey', sesskey());