-1 Removal
+213 Additions

Created by:frankiekam

ORIGINAL FILEMODIFIED 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());
if ($usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault)) { if ($usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault)) {
$modchoosertogglestring = get_string('modchooserdisable', 'moodle'); $modchoosertogglestring = get_string('modchooserdisable', 'moodle');
$modchoosertoggleurl->param('modchooser', 'off'); $modchoosertoggleurl->param('modchooser', 'off');
} else { } else {
$modchoosertogglestring = get_string('modchooserenable', 'moodle'); $modchoosertogglestring = get_string('modchooserenable', 'moodle');
$modchoosertoggleurl->param('modchooser', 'on'); $modchoosertoggleurl->param('modchooser', 'on');
} }
$modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING, null, 'modchoosertoggle'); $modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING, null, 'modchoosertoggle');
// Insert the modchoosertoggle after the settings node 'turneditingonoff' (navigation_node only has function to insert before, so we insert before and then swap). // Insert the modchoosertoggle after the settings node 'turneditingonoff' (navigation_node only has function to insert before, so we insert before and then swap).
$coursenode->add_node($modchoosertoggle, 'turneditingonoff'); $coursenode->add_node($modchoosertoggle, 'turneditingonoff');
$turneditingnode->remove(); $turneditingnode->remove();
$coursenode->add_node($turneditingnode, 'modchoosertoggle'); $coursenode->add_node($turneditingnode, 'modchoosertoggle');
$modchoosertoggle->add_class('modchoosertoggle'); $modchoosertoggle->add_class('modchoosertoggle');
$modchoosertoggle->add_class('visibleifjs'); $modchoosertoggle->add_class('visibleifjs');
user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL); user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL);
} }
/** /**
* Renders course info box. * Renders course info box.
* *
* @param stdClass|course_in_list $course * @param stdClass|course_in_list $course
* @return string * @return string
*/ */
public function course_info_box(stdClass $course) { public function course_info_box(stdClass $course) {
$content = ''; $content = '';
$content .= $this->output->box_start('generalbox info'); $content .= $this->output->box_start('generalbox info');
$chelper = new coursecat_helper(); $chelper = new coursecat_helper();
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
$content .= $this->coursecat_coursebox($chelper, $course); $content .= $this->coursecat_coursebox($chelper, $course);
$content .= $this->output->box_end(); $content .= $this->output->box_end();
return $content; return $content;
} }
/** /**
* Renderers a structured array of courses and categories into a nice XHTML tree structure. * Renderers a structured array of courses and categories into a nice XHTML tree structure.
* *
* @deprecated since 2.5 * @deprecated since 2.5
* *
* Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
* *
* @param array $ignored argument ignored * @param array $ignored argument ignored
* @return string * @return string
*/ */
public final function course_category_tree(array $ignored) { public final function course_category_tree(array $ignored) {
debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER); debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER);
return $this->frontpage_combo_list(); return $this->frontpage_combo_list();
} }
/** /**
* Renderers a category for use with course_category_tree * Renderers a category for use with course_category_tree
* *
* @deprecated since 2.5 * @deprecated since 2.5
* *
* Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
* *
* @param array $category * @param array $category
* @param int $depth * @param int $depth
* @return string * @return string
*/ */
protected final function course_category_tree_category(stdClass $category, $depth=1) { protected final function course_category_tree_category(stdClass $category, $depth=1) {
debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER); debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER);
return ''; return '';
} }
/** /**
* Build the HTML for the module chooser javascript popup * Build the HTML for the module chooser javascript popup
* *
* @param array $modules A set of modules as returned form @see * @param array $modules A set of modules as returned form @see
* get_module_metadata * get_module_metadata
* @param object $course The course that will be displayed * @param object $course The course that will be displayed
* @return string The composed HTML for the module * @return string The composed HTML for the module
*/ */
public function course_modchooser($modules, $course) { public function course_modchooser($modules, $course) {
if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) { if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) {
return ''; return '';
} }
// Add the module chooser // Add the module chooser
$this->page->requires->yui_module('moodle-course-modchooser', $this->page->requires->yui_module('moodle-course-modchooser',
'M.course.init_chooser', 'M.course.init_chooser',
array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor'))) array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
); );
$this->page->requires->strings_for_js(array( $this->page->requires->strings_for_js(array(
'addresourceoractivity', 'addresourceoractivity',
'modchooserenable', 'modchooserenable',
'modchooserdisable', 'modchooserdisable',
), 'moodle'); ), 'moodle');
// Add the header // Add the header
$header = html_writer::tag('div', get_string('addresourceoractivity', 'moodle'), $header = html_writer::tag('div', get_string('addresourceoractivity', 'moodle'),
array('class' => 'hd choosertitle')); array('class' => 'hd choosertitle'));
$formcontent = html_writer::start_tag('form', array('action' => new moodle_url('/course/jumpto.php'), $formcontent = html_writer::start_tag('form', array('action' => new moodle_url('/course/jumpto.php'),
'id' => 'chooserform', 'method' => 'post')); 'id' => 'chooserform', 'method' => 'post'));
$formcontent .= html_writer::start_tag('div', array('id' => 'typeformdiv')); $formcontent .= html_writer::start_tag('div', array('id' => 'typeformdiv'));
$formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'id' => 'course', $formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'id' => 'course',
'name' => 'course', 'value' => $course->id)); 'name' => 'course', 'value' => $course->id));
$formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', $formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey',
'value' => sesskey())); 'value' => sesskey()));
$formcontent .= html_writer::end_tag('div'); $formcontent .= html_writer::end_tag('div');
// Put everything into one tag 'options' // Put everything into one tag 'options'
$formcontent .= html_writer::start_tag('div', array('class' => 'options')); $formcontent .= html_writer::start_tag('div', array('class' => 'options'));
$formcontent .= html_writer::tag('div', get_string('selectmoduletoviewhelp', 'moodle'), $formcontent .= html_writer::tag('div', get_string('selectmoduletoviewhelp', 'moodle'),
array('class' => 'instruction')); array('class' => 'instruction'));
// Put all options into one tag 'alloptions' to allow us to handle scrolling // Put all options into one tag 'alloptions' to allow us to handle scrolling
$formcontent .= html_writer::start_tag('div', array('class' => 'alloptions')); $formcontent .= html_writer::start_tag('div', array('class' => 'alloptions'));
// Activities // Activities
$activities = array_filter($modules, create_function('$mod', 'return ($mod->archetype !== MOD_ARCHETYPE_RESOURCE && $mod->archetype !== MOD_ARCHETYPE_SYSTEM);')); $activities = array_filter($modules, create_function('$mod', 'return ($mod->archetype !== MOD_ARCHETYPE_RESOURCE && $mod->archetype !== MOD_ARCHETYPE_SYSTEM);'));
if (count($activities)) { if (count($activities)) {
$formcontent .= $this->course_modchooser_title('activities'); $formcontent .= $this->course_modchooser_title('activities');
$formcontent .= $this->course_modchooser_module_types($activities); $formcontent .= $this->course_modchooser_module_types($activities);
} }
// Resources // Resources
$resources = array_filter($modules, create_function('$mod', 'return ($mod->archetype === MOD_ARCHETYPE_RESOURCE);')); $resources = array_filter($modules, create_function('$mod', 'return ($mod->archetype === MOD_ARCHETYPE_RESOURCE);'));
if (count($resources)) { if (count($resources)) {
$formcontent .= $this->course_modchooser_title('resources'); $formcontent .= $this->course_modchooser_title('resources');
$formcontent .= $this->course_modchooser_module_types($resources); $formcontent .= $this->course_modchooser_module_types($resources);
} }
$formcontent .= html_writer::end_tag('div'); // modoptions $formcontent .= html_writer::end_tag('div'); // modoptions
$formcontent .= html_writer::end_tag('div'); // types $formcontent .= html_writer::end_tag('div'); // types
$formcontent .= html_writer::start_tag('div', array('class' => 'submitbuttons')); $formcontent .= html_writer::start_tag('div', array('class' => 'submitbuttons'));
$formcontent .= html_writer::tag('input', '', $formcontent .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'submitbutton', 'class' => 'submitbutton', 'value' => get_string('add'))); array('type' => 'submit', 'name' => 'submitbutton', 'class' => 'submitbutton', 'value' => get_string('add')));
$formcontent .= html_writer::tag('input', '', $formcontent .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'addcancel', 'class' => 'addcancel', 'value' => get_string('cancel'))); array('type' => 'submit', 'name' => 'addcancel', 'class' => 'addcancel', 'value' => get_string('cancel')));
$formcontent .= html_writer::end_tag('div'); $formcontent .= html_writer::end_tag('div');
$formcontent .= html_writer::end_tag('form'); $formcontent .= html_writer::end_tag('form');
// Wrap the whole form in a div // Wrap the whole form in a div
$formcontent = html_writer::tag('div', $formcontent, array('id' => 'chooseform')); $formcontent = html_writer::tag('div', $formcontent, array('id' => 'chooseform'));
// Put all of the content together // Put all of the content together
$content = $formcontent; $content = $formcontent;
$content = html_writer::tag('div', $content, array('class' => 'choosercontainer')); $content = html_writer::tag('div', $content, array('class' => 'choosercontainer'));
return $header . html_writer::tag('div', $content, array('class' => 'chooserdialoguebody')); return $header . html_writer::tag('div', $content, array('class' => 'chooserdialoguebody'));
} }
/** /**
* Build the HTML for a specified set of modules * Build the HTML for a specified set of modules
* *
* @param array $modules A set of modules as used by the * @param array $modules A set of modules as used by the
* course_modchooser_module function * course_modchooser_module function
* @return string The composed HTML for the module * @return string The composed HTML for the module
*/ */
protected function course_modchooser_module_types($modules) { protected function course_modchooser_module_types($modules) {
$return = ''; $return = '';
foreach ($modules as $module) { foreach ($modules as $module) {
if (!isset($module->types)) { if (!isset($module->types)) {
$return .= $this->course_modchooser_module($module); $return .= $this->course_modchooser_module($module);
} else { } else {
$return .= $this->course_modchooser_module($module, array('nonoption')); $return .= $this->course_modchooser_module($module, array('nonoption'));
foreach ($module->types as $type) { foreach ($module->types as $type) {
$return .= $this->course_modchooser_module($type, array('option', 'subtype')); $return .= $this->course_modchooser_module($type, array('option', 'subtype'));
} }
} }
} }
return $return; return $return;
} }
/** /**
* Return the HTML for the specified module adding any required classes * Return the HTML for the specified module adding any required classes
* *
* @param object $module An object containing the title, and link. An * @param object $module An object containing the title, and link. An
* icon, and help text may optionally be specified. If the module * icon, and help text may optionally be specified. If the module
* contains subtypes in the types option, then these will also be * contains subtypes in the types option, then these will also be
* displayed. * displayed.
* @param array $classes Additional classes to add to the encompassing * @param array $classes Additional classes to add to the encompassing
* div element * div element
* @return string The composed HTML for the module * @return string The composed HTML for the module
*/ */
protected function course_modchooser_module($module, $classes = array('option')) { protected function course_modchooser_module($module, $classes = array('option')) {
$output = ''; $output = '';
$output .= html_writer::start_tag('div', array('class' => implode(' ', $classes))); $output .= html_writer::start_tag('div', array('class' => implode(' ', $classes)));
$output .= html_writer::start_tag('label', array('for' => 'module_' . $module->name)); $output .= html_writer::start_tag('label', array('for' => 'module_' . $module->name));
if (!isset($module->types)) { if (!isset($module->types)) {
$output .= html_writer::tag('input', '', array('type' => 'radio', $output .= html_writer::tag('input', '', array('type' => 'radio',
'name' => 'jumplink', 'id' => 'module_' . $module->name, 'value' => $module->link)); 'name' => 'jumplink', 'id' => 'module_' . $module->name, 'value' => $module->link));
} }
$output .= html_writer::start_tag('span', array('class' => 'modicon')); $output .= html_writer::start_tag('span', array('class' => 'modicon'));
if (isset($module->icon)) { if (isset($module->icon)) {
// Add an icon if we have one // Add an icon if we have one
$output .= $module->icon; $output .= $module->icon;
} }
$output .= html_writer::end_tag('span'); $output .= html_writer::end_tag('span');
$output .= html_writer::tag('span', $module->title, array('class' => 'typename')); $output .= html_writer::tag('span', $module->title, array('class' => 'typename'));
if (!isset($module->help)) { if (!isset($module->help)) {
// Add help if found // Add help if found
$module->help = get_string('nohelpforactivityorresource', 'moodle'); $module->help = get_string('nohelpforactivityorresource', 'moodle');
} }
// Format the help text using markdown with the following options // Format the help text using markdown with the following options
$options = new stdClass(); $options = new stdClass();
$options->trusted = false; $options->trusted = false;
$options->noclean = false; $options->noclean = false;
$options->smiley = false; $options->smiley = false;
$options->filter = false; $options->filter = false;
$options->para = true; $options->para = true;
$options->newlines = false; $options->newlines = false;
$options->overflowdiv = false; $options->overflowdiv = false;
$module->help = format_text($module->help, FORMAT_MARKDOWN, $options); $module->help = format_text($module->help, FORMAT_MARKDOWN, $options);
$output .= html_writer::tag('span', $module->help, array('class' => 'typesummary')); $output .= html_writer::tag('span', $module->help, array('class' => 'typesummary'));
$output .= html_writer::end_tag('label'); $output .= html_writer::end_tag('label');
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
return $output; return $output;
} }
protected function course_modchooser_title($title, $identifier = null) { protected function course_modchooser_title($title, $identifier = null) {
$module = new stdClass(); $module = new stdClass();
$module->name = $title; $module->name = $title;
$module->types = array(); $module->types = array();
$module->title = get_string($title, $identifier); $module->title = get_string($title, $identifier);
$module->help = ''; $module->help = '';
return $this->course_modchooser_module($module, array('moduletypetitle')); return $this->course_modchooser_module($module, array('moduletypetitle'));
} }
/** /**
* Renders HTML for displaying the sequence of course module editing buttons * Renders HTML for displaying the sequence of course module editing buttons
* *
* @see course_get_cm_edit_actions() * @see course_get_cm_edit_actions()
* *
* @param action_link[] $actions Array of action_link objects * @param action_link[] $actions Array of action_link objects
* @param cm_info $mod The module we are displaying actions for. * @param cm_info $mod The module we are displaying actions for.
* @param array $displayoptions additional display options: * @param array $displayoptions additional display options:
* ownerselector => A JS/CSS selector that can be used to find an cm node. * ownerselector => A JS/CSS selector that can be used to find an cm node.
* If specified the owning node will be given the class 'action-menu-shown' when the action * If specified the owning node will be given the class 'action-menu-shown' when the action
* menu is being displayed. * menu is being displayed.
* constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain * constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
* the action menu to when it is being displayed. * the action menu to when it is being displayed.
* donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS. * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
* @return string * @return string
*/ */
public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) { public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) {
global $CFG; global $CFG;
if (empty($actions)) { if (empty($actions)) {
return ''; return '';
} }
if (isset($displayoptions['ownerselector'])) { if (isset($displayoptions['ownerselector'])) {
$ownerselector = $displayoptions['ownerselector']; $ownerselector = $displayoptions['ownerselector'];
} else if ($mod) { } else if ($mod) {
$ownerselector = '#module-'.$mod->id; $ownerselector = '#module-'.$mod->id;
} else { } else {
debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER); debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER);
$ownerselector = 'li.activity'; $ownerselector = 'li.activity';
} }
if (isset($displayoptions['constraintselector'])) { if (isset($displayoptions['constraintselector'])) {
$constraint = $displayoptions['constraintselector']; $constraint = $displayoptions['constraintselector'];
} else { } else {
$constraint = '.course-content'; $constraint = '.course-content';
} }
$menu = new action_menu(); $menu = new action_menu();
$menu->set_owner_selector($ownerselector); $menu->set_owner_selector($ownerselector);
$menu->set_constraint($constraint); $menu->set_constraint($constraint);
$menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_alignment(action_menu::TR, action_menu::BR);
$menu->set_menu_trigger(get_string('edit')); $menu->set_menu_trigger(get_string('edit'));
if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) { if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) {
$menu->do_not_enhance(); $menu->do_not_enhance();
// Swap the left/right icons. // Swap the left/right icons.
// Normally we have have right, then left but this does not // Normally we have have right, then left but this does not
// make sense when modactionmenu is disabled. // make sense when modactionmenu is disabled.
$moveright = null; $moveright = null;
$_actions = array(); $_actions = array();
foreach ($actions as $key => $value) { foreach ($actions as $key => $value) {
if ($key === 'moveright') { if ($key === 'moveright') {
// Save moveright for later. // Save moveright for later.
$moveright = $value; $moveright = $value;
} else if ($moveright) { } else if ($moveright) {
// This assumes that the order was moveright, moveleft. // This assumes that the order was moveright, moveleft.
// If we have a moveright, then we should place it immediately after the current value. // If we have a moveright, then we should place it immediately after the current value.
$_actions[$key] = $value; $_actions[$key] = $value;
$_actions['moveright'] = $moveright; $_actions['moveright'] = $moveright;
// Clear the value to prevent it being used multiple times. // Clear the value to prevent it being used multiple times.
$moveright = null; $moveright = null;
} else { } else {
$_actions[$key] = $value; $_actions[$key] = $value;
} }
} }
$actions = $_actions; $actions = $_actions;
unset($_actions); unset($_actions);
} }
foreach ($actions as $action) { foreach ($actions as $action) {
if ($action instanceof action_menu_link) { if ($action instanceof action_menu_link) {
$action->add_class('cm-edit-action'); $action->add_class('cm-edit-action');
} }
$menu->add($action); $menu->add($action);
} }
$menu->attributes['class'] .= ' section-cm-edit-actions commands'; $menu->attributes['class'] .= ' section-cm-edit-actions commands';
// Prioritise the menu ahead of all other actions. // Prioritise the menu ahead of all other actions.
$menu->prioritise = true; $menu->prioritise = true;
return $this->render($menu); return $this->render($menu);
} }
/** /**
* Renders HTML for the menus to add activities and resources to the current course * Renders HTML for the menus to add activities and resources to the current course
* *
* Note, if theme overwrites this function and it does not use modchooser, * Note, if theme overwrites this function and it does not use modchooser,
* see also {@link core_course_renderer::add_modchoosertoggle()} * see also {@link core_course_renderer::add_modchoosertoggle()}
* *
* @param stdClass $course * @param stdClass $course
* @param int $section relative section number (field course_sections.section) * @param int $section relative section number (field course_sections.section)
* @param int $sectionreturn The section to link back to * @param int $sectionreturn The section to link back to
* @param array $displayoptions additional display options, for example blocks add * @param array $displayoptions additional display options, for example blocks add
* option 'inblock' => true, suggesting to display controls vertically * option 'inblock' => true, suggesting to display controls vertically
* @return string * @return string
*/ */
function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) { function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) {
global $CFG; global $CFG;
$vertical = !empty($displayoptions['inblock']); $vertical = !empty($displayoptions['inblock']);
// check to see if user can add menus and there are modules to add // check to see if user can add menus and there are modules to add
if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id)) if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
|| !$this->page->user_is_editing() || !$this->page->user_is_editing()
|| !($modnames = get_module_types_names()) || empty($modnames)) { || !($modnames = get_module_types_names()) || empty($modnames)) {
return ''; return '';
} }
// Retrieve all modules with associated metadata // Retrieve all modules with associated metadata
$modules = get_module_metadata($course, $modnames, $sectionreturn); $modules = get_module_metadata($course, $modnames, $sectionreturn);
$urlparams = array('section' => $section); $urlparams = array('section' => $section);
// We'll sort resources and activities into two lists // We'll sort resources and activities into two lists
$activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array()); $activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
foreach ($modules as $module) { foreach ($modules as $module) {
if (isset($module->types)) { if (isset($module->types)) {
// This module has a subtype // This module has a subtype
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!! // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
$subtypes = array(); $subtypes = array();
foreach ($module->types as $subtype) { foreach ($module->types as $subtype) {
$link = $subtype->link->out(true, $urlparams); $link = $subtype->link->out(true, $urlparams);
$subtypes[$link] = $subtype->title; $subtypes[$link] = $subtype->title;
} }
// Sort module subtypes into the list // Sort module subtypes into the list
$activityclass = MOD_CLASS_ACTIVITY; $activityclass = MOD_CLASS_ACTIVITY;
if ($module->archetype == MOD_CLASS_RESOURCE) { if ($module->archetype == MOD_CLASS_RESOURCE) {
$activityclass = MOD_CLASS_RESOURCE; $activityclass = MOD_CLASS_RESOURCE;
} }
if (!empty($module->title)) { if (!empty($module->title)) {
// This grouping has a name // This grouping has a name
$activities[$activityclass][] = array($module->title => $subtypes); $activities[$activityclass][] = array($module->title => $subtypes);
} else { } else {
// This grouping does not have a name // This grouping does not have a name
$activities[$activityclass] = array_merge($activities[$activityclass], $subtypes); $activities[$activityclass] = array_merge($activities[$activityclass], $subtypes);
} }
} else { } else {
// This module has no subtypes // This module has no subtypes
$activityclass = MOD_CLASS_ACTIVITY; $activityclass = MOD_CLASS_ACTIVITY;
if ($module->archetype == MOD_ARCHETYPE_RESOURCE) { if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
$activityclass = MOD_CLASS_RESOURCE; $activityclass = MOD_CLASS_RESOURCE;
} else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) { } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
// System modules cannot be added by user, do not add to dropdown // System modules cannot be added by user, do not add to dropdown
continue; continue;
} }
$link = $module->link->out(true, $urlparams); $link = $module->link->out(true, $urlparams);
$activities[$activityclass][$link] = $module->title; $activities[$activityclass][$link] = $module->title;
} }
} }
$straddactivity = get_string('addactivity'); $straddactivity = get_string('addactivity');
$straddresource = get_string('addresource'); $straddresource = get_string('addresource');
$sectionname = get_section_name($course, $section); $sectionname = get_section_name($course, $section);
$strresourcelabel = get_string('addresourcetosection', null, $sectionname); $strresourcelabel = get_string('addresourcetosection', null, $sectionname);
$stractivitylabel = get_string('addactivitytosection', null, $sectionname); $stractivitylabel = get_string('addactivitytosection', null, $sectionname);
$output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section)); $output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section));
if (!$vertical) { if (!$vertical) {
$output .= html_writer::start_tag('div', array('class' => 'horizontal')); $output .= html_writer::start_tag('div', array('class' => 'horizontal'));
} }
if (!empty($activities[MOD_CLASS_RESOURCE])) { if (!empty($activities[MOD_CLASS_RESOURCE])) {
$select = new url_select($activities[MOD_CLASS_RESOURCE], '', array(''=>$straddresource), "ressection$section"); $select = new url_select($activities[MOD_CLASS_RESOURCE], '', array(''=>$straddresource), "ressection$section");
$select->set_help_icon('resources'); $select->set_help_icon('resources');
$select->set_label($strresourcelabel, array('class' => 'accesshide')); $select->set_label($strresourcelabel, array('class' => 'accesshide'));
$output .= $this->output->render($select); $output .= $this->output->render($select);
} }
if (!empty($activities[MOD_CLASS_ACTIVITY])) { if (!empty($activities[MOD_CLASS_ACTIVITY])) {
$select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array(''=>$straddactivity), "section$section"); $select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array(''=>$straddactivity), "section$section");
$select->set_help_icon('activities'); $select->set_help_icon('activities');
$select->set_label($stractivitylabel, array('class' => 'accesshide')); $select->set_label($stractivitylabel, array('class' => 'accesshide'));
$output .= $this->output->render($select); $output .= $this->output->render($select);
} }
if (!$vertical) { if (!$vertical) {
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
} }
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
if (course_ajax_enabled($course) && $course->id == $this->page->course->id) { if (course_ajax_enabled($course) && $course->id == $this->page->course->id) {
// modchooser can be added only for the current course set on the page! // modchooser can be added only for the current course set on the page!
$straddeither = get_string('addresourceoractivity'); $straddeither = get_string('addresourceoractivity');
// The module chooser link // The module chooser link
$modchooser = html_writer::start_tag('div', array('class' => 'mdl-right')); $modchooser = html_writer::start_tag('div', array('class' => 'mdl-right'));
$modchooser.= html_writer::start_tag('div', array('class' => 'section-modchooser')); $modchooser.= html_writer::start_tag('div', array('class' => 'section-modchooser'));
$icon = $this->output->pix_icon('t/add', ''); $icon = $this->output->pix_icon('t/add', '');
$span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text')); $span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text'));
$modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link')); $modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link'));
$modchooser.= html_writer::end_tag('div'); $modchooser.= html_writer::end_tag('div');
$modchooser.= html_writer::end_tag('div'); $modchooser.= html_writer::end_tag('div');
// Wrap the normal output in a noscript div // Wrap the normal output in a noscript div
$usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault); $usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault);
if ($usemodchooser) { if ($usemodchooser) {
$output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown')); $output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown'));
$modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser')); $modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser'));
} else { } else {
// If the module chooser is disabled, we need to ensure that the dropdowns are shown even if javascript is disabled // If the module chooser is disabled, we need to ensure that the dropdowns are shown even if javascript is disabled
$output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown')); $output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown'));
$modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser')); $modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser'));
} }
$output = $this->course_modchooser($modules, $course) . $modchooser . $output; $output = $this->course_modchooser($modules, $course) . $modchooser . $output;
} }
return $output; return $output;
} }
/** /**
* Renders html to display a course search form * Renders html to display a course search form
* *
* @param string $value default value to populate the search field * @param string $value default value to populate the search field
* @param string $format display format - 'plain' (default), 'short' or 'navbar' * @param string $format display format - 'plain' (default), 'short' or 'navbar'
* @return string * @return string
*/ */
function course_search_form($value = '', $format = 'plain') { function course_search_form($value = '', $format = 'plain') {
static $count = 0; static $count = 0;
$formid = 'coursesearch'; $formid = 'coursesearch';
if ((++$count) > 1) { if ((++$count) > 1) {
$formid .= $count; $formid .= $count;
} }
switch ($format) { switch ($format) {
case 'navbar' : case 'navbar' :
$formid = 'coursesearchnavbar'; $formid = 'coursesearchnavbar';
$inputid = 'navsearchbox'; $inputid = 'navsearchbox';
$inputsize = 20; $inputsize = 20;
break; break;
case 'short' : case 'short' :
$inputid = 'shortsearchbox'; $inputid = 'shortsearchbox';
$inputsize = 12; $inputsize = 12;
break; break;
default : default :
$inputid = 'coursesearchbox'; $inputid = 'coursesearchbox';
$inputsize = 30; $inputsize = 30;
} }
$strsearchcourses= get_string("searchcourses"); $strsearchcourses= get_string("searchcourses");
$searchurl = new moodle_url('/course/search.php'); $searchurl = new moodle_url('/course/search.php');
$output = html_writer::start_tag('form', array('id' => $formid, 'action' => $searchurl, 'method' => 'get')); $output = html_writer::start_tag('form', array('id' => $formid, 'action' => $searchurl, 'method' => 'get'));
$output .= html_writer::start_tag('fieldset', array('class' => 'coursesearchbox invisiblefieldset')); $output .= html_writer::start_tag('fieldset', array('class' => 'coursesearchbox invisiblefieldset'));
$output .= html_writer::tag('label', $strsearchcourses.': ', array('for' => $inputid)); $output .= html_writer::tag('label', $strsearchcourses.': ', array('for' => $inputid));
$output .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $inputid, $output .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $inputid,
'size' => $inputsize, 'name' => 'search', 'value' => s($value))); 'size' => $inputsize, 'name' => 'search', 'value' => s($value)));
$output .= html_writer::empty_tag('input', array('type' => 'submit', $output .= html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('go'))); 'value' => get_string('go')));
$output .= html_writer::end_tag('fieldset'); $output .= html_writer::end_tag('fieldset');
$output .= html_writer::end_tag('form'); $output .= html_writer::end_tag('form');
return $output; return $output;
} }
/** /**
* Renders html for completion box on course page * Renders html for completion box on course page
* *
* If completion is disabled, returns empty string * If completion is disabled, returns empty string
* If completion is automatic, returns an icon of the current completion state * If completion is automatic, returns an icon of the current completion state
* If completion is manual, returns a form (with an icon inside) that allows user to * If completion is manual, returns a form (with an icon inside) that allows user to
* toggle completion * toggle completion
* *
* @param stdClass $course course object * @param stdClass $course course object
* @param completion_info $completioninfo completion info for the course, it is recommended * @param completion_info $completioninfo completion info for the course, it is recommended
* to fetch once for all modules in course/section for performance * to fetch once for all modules in course/section for performance
* @param cm_info $mod module to show completion for * @param cm_info $mod module to show completion for
* @param array $displayoptions display options, not used in core * @param array $displayoptions display options, not used in core
* @return string * @return string
*/ */
public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) { public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) {
global $CFG; global $CFG;
$output = ''; $output = '';
if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) { if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) {
return $output; return $output;
} }
if ($completioninfo === null) { if ($completioninfo === null) {
$completioninfo = new completion_info($course); $completioninfo = new completion_info($course);
} }
$completion = $completioninfo->is_enabled($mod); $completion = $completioninfo->is_enabled($mod);
if ($completion == COMPLETION_TRACKING_NONE) { if ($completion == COMPLETION_TRACKING_NONE) {
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
$output .= html_writer::span('&nbsp;', 'filler'); $output .= html_writer::span('&nbsp;', 'filler');
} }
return $output; return $output;
} }
$completiondata = $completioninfo->get_data($mod, true); $completiondata = $completioninfo->get_data($mod, true);
$completionicon = ''; $completionicon = '';
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
switch ($completion) { switch ($completion) {
case COMPLETION_TRACKING_MANUAL : case COMPLETION_TRACKING_MANUAL :
$completionicon = 'manual-enabled'; break; $completionicon = 'manual-enabled'; break;
case COMPLETION_TRACKING_AUTOMATIC : case COMPLETION_TRACKING_AUTOMATIC :
$completionicon = 'auto-enabled'; break; $completionicon = 'auto-enabled'; break;
} }
} else if ($completion == COMPLETION_TRACKING_MANUAL) { } else if ($completion == COMPLETION_TRACKING_MANUAL) {
switch($completiondata->completionstate) { switch($completiondata->completionstate) {
case COMPLETION_INCOMPLETE: case COMPLETION_INCOMPLETE:
$completionicon = 'manual-n'; break; $completionicon = 'manual-n'; break;
case COMPLETION_COMPLETE: case COMPLETION_COMPLETE:
$completionicon = 'manual-y'; break; $completionicon = 'manual-y'; break;
} }
} else { // Automatic } else { // Automatic
switch($completiondata->completionstate) { switch($completiondata->completionstate) {
case COMPLETION_INCOMPLETE: case COMPLETION_INCOMPLETE:
$completionicon = 'auto-n'; break; $completionicon = 'auto-n'; break;
case COMPLETION_COMPLETE: case COMPLETION_COMPLETE:
$completionicon = 'auto-y'; break; $completionicon = 'auto-y'; break;
case COMPLETION_COMPLETE_PASS: case COMPLETION_COMPLETE_PASS:
$completionicon = 'auto-pass'; break; $completionicon = 'auto-pass'; break;
case COMPLETION_COMPLETE_FAIL: case COMPLETION_COMPLETE_FAIL:
$completionicon = 'auto-fail'; break; $completionicon = 'auto-fail'; break;
} }
} }
if ($completionicon) { if ($completionicon) {
$formattedname = $mod->get_formatted_name(); $formattedname = $mod->get_formatted_name();
$imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname); $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
// When editing, the icon is just an image. // When editing, the icon is just an image.
$completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '', $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
array('title' => $imgalt, 'class' => 'iconsmall')); array('title' => $imgalt, 'class' => 'iconsmall'));
$output .= html_writer::tag('span', $this->output->render($completionpixicon), $output .= html_writer::tag('span', $this->output->render($completionpixicon),
array('class' => 'autocompletion')); array('class' => 'autocompletion'));
} else if ($completion == COMPLETION_TRACKING_MANUAL) { } else if ($completion == COMPLETION_TRACKING_MANUAL) {
$imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname); $imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname);
$newstate = $newstate =
$completiondata->completionstate == COMPLETION_COMPLETE $completiondata->completionstate == COMPLETION_COMPLETE
? COMPLETION_INCOMPLETE ? COMPLETION_INCOMPLETE
: COMPLETION_COMPLETE; : COMPLETION_COMPLETE;
// In manual mode the icon is a toggle form... // In manual mode the icon is a toggle form...
// If this completion state is used by the // If this completion state is used by the
// conditional activities system, we need to turn // conditional activities system, we need to turn
// off the JS. // off the JS.
$extraclass = ''; $extraclass = '';
if (!empty($CFG->enableavailability) && if (!empty($CFG->enableavailability) &&
core_availability\info::completion_value_used($course, $mod->id)) { core_availability\info::completion_value_used($course, $mod->id)) {
$extraclass = ' preventjs'; $extraclass = ' preventjs';
} }
$output .= html_writer::start_tag('form', array('method' => 'post', $output .= html_writer::start_tag('form', array('method' => 'post',
'action' => new moodle_url('/course/togglecompletion.php'), 'action' => new moodle_url('/course/togglecompletion.php'),
'class' => 'togglecompletion'. $extraclass)); 'class' => 'togglecompletion'. $extraclass));
$output .= html_writer::start_tag('div'); $output .= html_writer::start_tag('div');
$output .= html_writer::empty_tag('input', array( $output .= html_writer::empty_tag('input', array(
'type' => 'hidden', 'name' => 'id', 'value' => $mod->id)); 'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
$output .= html_writer::empty_tag('input', array( $output .= html_writer::empty_tag('input', array(
'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); 'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
$output .= html_writer::empty_tag('input', array( $output .= html_writer::empty_tag('input', array(
'type' => 'hidden', 'name' => 'modulename', 'value' => $mod->name)); 'type' => 'hidden', 'name' => 'modulename', 'value' => $mod->name));
$output .= html_writer::empty_tag('input', array( $output .= html_writer::empty_tag('input', array(
'type' => 'hidden', 'name' => 'completionstate', 'value' => $newstate)); 'type' => 'hidden', 'name' => 'completionstate', 'value' => $newstate));
$output .= html_writer::empty_tag('input', array( $output .= html_writer::empty_tag('input', array(
'type' => 'image', 'type' => 'image',
'src' => $this->output->pix_url('i/completion-'.$completionicon), 'src' => $this->output->pix_url('i/completion-'.$completionicon),
'alt' => $imgalt, 'title' => $imgtitle, 'alt' => $imgalt, 'title' => $imgtitle,
'aria-live' => 'polite')); 'aria-live' => 'polite'));
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('form'); $output .= html_writer::end_tag('form');
} else { } else {
// In auto mode, the icon is just an image. // In auto mode, the icon is just an image.
$completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '', $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
array('title' => $imgalt)); array('title' => $imgalt));
$output .= html_writer::tag('span', $this->output->render($completionpixicon), $output .= html_writer::tag('span', $this->output->render($completionpixicon),
array('class' => 'autocompletion')); array('class' => 'autocompletion'));
} }
} }
return $output; return $output;
} }
/** /**
* Checks if course module has any conditions that may make it unavailable for * Checks if course module has any conditions that may make it unavailable for
* all or some of the students * all or some of the students
* *
* This function is internal and is only used to create CSS classes for the module name/text * This function is internal and is only used to create CSS classes for the module name/text
* *
* @param cm_info $mod * @param cm_info $mod
* @return bool * @return bool
*/ */
protected function is_cm_conditionally_hidden(cm_info $mod) { protected function is_cm_conditionally_hidden(cm_info $mod) {
global $CFG; global $CFG;
$conditionalhidden = false; $conditionalhidden = false;
if (!empty($CFG->enableavailability)) { if (!empty($CFG->enableavailability)) {
$info = new \core_availability\info_module($mod); $info = new \core_availability\info_module($mod);
$conditionalhidden = !$info->is_available_for_all(); $conditionalhidden = !$info->is_available_for_all();
} }
return $conditionalhidden; return $conditionalhidden;
} }
/** /**
* Renders html to display a name with the link to the course module on a course page * Renders html to display a name with the link to the course module on a course page
* *
* If module is unavailable for user but still needs to be displayed * If module is unavailable for user but still needs to be displayed
* in the list, just the name is returned without a link * in the list, just the name is returned without a link
* *
* Note, that for course modules that never have separate pages (i.e. labels) * Note, that for course modules that never have separate pages (i.e. labels)
* this function return an empty string * this function return an empty string
* *
* @param cm_info $mod * @param cm_info $mod
* @param array $displayoptions * @param array $displayoptions
* @return string * @return string
*/ */
public function course_section_cm_name(cm_info $mod, $displayoptions = array()) { public function course_section_cm_name(cm_info $mod, $displayoptions = array()) {
$output = '';
if (!$mod->uservisible && empty($mod->availableinfo)) {
// nothing to be displayed to the user
return $output;
}
$url = $mod->url;
if (!$url) {
return $output;
}
//Accessibility: for files get description via icon, this is very ugly hack!
$instancename = $mod->get_formatted_name();
$altname = $mod->modfullname;
// Avoid unnecessary duplication: if e.g. a forum name already
// includes the word forum (or Forum, etc) then it is unhelpful
// to include that in the accessible description that is added.
if (false !== strpos(core_text::strtolower($instancename),
core_text::strtolower($altname))) {
$altname = '';
}
// File type after name, for alphabetic lists (screen reader).
if ($altname) {
$altname = get_accesshide(' '.$altname);
}
// For items which are hidden but available to current user
// ($mod->uservisible), we show those as dimmed only if the user has
// viewhiddenactivities, so that teachers see 'items which might not
// be available to some students' dimmed but students do not see 'item
// which is actually available to current student' dimmed.
$linkclasses = '';
$accesstext = '';
$textclasses = '';
if ($mod->uservisible) {
$conditionalhidden = $this->is_cm_conditionally_hidden($mod);
$accessiblebutdim = (!$mod->visible || $conditionalhidden) &&
has_capability('moodle/course:viewhiddenactivities', $mod->context);
if ($accessiblebutdim) {
$linkclasses .= ' dimmed';
$textclasses .= ' dimmed_text';
if ($conditionalhidden) {
$linkclasses .= ' conditionalhidden';
$textclasses .= ' conditionalhidden';
}
// Show accessibility note only if user can access the module himself.
$accesstext = get_accesshide(get_string('hiddenfromstudents').':'. $mod->modfullname);
}
} else {
$linkclasses .= ' dimmed';
$textclasses .= ' dimmed_text';
}
// Get on-click attribute value if specified and decode the onclick - it
// has already been encoded for display (puke).
$onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES);
$groupinglabel = $mod->get_grouping_label($textclasses);
// Display link itself.
$activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) . $accesstext .
html_writer::tag('span', $instancename . $altname, array('class' => 'instancename'));
$filename = $url;
if ($mod->uservisible) {
/* Start of Frankie code */
//print_object($activitylink);
if (
(strpos($activitylink,'writer-24') !== false) ||
(strpos($activitylink,'calc-24') !== false) ||
(strpos($activitylink,'impress-24') !== false)
)
{
$url = str_replace("/m30/","/m30/ViewerJS/#../", $url);
$output .= html_writer::link($url, $activitylink, array(/*'title'=>'Click text to pop-up PDF',*/'rel' => 'shadowbox[Mixed]'/*,'onclick' => $onclick*/)) .
$groupinglabel;
/*
$output .= html_writer::link($url, $activitylink,
array('data-fancybox-type' => 'iframe', 'class' => 'fancybox', 'onclick' => $onclick)) .
$groupinglabel;
*/
}
else
if (strpos($activitylink,'pdf-24') !== false)
{
/*$browser = $_SERVER['HTTP_USER_AGENT'];
$chrome = '/Chrome/';
$firefox = '/Firefox/';
$ie = '/MSIE/';
if (preg_match($firefox, $browser))
*/
if (core_useragent::is_chrome())
{
/*This code replaces this: http://cefl4u.org/teach/pdf.js-gh-pages/web/viewer.html?file=http://cefl4u.org/teach/mod/resource/view.php%3Fid=44
with this: http://cefl4u.org/teach/pdf.js-gh-pages/web/viewer.html?file=http%3A%2F%2Fcefl4u%2Eorg%2Fteach%2Fmod%2Fresource%2Fview%2Ephp%3Fid%3D44
%3A : Colon
%2F / Solidus (slash)
%2E . Period (fullstop)
%3D = Equals sign
%3F ? Question mark
*/
global $CFG;
$newurl = str_replace(':','%3A', $url);
$newurl = str_replace('/','%2F', $newurl);
$newurl = str_replace('.','%2E', $newurl);
$newurl = str_replace('?','%3F', $newurl);
$newurl = str_replace('=','%3D', $newurl);
$newurl = $CFG->wwwroot.'/pdf.js-gh-pages/web/viewer.html?file='.$newurl;
$activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation'));
//So hard to just add the word download but here it is!
//$output .= str_replace('=""','',html_writer::link($url, $activitylink, str_replace('=""','',array('download'=>'','title'=>'Click icon to download'))));
$output .= str_replace('=""','',html_writer::link($url, $activitylink, array('download'=>'','title'=>'Click icon to download')));
$instancename = html_writer::start_span('instancename').$instancename.
html_writer::start_span('accesshide ').'File'.
html_writer::end_span().
html_writer::end_span();
//ShadowBox
$output .= html_writer::link($newurl, $instancename, array('title'=>'Click text to pop-up PDF','rel' => 'shadowbox[Mixed]','onclick' => $onclick)) .
$groupinglabel;
} else
if (core_useragent::is_firefox()) {
global $CFG;
$newurl = str_replace(':','%3A', $url);
$newurl = str_replace('/','%2F', $newurl);
$newurl = str_replace('.','%2E', $newurl);
$newurl = str_replace('?','%3F', $newurl);
$newurl = str_replace('=','%3D', $newurl);
$newurl = $CFG->wwwroot.'/pdf.js-gh-pages/web/viewer.html?file='.$newurl;
$activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation'));
//So hard to just add the word download but here it is!
//$output .= str_replace('=""','',html_writer::link($url, $activitylink, str_replace('=""','',array('download'=>'','title'=>'Click icon to download'))));
$output .= str_replace('=""','',html_writer::link($url, $activitylink, array('download'=>'','title'=>'Right-click icon to download')));
$instancename = html_writer::start_span('instancename').$instancename.
html_writer::start_span('accesshide ').'File'.
html_writer::end_span().
html_writer::end_span();
//ShadowBox
$output .= html_writer::link($newurl, $instancename, array('title'=>'Click text to pop-up PDF','rel' => 'shadowbox[Mixed]'/*,'onclick' => $onclick*/)) .
$groupinglabel;
}
else if (core_useragent::is_safari_ios())
{
global $CFG;
$newurl = str_replace(':','%3A', $url);
$newurl = str_replace('/','%2F', $newurl);
$newurl = str_replace('.','%2E', $newurl);
$newurl = str_replace('?','%3F', $newurl);
$newurl = str_replace('=','%3D', $newurl);
$newurl = $CFG->wwwroot.'/pdf.js-gh-pages/web/viewer.html?file='.$newurl;
//ShadowBox
$output .= html_writer::link($newurl, $activitylink, array('title'=>'Click text to
pop-up PDF', 'rel' => 'shadowbox[Mixed]','onclick' => $onclick)) .
$groupinglabel;
}
else if(core_useragent::is_ie())
{ /* Opera, and ALL others!!! */
global $CFG;
$newurl = str_replace(':','%3A', $url);
$newurl = str_replace('/','%2F', $newurl);
$newurl = str_replace('.','%2E', $newurl);
$newurl = str_replace('?','%3F', $newurl);
$newurl = str_replace('=','%3D', $newurl);
$newurl = $CFG->wwwroot.'/pdf.js-gh-pages/web/viewer.html?file='.$newurl;
//ShadowBox
$output .= html_writer::link($newurl, $activitylink, array('title'=>'Click text to pop-up PDF','rel' => 'shadowbox[Mixed]','onclick' => $onclick)).
$groupinglabel;
}
else
{ /* Opera, and ALL others!!! */
global $CFG;
$newurl = str_replace(':','%3A', $url);
$newurl = str_replace('/','%2F', $newurl);
$newurl = str_replace('.','%2E', $newurl);
$newurl = str_replace('?','%3F', $newurl);
$newurl = str_replace('=','%3D', $newurl);
$newurl = $CFG->wwwroot.'/pdf.js-gh-pages/web/viewer.html?file='.$newurl;
//ShadowBox
$output .= html_writer::link($newurl, $activitylink, array('title'=>'Click text to pop-up PDF','rel' => 'shadowbox[Mixed]','onclick' => $onclick)).
$groupinglabel;
}
}
else {
$output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick)) .
$groupinglabel;
}
/* End of Frankie code */
} else {
// We may be displaying this just in order to show information
// about visibility, without the actual link ($mod->uservisible)
$output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)) .
$groupinglabel;
}
return $output;
}
/* public function course_section_cm_name(cm_info $mod, $displayoptions = array()) {
global $CFG; global $CFG;
$output = ''; $output = '';
if (!$mod->uservisible && empty($mod->availableinfo)) { if (!$mod->uservisible && empty($mod->availableinfo)) {
// nothing to be displayed to the user // nothing to be displayed to the user
return $output; return $output;
} }
$url = $mod->url; $url = $mod->url;
if (!$url) { if (!$url) {
return $output; return $output;
} }
//Accessibility: for files get description via icon, this is very ugly hack! //Accessibility: for files get description via icon, this is very ugly hack!
$instancename = $mod->get_formatted_name(); $instancename = $mod->get_formatted_name();
$altname = $mod->modfullname; $altname = $mod->modfullname;
// Avoid unnecessary duplication: if e.g. a forum name already // Avoid unnecessary duplication: if e.g. a forum name already
// includes the word forum (or Forum, etc) then it is unhelpful // includes the word forum (or Forum, etc) then it is unhelpful
// to include that in the accessible description that is added. // to include that in the accessible description that is added.
if (false !== strpos(core_text::strtolower($instancename), if (false !== strpos(core_text::strtolower($instancename),
core_text::strtolower($altname))) { core_text::strtolower($altname))) {
$altname = ''; $altname = '';
} }
// File type after name, for alphabetic lists (screen reader). // File type after name, for alphabetic lists (screen reader).
if ($altname) { if ($altname) {
$altname = get_accesshide(' '.$altname); $altname = get_accesshide(' '.$altname);
} }
// For items which are hidden but available to current user // For items which are hidden but available to current user
// ($mod->uservisible), we show those as dimmed only if the user has // ($mod->uservisible), we show those as dimmed only if the user has
// viewhiddenactivities, so that teachers see 'items which might not // viewhiddenactivities, so that teachers see 'items which might not
// be available to some students' dimmed but students do not see 'item // be available to some students' dimmed but students do not see 'item
// which is actually available to current student' dimmed. // which is actually available to current student' dimmed.
$linkclasses = ''; $linkclasses = '';
$accesstext = ''; $accesstext = '';
$textclasses = ''; $textclasses = '';
if ($mod->uservisible) { if ($mod->uservisible) {
$conditionalhidden = $this->is_cm_conditionally_hidden($mod); $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
$accessiblebutdim = (!$mod->visible || $conditionalhidden) && $accessiblebutdim = (!$mod->visible || $conditionalhidden) &&
has_capability('moodle/course:viewhiddenactivities', $mod->context); has_capability('moodle/course:viewhiddenactivities', $mod->context);
if ($accessiblebutdim) { if ($accessiblebutdim) {
$linkclasses .= ' dimmed'; $linkclasses .= ' dimmed';
$textclasses .= ' dimmed_text'; $textclasses .= ' dimmed_text';
if ($conditionalhidden) { if ($conditionalhidden) {
$linkclasses .= ' conditionalhidden'; $linkclasses .= ' conditionalhidden';
$textclasses .= ' conditionalhidden'; $textclasses .= ' conditionalhidden';
} }
// Show accessibility note only if user can access the module himself. // Show accessibility note only if user can access the module himself.
$accesstext = get_accesshide(get_string('hiddenfromstudents').':'. $mod->modfullname); $accesstext = get_accesshide(get_string('hiddenfromstudents').':'. $mod->modfullname);
} }
} else { } else {
$linkclasses .= ' dimmed'; $linkclasses .= ' dimmed';
$textclasses .= ' dimmed_text'; $textclasses .= ' dimmed_text';
} }
// Get on-click attribute value if specified and decode the onclick - it // Get on-click attribute value if specified and decode the onclick - it
// has already been encoded for display (puke). // has already been encoded for display (puke).
$onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES); $onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES);
$groupinglabel = $mod->get_grouping_label($textclasses); $groupinglabel = $mod->get_grouping_label($textclasses);
// Display link itself. // Display link itself.
$activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(), $activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) . $accesstext . 'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) . $accesstext .
html_writer::tag('span', $instancename . $altname, array('class' => 'instancename')); html_writer::tag('span', $instancename . $altname, array('class' => 'instancename'));
if ($mod->uservisible) { if ($mod->uservisible) {
$output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick)) . $output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick)) .
$groupinglabel; $groupinglabel;
} else { } else {
// We may be displaying this just in order to show information // We may be displaying this just in order to show information
// about visibility, without the actual link ($mod->uservisible) // about visibility, without the actual link ($mod->uservisible)
$output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)) . $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)) .
$groupinglabel; $groupinglabel;
} }
return $output; return $output;
} }
*/
/** /**
* Renders html to display the module content on the course page (i.e. text of the labels) * Renders html to display the module content on the course page (i.e. text of the labels)
* *
* @param cm_info $mod * @param cm_info $mod
* @param array $displayoptions * @param array $displayoptions
* @return string * @return string
*/ */
public function course_section_cm_text(cm_info $mod, $displayoptions = array()) { public function course_section_cm_text(cm_info $mod, $displayoptions = array()) {
$output = ''; $output = '';
if (!$mod->uservisible && empty($mod->availableinfo)) { if (!$mod->uservisible && empty($mod->availableinfo)) {
// nothing to be displayed to the user // nothing to be displayed to the user
return $output; return $output;
} }
$content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$accesstext = ''; $accesstext = '';
$textclasses = ''; $textclasses = '';
if ($mod->uservisible) { if ($mod->uservisible) {
$conditionalhidden = $this->is_cm_conditionally_hidden($mod); $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
$accessiblebutdim = (!$mod->visible || $conditionalhidden) && $accessiblebutdim = (!$mod->visible || $conditionalhidden) &&
has_capability('moodle/course:viewhiddenactivities', $mod->context); has_capability('moodle/course:viewhiddenactivities', $mod->context);
if ($accessiblebutdim) { if ($accessiblebutdim) {
$textclasses .= ' dimmed_text'; $textclasses .= ' dimmed_text';
if ($conditionalhidden) { if ($conditionalhidden) {
$textclasses .= ' conditionalhidden'; $textclasses .= ' conditionalhidden';
} }
// Show accessibility note only if user can access the module himself. // Show accessibility note only if user can access the module himself.
$accesstext = get_accesshide(get_string('hiddenfromstudents').':'. $mod->modfullname); $accesstext = get_accesshide(get_string('hiddenfromstudents').':'. $mod->modfullname);
} }
} else { } else {
$textclasses .= ' dimmed_text'; $textclasses .= ' dimmed_text';
} }
if ($mod->url) { if ($mod->url) {
if ($content) { if ($content) {
// If specified, display extra content after link. // If specified, display extra content after link.
$output = html_writer::tag('div', $content, array('class' => $output = html_writer::tag('div', $content, array('class' =>
trim('contentafterlink ' . $textclasses))); trim('contentafterlink ' . $textclasses)));
} }
} else { } else {
$groupinglabel = $mod->get_grouping_label($textclasses); $groupinglabel = $mod->get_grouping_label($textclasses);
// No link, so display only content. // No link, so display only content.
$output = html_writer::tag('div', $accesstext . $content . $groupinglabel, $output = html_writer::tag('div', $accesstext . $content . $groupinglabel,
array('class' => 'contentwithoutlink ' . $textclasses)); array('class' => 'contentwithoutlink ' . $textclasses));
} }
return $output; return $output;
} }
/** /**
* Renders HTML to show course module availability information (for someone who isn't allowed * Renders HTML to show course module availability information (for someone who isn't allowed
* to see the activity itself, or for staff) * to see the activity itself, or for staff)
* *
* @param cm_info $mod * @param cm_info $mod
* @param array $displayoptions * @param array $displayoptions
* @return string * @return string
*/ */
public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) { public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) {
global $CFG; global $CFG;
if (!$mod->uservisible) { if (!$mod->uservisible) {
// this is a student who is not allowed to see the module but might be allowed // this is a student who is not allowed to see the module but might be allowed
// to see availability info (i.e. "Available from ...") // to see availability info (i.e. "Available from ...")
if (!empty($mod->availableinfo)) { if (!empty($mod->availableinfo)) {
$formattedinfo = \core_availability\info::format_info( $formattedinfo = \core_availability\info::format_info(
$mod->availableinfo, $mod->get_course()); $mod->availableinfo, $mod->get_course());
$output = html_writer::tag('div', $formattedinfo, array('class' => 'availabilityinfo')); $output = html_writer::tag('div', $formattedinfo, array('class' => 'availabilityinfo'));
} }
return $output; return $output;
} }
// this is a teacher who is allowed to see module but still should see the // this is a teacher who is allowed to see module but still should see the
// information that module is not available to all/some students // information that module is not available to all/some students
$modcontext = context_module::instance($mod->id); $modcontext = context_module::instance($mod->id);
$canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext); $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
if ($canviewhidden && !empty($CFG->enableavailability)) { if ($canviewhidden && !empty($CFG->enableavailability)) {
// Don't add availability information if user is not editing and activity is hidden. // Don't add availability information if user is not editing and activity is hidden.
if ($mod->visible || $this->page->user_is_editing()) { if ($mod->visible || $this->page->user_is_editing()) {
$hidinfoclass = ''; $hidinfoclass = '';
if (!$mod->visible) { if (!$mod->visible) {
$hidinfoclass = 'hide'; $hidinfoclass = 'hide';
} }
$ci = new \core_availability\info_module($mod); $ci = new \core_availability\info_module($mod);
$fullinfo = $ci->get_full_information(); $fullinfo = $ci->get_full_information();
if ($fullinfo) { if ($fullinfo) {
$formattedinfo = \core_availability\info::format_info( $formattedinfo = \core_availability\info::format_info(
$fullinfo, $mod->get_course()); $fullinfo, $mod->get_course());
return html_writer::div($formattedinfo, 'availabilityinfo ' . $hidinfoclass); return html_writer::div($formattedinfo, 'availabilityinfo ' . $hidinfoclass);
} }
} }
} }
return ''; return '';
} }
/** /**
* Renders HTML to display one course module for display within a section. * Renders HTML to display one course module for display within a section.
* *
* This function calls: * This function calls:
* {@link core_course_renderer::course_section_cm()} * {@link core_course_renderer::course_section_cm()}
* *
* @param stdClass $course * @param stdClass $course
* @param completion_info $completioninfo * @param completion_info $completioninfo
* @param cm_info $mod * @param cm_info $mod
* @param int|null $sectionreturn * @param int|null $sectionreturn
* @param array $displayoptions * @param array $displayoptions
* @return String * @return String
*/ */
public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) { public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
$output = ''; $output = '';
if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) { if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) {
$modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->extraclasses; $modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->extraclasses;
$output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id)); $output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id));
} }
return $output; return $output;
} }
/** /**
* Renders HTML to display one course module in a course section * Renders HTML to display one course module in a course section
* *
* This includes link, content, availability, completion info and additional information * This includes link, content, availability, completion info and additional information
* that module type wants to display (i.e. number of unread forum posts) * that module type wants to display (i.e. number of unread forum posts)
* *
* This function calls: * This function calls:
* {@link core_course_renderer::course_section_cm_name()} * {@link core_course_renderer::course_section_cm_name()}
* {@link core_course_renderer::course_section_cm_text()} * {@link core_course_renderer::course_section_cm_text()}
* {@link core_course_renderer::course_section_cm_availability()} * {@link core_course_renderer::course_section_cm_availability()}
* {@link core_course_renderer::course_section_cm_completion()} * {@link core_course_renderer::course_section_cm_completion()}
* {@link course_get_cm_edit_actions()} * {@link course_get_cm_edit_actions()}
* {@link core_course_renderer::course_section_cm_edit_actions()} * {@link core_course_renderer::course_section_cm_edit_actions()}
* *
* @param stdClass $course * @param stdClass $course
* @param completion_info $completioninfo * @param completion_info $completioninfo
* @param cm_info $mod * @param cm_info $mod
* @param int|null $sectionreturn * @param int|null $sectionreturn
* @param array $displayoptions * @param array $displayoptions
* @return string * @return string
*/ */
public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) { public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
$output = ''; $output = '';
// We return empty string (because course module will not be displayed at all) // We return empty string (because course module will not be displayed at all)
// if: // if:
// 1) The activity is not visible to users // 1) The activity is not visible to users
// and // and
// 2) The 'availableinfo' is empty, i.e. the activity was // 2) The 'availableinfo' is empty, i.e. the activity was
// hidden in a way that leaves no info, such as using the // hidden in a way that leaves no info, such as using the
// eye icon. // eye icon.
if (!$mod->uservisible && empty($mod->availableinfo)) { if (!$mod->uservisible && empty($mod->availableinfo)) {
return $output; return $output;
} }
$indentclasses = 'mod-indent'; $indentclasses = 'mod-indent';
if (!empty($mod->indent)) { if (!empty($mod->indent)) {
$indentclasses .= ' mod-indent-'.$mod->indent; $indentclasses .= ' mod-indent-'.$mod->indent;
if ($mod->indent > 15) { if ($mod->indent > 15) {
$indentclasses .= ' mod-indent-huge'; $indentclasses .= ' mod-indent-huge';
} }
} }
$output .= html_writer::start_tag('div'); $output .= html_writer::start_tag('div');
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
$output .= course_get_cm_move($mod, $sectionreturn); $output .= course_get_cm_move($mod, $sectionreturn);
} }
$output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer')); $output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer'));
// This div is used to indent the content. // This div is used to indent the content.
$output .= html_writer::div('', $indentclasses); $output .= html_writer::div('', $indentclasses);
// Start a wrapper for the actual content to keep the indentation consistent // Start a wrapper for the actual content to keep the indentation consistent
$output .= html_writer::start_tag('div'); $output .= html_writer::start_tag('div');
// Display the link to the module (or do nothing if module has no url) // Display the link to the module (or do nothing if module has no url)
$cmname = $this->course_section_cm_name($mod, $displayoptions); $cmname = $this->course_section_cm_name($mod, $displayoptions);
if (!empty($cmname)) { if (!empty($cmname)) {
// Start the div for the activity title, excluding the edit icons. // Start the div for the activity title, excluding the edit icons.
$output .= html_writer::start_tag('div', array('class' => 'activityinstance')); $output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
$output .= $cmname; $output .= $cmname;
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
$output .= ' ' . course_get_cm_rename_action($mod, $sectionreturn); $output .= ' ' . course_get_cm_rename_action($mod, $sectionreturn);
} }
// Module can put text after the link (e.g. forum unread) // Module can put text after the link (e.g. forum unread)
$output .= $mod->afterlink; $output .= $mod->afterlink;
// Closing the tag which contains everything but edit icons. Content part of the module should not be part of this. // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
$output .= html_writer::end_tag('div'); // .activityinstance $output .= html_writer::end_tag('div'); // .activityinstance
} }
// If there is content but NO link (eg label), then display the // If there is content but NO link (eg label), then display the
// content here (BEFORE any icons). In this case cons must be // content here (BEFORE any icons). In this case cons must be
// displayed after the content so that it makes more sense visually // displayed after the content so that it makes more sense visually
// and for accessibility reasons, e.g. if you have a one-line label // and for accessibility reasons, e.g. if you have a one-line label
// it should work similarly (at least in terms of ordering) to an // it should work similarly (at least in terms of ordering) to an
// activity. // activity.
$contentpart = $this->course_section_cm_text($mod, $displayoptions); $contentpart = $this->course_section_cm_text($mod, $displayoptions);
$url = $mod->url; $url = $mod->url;
if (empty($url)) { if (empty($url)) {
$output .= $contentpart; $output .= $contentpart;
} }
$modicons = ''; $modicons = '';
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
$editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn); $editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
$modicons .= ' '. $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions); $modicons .= ' '. $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
$modicons .= $mod->afterediticons; $modicons .= $mod->afterediticons;
} }
$modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions); $modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
if (!empty($modicons)) { if (!empty($modicons)) {
$output .= html_writer::span($modicons, 'actions'); $output .= html_writer::span($modicons, 'actions');
} }
// If there is content AND a link, then display the content here // If there is content AND a link, then display the content here
// (AFTER any icons). Otherwise it was displayed before // (AFTER any icons). Otherwise it was displayed before
if (!empty($url)) { if (!empty($url)) {
$output .= $contentpart; $output .= $contentpart;
} }
// show availability info (if module is not available) // show availability info (if module is not available)
$output .= $this->course_section_cm_availability($mod, $displayoptions); $output .= $this->course_section_cm_availability($mod, $displayoptions);
$output .= html_writer::end_tag('div'); // $indentclasses $output .= html_writer::end_tag('div'); // $indentclasses
// End of indentation div. // End of indentation div.
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div');
return $output; return $output;
} }
/** /**
* Renders HTML to display a list of course modules in a course section * Renders HTML to display a list of course modules in a course section
* Also displays "move here" controls in Javascript-disabled mode * Also displays "move here" controls in Javascript-disabled mode
* *
* This function calls {@link core_course_renderer::course_section_cm()} * This function calls {@link core_course_renderer::course_section_cm()}
* *
* @param stdClass $course course object * @param stdClass $course course object
* @param int|stdClass|section_info $section relative section number or section object * @param int|stdClass|section_info $section relative section number or section object
* @param int $sectionreturn section number to return to * @param int $sectionreturn section number to return to
* @param int $displayoptions * @param int $displayoptions
* @return void * @return void
*/ */
public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array()) { public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array()) {
global $USER; global $USER;
$output = ''; $output = '';
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
if (is_object($section)) { if (is_object($section)) {
$section = $modinfo->get_section_info($section->section); $section = $modinfo->get_section_info($section->section);
} else { } else {
$section = $modinfo->get_section_info($section); $section = $modinfo->get_section_info($section);
} }
$completioninfo = new completion_info($course); $completioninfo = new completion_info($course);
// check if we are currently in the process of moving a module with JavaScript disabled // check if we are currently in the process of moving a module with JavaScript disabled
$ismoving = $this->page->user_is_editing() && ismoving($course->id); $ismoving = $this->page->user_is_editing() && ismoving($course->id);
if ($ismoving) { if ($ismoving) {
$movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget')); $movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget'));
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
} }
// Get the list of modules visible to user (excluding the module being moved if there is one) // Get the list of modules visible to user (excluding the module being moved if there is one)
$moduleshtml = array(); $moduleshtml = array();
if (!empty($modinfo->sections[$section->section])) { if (!empty($modinfo->sections[$section->section])) {
foreach ($modinfo->sections[$section->section] as $modnumber) { foreach ($modinfo->sections[$section->section] as $modnumber) {
$mod = $modinfo->cms[$modnumber]; $mod = $modinfo->cms[$modnumber];
if ($ismoving and $mod->id == $USER->activitycopy) { if ($ismoving and $mod->id == $USER->activitycopy) {
// do not display moving mod // do not display moving mod
continue; continue;
} }
if ($modulehtml = $this->course_section_cm_list_item($course, if ($modulehtml = $this->course_section_cm_list_item($course,
$completioninfo, $mod, $sectionreturn, $displayoptions)) { $completioninfo, $mod, $sectionreturn, $displayoptions)) {
$moduleshtml[$modnumber] = $modulehtml; $moduleshtml[$modnumber] = $modulehtml;
} }
} }
} }
$sectionoutput = ''; $sectionoutput = '';
if (!empty($moduleshtml) || $ismoving) { if (!empty($moduleshtml) || $ismoving) {
foreach ($moduleshtml as $modnumber => $modulehtml) { foreach ($moduleshtml as $modnumber => $modulehtml) {
if ($ismoving) { if ($ismoving) {
$movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey())); $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
$sectionoutput .= html_writer::tag('li', $sectionoutput .= html_writer::tag('li',
html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)), html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)),
array('class' => 'movehere')); array('class' => 'movehere'));
} }
$sectionoutput .= $modulehtml; $sectionoutput .= $modulehtml;
} }
if ($ismoving) { if ($ismoving) {
$movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey())); $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
$sectionoutput .= html_writer::tag('li', $sectionoutput .= html_writer::tag('li',
html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)), html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)),
array('class' => 'movehere')); array('class' => 'movehere'));
} }
} }
// Always output the section module list. // Always output the section module list.
$output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text')); $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
return $output; return $output;
} }
/** /**
* Displays a custom list of courses with paging bar if necessary * Displays a custom list of courses with paging bar if necessary
* *
* If $paginationurl is specified but $totalcount is not, the link 'View more' * If $paginationurl is specified but $totalcount is not, the link 'View more'
* appears under the list. * appears under the list.
* *
* If both $paginationurl and $totalcount are specified, and $totalcount is * If both $paginationurl and $totalcount are specified, and $totalcount is
* bigger than count($courses), a paging bar is displayed above and under the * bigger than count($courses), a paging bar is displayed above and under the
* courses list. * courses list.
* *
* @param array $courses array of course records (or instances of course_in_list) to show on this page * @param array $courses array of course records (or instances of course_in_list) to show on this page
* @param bool $showcategoryname whether to add category name to the course description * @param bool $showcategoryname whether to add category name to the course description
* @param string $additionalclasses additional CSS classes to add to the div.courses * @param string $additionalclasses additional CSS classes to add to the div.courses
* @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar * @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar
* @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link * @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link
* @param int $page current page number (defaults to 0 referring to the first page) * @param int $page current page number (defaults to 0 referring to the first page)
* @param int $perpage number of records per page (defaults to $CFG->coursesperpage) * @param int $perpage number of records per page (defaults to $CFG->coursesperpage)
* @return string * @return string
*/ */
public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) { public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) {
global $CFG; global $CFG;
// create instance of coursecat_helper to pass display options to function rendering courses list // create instance of coursecat_helper to pass display options to function rendering courses list
$chelper = new coursecat_helper(); $chelper = new coursecat_helper();
if ($showcategoryname) { if ($showcategoryname) {
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT);
} else { } else {
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
} }
if ($totalcount !== null && $paginationurl !== null) { if ($totalcount !== null && $paginationurl !== null) {
// add options to display pagination // add options to display pagination
if ($perpage === null) { if ($perpage === null) {
$perpage = $CFG->coursesperpage; $perpage = $CFG->coursesperpage;
} }
$chelper->set_courses_display_options(array( $chelper->set_courses_display_options(array(
'limit' => $perpage, 'limit' => $perpage,
'offset' => ((int)$page) * $perpage, 'offset' => ((int)$page) * $perpage,
'paginationurl' => $paginationurl, 'paginationurl' => $paginationurl,
)); ));
} else if ($paginationurl !== null) { } else if ($paginationurl !== null) {
// add options to display 'View more' link // add options to display 'View more' link
$chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl)); $chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl));
$totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed $totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed
} }
$chelper->set_attributes(array('class' => $additionalclasses)); $chelper->set_attributes(array('class' => $additionalclasses));
$content = $this->coursecat_courses($chelper, $courses, $totalcount); $content = $this->coursecat_courses($chelper, $courses, $totalcount);
return $content; return $content;
} }
/** /**
* Displays one course in the list of courses. * Displays one course in the list of courses.
* *
* This is an internal function, to display an information about just one course * This is an internal function, to display an information about just one course
* please use {@link core_course_renderer::course_info_box()} * please use {@link core_course_renderer::course_info_box()}
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param course_in_list|stdClass $course * @param course_in_list|stdClass $course
* @param string $additionalclasses additional classes to add to the main <div> tag (usually * @param string $additionalclasses additional classes to add to the main <div> tag (usually
* depend on the course position in list - first/last/even/odd) * depend on the course position in list - first/last/even/odd)
* @return string * @return string
*/ */
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') { protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
global $CFG; global $CFG;
if (!isset($this->strings->summary)) { if (!isset($this->strings->summary)) {
$this->strings->summary = get_string('summary'); $this->strings->summary = get_string('summary');
} }
if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) { if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
return ''; return '';
} }
if ($course instanceof stdClass) { if ($course instanceof stdClass) {
require_once($CFG->libdir. '/coursecatlib.php'); require_once($CFG->libdir. '/coursecatlib.php');
$course = new course_in_list($course); $course = new course_in_list($course);
} }
$content = ''; $content = '';
$classes = trim('coursebox clearfix '. $additionalclasses); $classes = trim('coursebox clearfix '. $additionalclasses);
if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) { if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
$nametag = 'h3'; $nametag = 'h3';
} else { } else {
$classes .= ' collapsed'; $classes .= ' collapsed';
$nametag = 'div'; $nametag = 'div';
} }
// .coursebox // .coursebox
$content .= html_writer::start_tag('div', array( $content .= html_writer::start_tag('div', array(
'class' => $classes, 'class' => $classes,
'data-courseid' => $course->id, 'data-courseid' => $course->id,
'data-type' => self::COURSECAT_TYPE_COURSE, 'data-type' => self::COURSECAT_TYPE_COURSE,
)); ));
$content .= html_writer::start_tag('div', array('class' => 'info')); $content .= html_writer::start_tag('div', array('class' => 'info'));
// course name // course name
$coursename = $chelper->get_course_formatted_name($course); $coursename = $chelper->get_course_formatted_name($course);
$coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
$coursename, array('class' => $course->visible ? '' : 'dimmed')); $coursename, array('class' => $course->visible ? '' : 'dimmed'));
$content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'coursename')); $content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'coursename'));
// If we display course in collapsed form but the course has summary or course contacts, display the link to the info page. // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
$content .= html_writer::start_tag('div', array('class' => 'moreinfo')); $content .= html_writer::start_tag('div', array('class' => 'moreinfo'));
if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()) { if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()) {
$url = new moodle_url('/course/info.php', array('id' => $course->id)); $url = new moodle_url('/course/info.php', array('id' => $course->id));
$image = html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/info'), $image = html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/info'),
'alt' => $this->strings->summary)); 'alt' => $this->strings->summary));
$content .= html_writer::link($url, $image, array('title' => $this->strings->summary)); $content .= html_writer::link($url, $image, array('title' => $this->strings->summary));
// Make sure JS file to expand course content is included. // Make sure JS file to expand course content is included.
$this->coursecat_include_js(); $this->coursecat_include_js();
} }
} }
$content .= html_writer::end_tag('div'); // .moreinfo $content .= html_writer::end_tag('div'); // .moreinfo
// print enrolmenticons // print enrolmenticons
if ($icons = enrol_get_course_info_icons($course)) { if ($icons = enrol_get_course_info_icons($course)) {
$content .= html_writer::start_tag('div', array('class' => 'enrolmenticons')); $content .= html_writer::start_tag('div', array('class' => 'enrolmenticons'));
foreach ($icons as $pix_icon) { foreach ($icons as $pix_icon) {
$content .= $this->render($pix_icon); $content .= $this->render($pix_icon);
} }
$content .= html_writer::end_tag('div'); // .enrolmenticons $content .= html_writer::end_tag('div'); // .enrolmenticons
} }
$content .= html_writer::end_tag('div'); // .info $content .= html_writer::end_tag('div'); // .info
$content .= html_writer::start_tag('div', array('class' => 'content')); $content .= html_writer::start_tag('div', array('class' => 'content'));
$content .= $this->coursecat_coursebox_content($chelper, $course); $content .= $this->coursecat_coursebox_content($chelper, $course);
$content .= html_writer::end_tag('div'); // .content $content .= html_writer::end_tag('div'); // .content
$content .= html_writer::end_tag('div'); // .coursebox $content .= html_writer::end_tag('div'); // .coursebox
return $content; return $content;
} }
/** /**
* Returns HTML to display course content (summary, course contacts and optionally category name) * Returns HTML to display course content (summary, course contacts and optionally category name)
* *
* This method is called from coursecat_coursebox() and may be re-used in AJAX * This method is called from coursecat_coursebox() and may be re-used in AJAX
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param stdClass|course_in_list $course * @param stdClass|course_in_list $course
* @return string * @return string
*/ */
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) { protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
global $CFG; global $CFG;
if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
return ''; return '';
} }
if ($course instanceof stdClass) { if ($course instanceof stdClass) {
require_once($CFG->libdir. '/coursecatlib.php'); require_once($CFG->libdir. '/coursecatlib.php');
$course = new course_in_list($course); $course = new course_in_list($course);
} }
$content = ''; $content = '';
// display course summary // display course summary
if ($course->has_summary()) { if ($course->has_summary()) {
$content .= html_writer::start_tag('div', array('class' => 'summary')); $content .= html_writer::start_tag('div', array('class' => 'summary'));
$content .= $chelper->get_course_formatted_summary($course, $content .= $chelper->get_course_formatted_summary($course,
array('overflowdiv' => true, 'noclean' => true, 'para' => false)); array('overflowdiv' => true, 'noclean' => true, 'para' => false));
$content .= html_writer::end_tag('div'); // .summary $content .= html_writer::end_tag('div'); // .summary
} }
// display course overview files // display course overview files
$contentimages = $contentfiles = ''; $contentimages = $contentfiles = '';
foreach ($course->get_course_overviewfiles() as $file) { foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image(); $isimage = $file->is_valid_image();
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", $url = file_encode_url("$CFG->wwwroot/pluginfile.php",
'/'. $file->get_contextid(). '/'. $file->get_component(). '/'. '/'. $file->get_contextid(). '/'. $file->get_component(). '/'.
$file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage); $file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage);
if ($isimage) { if ($isimage) {
$contentimages .= html_writer::tag('div', $contentimages .= html_writer::tag('div',
html_writer::empty_tag('img', array('src' => $url)), html_writer::empty_tag('img', array('src' => $url)),
array('class' => 'courseimage')); array('class' => 'courseimage'));
} else { } else {
$image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle'); $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
$filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename')); html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
$contentfiles .= html_writer::tag('span', $contentfiles .= html_writer::tag('span',
html_writer::link($url, $filename), html_writer::link($url, $filename),
array('class' => 'coursefile fp-filename-icon')); array('class' => 'coursefile fp-filename-icon'));
} }
} }
$content .= $contentimages. $contentfiles; $content .= $contentimages. $contentfiles;
// display course contacts. See course_in_list::get_course_contacts() // display course contacts. See course_in_list::get_course_contacts()
if ($course->has_course_contacts()) { if ($course->has_course_contacts()) {
$content .= html_writer::start_tag('ul', array('class' => 'teachers')); $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
foreach ($course->get_course_contacts() as $userid => $coursecontact) { foreach ($course->get_course_contacts() as $userid => $coursecontact) {
$name = $coursecontact['rolename'].': '. $name = $coursecontact['rolename'].': '.
html_writer::link(new moodle_url('/user/view.php', html_writer::link(new moodle_url('/user/view.php',
array('id' => $userid, 'course' => SITEID)), array('id' => $userid, 'course' => SITEID)),
$coursecontact['username']); $coursecontact['username']);
$content .= html_writer::tag('li', $name); $content .= html_writer::tag('li', $name);
} }
$content .= html_writer::end_tag('ul'); // .teachers $content .= html_writer::end_tag('ul'); // .teachers
} }
// display course category if necessary (for example in search results) // display course category if necessary (for example in search results)
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) { if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
require_once($CFG->libdir. '/coursecatlib.php'); require_once($CFG->libdir. '/coursecatlib.php');
if ($cat = coursecat::get($course->category, IGNORE_MISSING)) { if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
$content .= html_writer::start_tag('div', array('class' => 'coursecat')); $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
$content .= get_string('category').': '. $content .= get_string('category').': '.
html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
$cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed')); $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
$content .= html_writer::end_tag('div'); // .coursecat $content .= html_writer::end_tag('div'); // .coursecat
} }
} }
return $content; return $content;
} }
/** /**
* Renders the list of courses * Renders the list of courses
* *
* This is internal function, please use {@link core_course_renderer::courses_list()} or another public * This is internal function, please use {@link core_course_renderer::courses_list()} or another public
* method from outside of the class * method from outside of the class
* *
* If list of courses is specified in $courses; the argument $chelper is only used * If list of courses is specified in $courses; the argument $chelper is only used
* to retrieve display options and attributes, only methods get_show_courses(), * to retrieve display options and attributes, only methods get_show_courses(),
* get_courses_display_option() and get_and_erase_attributes() are called. * get_courses_display_option() and get_and_erase_attributes() are called.
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param array $courses the list of courses to display * @param array $courses the list of courses to display
* @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable), * @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable),
* defaulted to count($courses) * defaulted to count($courses)
* @return string * @return string
*/ */
protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) { protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
global $CFG; global $CFG;
if ($totalcount === null) { if ($totalcount === null) {
$totalcount = count($courses); $totalcount = count($courses);
} }
if (!$totalcount) { if (!$totalcount) {
// Courses count is cached during courses retrieval. // Courses count is cached during courses retrieval.
return ''; return '';
} }
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) { if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) {
// In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit
if ($totalcount <= $CFG->courseswithsummarieslimit) { if ($totalcount <= $CFG->courseswithsummarieslimit) {
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
} else { } else {
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
} }
} }
// prepare content of paging bar if it is needed // prepare content of paging bar if it is needed
$paginationurl = $chelper->get_courses_display_option('paginationurl'); $paginationurl = $chelper->get_courses_display_option('paginationurl');
$paginationallowall = $chelper->get_courses_display_option('paginationallowall'); $paginationallowall = $chelper->get_courses_display_option('paginationallowall');
if ($totalcount > count($courses)) { if ($totalcount > count($courses)) {
// there are more results that can fit on one page // there are more results that can fit on one page
if ($paginationurl) { if ($paginationurl) {
// the option paginationurl was specified, display pagingbar // the option paginationurl was specified, display pagingbar
$perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage); $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage);
$page = $chelper->get_courses_display_option('offset') / $perpage; $page = $chelper->get_courses_display_option('offset') / $perpage;
$pagingbar = $this->paging_bar($totalcount, $page, $perpage, $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
$paginationurl->out(false, array('perpage' => $perpage))); $paginationurl->out(false, array('perpage' => $perpage)));
if ($paginationallowall) { if ($paginationallowall) {
$pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')), $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall')); get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
} }
} else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) { } else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
// the option for 'View more' link was specified, display more link // the option for 'View more' link was specified, display more link
$viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore')); $viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore'));
$morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext), $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext),
array('class' => 'paging paging-morelink')); array('class' => 'paging paging-morelink'));
} }
} else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) { } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
// there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
$pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)), $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage')); get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
} }
// display list of courses // display list of courses
$attributes = $chelper->get_and_erase_attributes('courses'); $attributes = $chelper->get_and_erase_attributes('courses');
$content = html_writer::start_tag('div', $attributes); $content = html_writer::start_tag('div', $attributes);
if (!empty($pagingbar)) { if (!empty($pagingbar)) {
$content .= $pagingbar; $content .= $pagingbar;
} }
$coursecount = 0; $coursecount = 0;
foreach ($courses as $course) { foreach ($courses as $course) {
$coursecount ++; $coursecount ++;
$classes = ($coursecount%2) ? 'odd' : 'even'; $classes = ($coursecount%2) ? 'odd' : 'even';
if ($coursecount == 1) { if ($coursecount == 1) {
$classes .= ' first'; $classes .= ' first';
} }
if ($coursecount >= count($courses)) { if ($coursecount >= count($courses)) {
$classes .= ' last'; $classes .= ' last';
} }
$content .= $this->coursecat_coursebox($chelper, $course, $classes); $content .= $this->coursecat_coursebox($chelper, $course, $classes);
} }
if (!empty($pagingbar)) { if (!empty($pagingbar)) {
$content .= $pagingbar; $content .= $pagingbar;
} }
if (!empty($morelink)) { if (!empty($morelink)) {
$content .= $morelink; $content .= $morelink;
} }
$content .= html_writer::end_tag('div'); // .courses $content .= html_writer::end_tag('div'); // .courses
return $content; return $content;
} }
/** /**
* Renders the list of subcategories in a category * Renders the list of subcategories in a category
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param coursecat $coursecat * @param coursecat $coursecat
* @param int $depth depth of the category in the current tree * @param int $depth depth of the category in the current tree
* @return string * @return string
*/ */
protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) { protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) {
global $CFG; global $CFG;
$subcategories = array(); $subcategories = array();
if (!$chelper->get_categories_display_option('nodisplay')) { if (!$chelper->get_categories_display_option('nodisplay')) {
$subcategories = $coursecat->get_children($chelper->get_categories_display_options()); $subcategories = $coursecat->get_children($chelper->get_categories_display_options());
} }
$totalcount = $coursecat->get_children_count(); $totalcount = $coursecat->get_children_count();
if (!$totalcount) { if (!$totalcount) {
// Note that we call coursecat::get_children_count() AFTER coursecat::get_children() to avoid extra DB requests. // Note that we call coursecat::get_children_count() AFTER coursecat::get_children() to avoid extra DB requests.
// Categories count is cached during children categories retrieval. // Categories count is cached during children categories retrieval.
return ''; return '';
} }
// prepare content of paging bar or more link if it is needed // prepare content of paging bar or more link if it is needed
$paginationurl = $chelper->get_categories_display_option('paginationurl'); $paginationurl = $chelper->get_categories_display_option('paginationurl');
$paginationallowall = $chelper->get_categories_display_option('paginationallowall'); $paginationallowall = $chelper->get_categories_display_option('paginationallowall');
if ($totalcount > count($subcategories)) { if ($totalcount > count($subcategories)) {
if ($paginationurl) { if ($paginationurl) {
// the option 'paginationurl was specified, display pagingbar // the option 'paginationurl was specified, display pagingbar
$perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage); $perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage);
$page = $chelper->get_categories_display_option('offset') / $perpage; $page = $chelper->get_categories_display_option('offset') / $perpage;
$pagingbar = $this->paging_bar($totalcount, $page, $perpage, $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
$paginationurl->out(false, array('perpage' => $perpage))); $paginationurl->out(false, array('perpage' => $perpage)));
if ($paginationallowall) { if ($paginationallowall) {
$pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')), $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall')); get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
} }
} else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) { } else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) {
// the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id) // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id)
if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) { if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
$viewmoreurl->param('categoryid', $coursecat->id); $viewmoreurl->param('categoryid', $coursecat->id);
} }
$viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore')); $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore'));
$morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext), $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext),
array('class' => 'paging paging-morelink')); array('class' => 'paging paging-morelink'));
} }
} else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) { } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
// there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
$pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)), $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage')); get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
} }
// display list of subcategories // display list of subcategories
$content = html_writer::start_tag('div', array('class' => 'subcategories')); $content = html_writer::start_tag('div', array('class' => 'subcategories'));
if (!empty($pagingbar)) { if (!empty($pagingbar)) {
$content .= $pagingbar; $content .= $pagingbar;
} }
foreach ($subcategories as $subcategory) { foreach ($subcategories as $subcategory) {
$content .= $this->coursecat_category($chelper, $subcategory, $depth + 1); $content .= $this->coursecat_category($chelper, $subcategory, $depth + 1);
} }
if (!empty($pagingbar)) { if (!empty($pagingbar)) {
$content .= $pagingbar; $content .= $pagingbar;
} }
if (!empty($morelink)) { if (!empty($morelink)) {
$content .= $morelink; $content .= $morelink;
} }
$content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('div');
return $content; return $content;
} }
/** /**
* Make sure that javascript file for AJAX expanding of courses and categories content is included * Make sure that javascript file for AJAX expanding of courses and categories content is included
*/ */
protected function coursecat_include_js() { protected function coursecat_include_js() {
if (!$this->page->requires->should_create_one_time_item_now('core_course_categoryexpanderjsinit')) { if (!$this->page->requires->should_create_one_time_item_now('core_course_categoryexpanderjsinit')) {
return; return;
} }
// We must only load this module once. // We must only load this module once.
$this->page->requires->yui_module('moodle-course-categoryexpander', $this->page->requires->yui_module('moodle-course-categoryexpander',
'Y.Moodle.course.categoryexpander.init'); 'Y.Moodle.course.categoryexpander.init');
} }
/** /**
* Returns HTML to display the subcategories and courses in the given category * 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 * This method is re-used by AJAX to expand content of not loaded category
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param coursecat $coursecat * @param coursecat $coursecat
* @param int $depth depth of the category in the current tree * @param int $depth depth of the category in the current tree
* @return string * @return string
*/ */
protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth) { protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth) {
$content = ''; $content = '';
// Subcategories // Subcategories
$content .= $this->coursecat_subcategories($chelper, $coursecat, $depth); $content .= $this->coursecat_subcategories($chelper, $coursecat, $depth);
// AUTO show courses: Courses will be shown expanded if this is not nested category, // AUTO show courses: Courses will be shown expanded if this is not nested category,
// and number of courses no bigger than $CFG->courseswithsummarieslimit. // and number of courses no bigger than $CFG->courseswithsummarieslimit.
$showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO; $showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO;
if ($showcoursesauto && $depth) { if ($showcoursesauto && $depth) {
// this is definitely collapsed mode // this is definitely collapsed mode
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
} }
// Courses // Courses
if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) { if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) {
$courses = array(); $courses = array();
if (!$chelper->get_courses_display_option('nodisplay')) { if (!$chelper->get_courses_display_option('nodisplay')) {
$courses = $coursecat->get_courses($chelper->get_courses_display_options()); $courses = $coursecat->get_courses($chelper->get_courses_display_options());
} }
if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) { 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) // 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('/course/index.php'), URL_MATCH_BASE)) { if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
$chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id))); $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id)));
} }
} }
$content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count()); $content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count());
} }
if ($showcoursesauto) { if ($showcoursesauto) {
// restore the show_courses back to AUTO // restore the show_courses back to AUTO
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO);
} }
return $content; return $content;
} }
/** /**
* Returns HTML to display a course category as a part of a tree * 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 * This is an internal function, to display a particular category and all its contents
* use {@link core_course_renderer::course_category()} * use {@link core_course_renderer::course_category()}
* *
* @param coursecat_helper $chelper various display options * @param coursecat_helper $chelper various display options
* @param coursecat $coursecat * @param coursecat $coursecat
* @param int $depth depth of this category in the current tree * @param int $depth depth of this category in the current tree
* @return string * @return string
*/ */
protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) { protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {
// open category tag // open category tag
$classes = array('category'); $classes = array('category');
if (empty($coursecat->visible)) { if (empty($coursecat->visible)) {