Untitled diff

Created Diff never expires
ORIGINAL FILE
MODIFIED FILE
<?php
<?php


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


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


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


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


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


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


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


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


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


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