示例#1
0
/**
 * Include the relevant javascript and language strings for the resource
 * toolbox YUI module
 *
 * @param integer $id The ID of the course being applied to
 * @param array $usedmodules An array containing the names of the modules in use on the page
 * @param array $enabledmodules An array containing the names of the enabled (visible) modules on this site
 * @param stdClass $config An object containing configuration parameters for ajax modules including:
 *          * resourceurl   The URL to post changes to for resource changes
 *          * sectionurl    The URL to post changes to for section changes
 *          * pageparams    Additional parameters to pass through in the post
 * @return bool
 */
function include_course_ajax($course, $usedmodules = array(), $enabledmodules = null, $config = null)
{
    global $CFG, $PAGE, $SITE;
    // Ensure that ajax should be included
    if (!course_ajax_enabled($course)) {
        return false;
    }
    if (!$config) {
        $config = new stdClass();
    }
    // The URL to use for resource changes
    if (!isset($config->resourceurl)) {
        $config->resourceurl = '/course/rest.php';
    }
    // The URL to use for section changes
    if (!isset($config->sectionurl)) {
        $config->sectionurl = '/course/rest.php';
    }
    // Any additional parameters which need to be included on page submission
    if (!isset($config->pageparams)) {
        $config->pageparams = array();
    }
    // Include toolboxes
    $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_resource_toolbox', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config)));
    $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_section_toolbox', array(array('courseid' => $course->id, 'format' => $course->format, 'ajaxurl' => $config->sectionurl, 'config' => $config)));
    // Include course dragdrop
    if (course_format_uses_sections($course->format)) {
        $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.course.init_section_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->sectionurl, 'config' => $config)), null, true);
        $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.course.init_resource_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config)), null, true);
    }
    // Require various strings for the command toolbox
    $PAGE->requires->strings_for_js(array('moveleft', 'deletechecktype', 'deletechecktypename', 'edittitle', 'edittitleinstructions', 'show', 'hide', 'groupsnone', 'groupsvisible', 'groupsseparate', 'clicktochangeinbrackets', 'markthistopic', 'markedthistopic', 'movesection', 'movecoursemodule', 'movecoursesection', 'movecontent', 'tocontent', 'emptydragdropregion', 'afterresource', 'aftersection', 'totopofsection'), 'moodle');
    // Include section-specific strings for formats which support sections.
    if (course_format_uses_sections($course->format)) {
        $PAGE->requires->strings_for_js(array('showfromothers', 'hidefromothers'), 'format_' . $course->format);
    }
    // For confirming resource deletion we need the name of the module in question
    foreach ($usedmodules as $module => $modname) {
        $PAGE->requires->string_for_js('pluginname', $module);
    }
    // Load drag and drop upload AJAX.
    require_once $CFG->dirroot . '/course/dnduploadlib.php';
    dndupload_add_to_course($course, $enabledmodules);
    return true;
}
示例#2
0
文件: lib.php 项目: nmicha/moodle
/**
 * Include the relevant javascript and language strings for the resource
 * toolbox YUI module
 *
 * @param integer $id The ID of the course being applied to
 * @param array $usedmodules An array containing the names of the modules in use on the page
 * @param array $enabledmodules An array containing the names of the enabled (visible) modules on this site
 * @param stdClass $config An object containing configuration parameters for ajax modules including:
 *          * resourceurl   The URL to post changes to for resource changes
 *          * sectionurl    The URL to post changes to for section changes
 *          * pageparams    Additional parameters to pass through in the post
 * @return bool
 */
function include_course_ajax($course, $usedmodules = array(), $enabledmodules = null, $config = null)
{
    global $PAGE, $SITE;
    // Ensure that ajax should be included
    if (!course_ajax_enabled($course)) {
        return false;
    }
    if (!$config) {
        $config = new stdClass();
    }
    // The URL to use for resource changes
    if (!isset($config->resourceurl)) {
        $config->resourceurl = '/course/rest.php';
    }
    // The URL to use for section changes
    if (!isset($config->sectionurl)) {
        $config->sectionurl = '/course/rest.php';
    }
    // Any additional parameters which need to be included on page submission
    if (!isset($config->pageparams)) {
        $config->pageparams = array();
    }
    // Include toolboxes
    $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_resource_toolbox', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config)));
    $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_section_toolbox', array(array('courseid' => $course->id, 'format' => $course->format, 'ajaxurl' => $config->sectionurl, 'config' => $config)));
    // Include course dragdrop
    if ($course->id != $SITE->id) {
        $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.course.init_section_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->sectionurl, 'config' => $config)), null, true);
        $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.course.init_resource_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config)), null, true);
    }
    // Include blocks dragdrop
    $params = array('courseid' => $course->id, 'pagetype' => $PAGE->pagetype, 'pagelayout' => $PAGE->pagelayout, 'regions' => $PAGE->blocks->get_regions());
    $PAGE->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
    // Require various strings for the command toolbox
    $PAGE->requires->strings_for_js(array('moveleft', 'deletechecktype', 'deletechecktypename', 'edittitle', 'edittitleinstructions', 'show', 'hide', 'groupsnone', 'groupsvisible', 'groupsseparate', 'clicktochangeinbrackets', 'markthistopic', 'markedthistopic', 'move', 'movesection'), 'moodle');
    // Include format-specific strings
    if ($course->id != $SITE->id) {
        $PAGE->requires->strings_for_js(array('showfromothers', 'hidefromothers'), 'format_' . $course->format);
    }
    // For confirming resource deletion we need the name of the module in question
    foreach ($usedmodules as $module => $modname) {
        $PAGE->requires->string_for_js('pluginname', $module);
    }
    // Load drag and drop upload AJAX.
    dndupload_add_to_course($course, $enabledmodules);
    // Add the module chooser
    $PAGE->requires->yui_module('moodle-course-modchooser', 'M.course.init_chooser', array(array('courseid' => $course->id)));
    $PAGE->requires->strings_for_js(array('addresourceoractivity', 'modchooserenable', 'modchooserdisable'), 'moodle');
    return true;
}