function link_to_gdoc($name, $link, $type = null, $modtype = 'url')
{
    global $COURSE, $DB, $CFG, $USER;
    require_once "{$CFG->dirroot}/mod/{$modtype}/lib.php";
    //add
    $fromform = new stdClass();
    $newform = new stdClass();
    $mform = new MoodleQuickForm(null, 'POST', 'nothing');
    $module = $DB->get_record("modules", array('name' => $modtype));
    $course = $COURSE;
    $cw = get_course_section(0, $course->id);
    $cm = null;
    // fields for mdl_url
    $fromform->course = $course->id;
    $fromform->name = $name;
    $fromform->introformat = 0;
    $fromform->introeditor = 0;
    $fromform->externalurl = $link;
    /*    if ($type !== 'dir') {
            $fromform->display          = 6;
            $fromform->displayoptions = 'a:2:{s:10:"popupwidth";i:1024;s:11:"popupheight";i:768;}';
        } else {
    */
    $fromform->display = 0;
    $fromform->popupwidth = 1024;
    $fromform->popupheight = 768;
    $fromform->popupwidth = null;
    $fromform->popupheight = null;
    $fromform->displayoptions = 'a:1:{s:10:"printintro";i:0;}';
    //    }
    // fields for mdl_course_module
    $fromform->module = $module->id;
    $fromform->instance = '';
    $fromform->section = 0;
    // The section number itself - relative!!! (section column in course_sections)
    $fromform->idnumber = null;
    $fromform->score = 0;
    $fromform->indent = 0;
    $fromform->visible = 1;
    $fromform->visibleold = 1;
    $fromform->groupmode = $course->groupmode;
    $fromform->groupingid = 0;
    $fromform->groupmembersonly = 0;
    $fromform->completion = 0;
    $fromform->completionview = 0;
    $fromform->completionexpected = 0;
    $fromform->availablefrom = 0;
    $fromform->availableuntil = 0;
    $fromform->showavailability = 0;
    $fromform->showdescription = 0;
    $fromform->conditiongradegroup = array();
    $fromform->conditionfieldgroup = array();
    // fields for mdl_course_sections
    $fromform->summaryformat = 0;
    $fromform->modulename = clean_param($module->name, PARAM_SAFEDIR);
    // For safety
    //	$fromform->add              = 'resource';
    //	$fromform->type             = $type == 'dir' ? 'collection' : 'file';
    //	$fromform->return           = 0; //must be false if this is an add, go back to course view on cancel
    //    $fromform->coursemodule 	= '';
    //	$fromform->popup			= 'resizable=1,scrollbars=1,directories=1,location=1,menubar=1,toolbar=1,status=1,width=1024,height=768';
    //	require_login($course->id); // needed to setup proper $COURSE
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('moodle/course:manageactivities', $context);
    if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
        $fromform->groupmode = 0;
        // do not set groupmode
    }
    if (!course_allowed_module($course, $fromform->modulename)) {
        print_error('moduledisable', '', '', $fromform->modulename);
    }
    // first add course_module record because we need the context
    $newcm = new stdClass();
    $newcm->course = $course->id;
    $newcm->module = $fromform->module;
    $newcm->instance = 0;
    // not known yet, will be updated later (this is similar to restore code)
    $newcm->visible = $fromform->visible;
    $newcm->groupmode = $fromform->groupmode;
    $newcm->groupingid = $fromform->groupingid;
    $newcm->groupmembersonly = $fromform->groupmembersonly;
    $completion = new completion_info($course);
    if ($completion->is_enabled()) {
        $newcm->completion = $fromform->completion;
        $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
        $newcm->completionview = $fromform->completionview;
        $newcm->completionexpected = $fromform->completionexpected;
    }
    if (!empty($CFG->enableavailability)) {
        $newcm->availablefrom = $fromform->availablefrom;
        $newcm->availableuntil = $fromform->availableuntil;
        $newcm->showavailability = $fromform->showavailability;
    }
    if (isset($fromform->showdescription)) {
        $newcm->showdescription = $fromform->showdescription;
    } else {
        $newcm->showdescription = 0;
    }
    if (!($fromform->coursemodule = add_course_module($newcm))) {
        print_error('cannotaddcoursemodule');
    }
    if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
        $draftid_editor = file_get_submitted_draft_itemid('introeditor');
        file_prepare_draft_area($draftid_editor, null, null, null, null);
        $fromform->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
        // TODO: add better default
    }
    if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
        $introeditor = $fromform->introeditor;
        unset($fromform->introeditor);
        $fromform->intro = $introeditor['text'];
        $fromform->introformat = $introeditor['format'];
    }
    $addinstancefunction = $fromform->modulename . "_add_instance";
    $updateinstancefunction = $fromform->modulename . "_update_instance";
    $returnfromfunc = $addinstancefunction($fromform, $mform);
    //	$returnfromfunc = url_add_instance($fromform, $mform);
    if (!$returnfromfunc or !is_number($returnfromfunc)) {
        // undo everything we can
        $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
        delete_context(CONTEXT_MODULE, $fromform->coursemodule);
        $DB->delete_records('course_modules', array('id' => $fromform->coursemodule));
        if (!is_number($returnfromfunc)) {
            print_error('invalidfunction', '', course_get_url($course, $cw->section));
        } else {
            print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
        }
    }
    $fromform->instance = $returnfromfunc;
    $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $fromform->coursemodule));
    // update embedded links and save files
    $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
    if (!empty($introeditor)) {
        $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $fromform->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
        $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id' => $fromform->instance));
    }
    // course_modules and course_sections each contain a reference
    // to each other, so we have to update one of them twice.
    $sectionid = add_mod_to_section($fromform);
    $DB->set_field('course_modules', 'section', $sectionid, array('id' => $fromform->coursemodule));
    // make sure visibility is set correctly (in particular in calendar)
    set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
    if (isset($fromform->cmidnumber)) {
        //label
        // set cm idnumber
        set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
    }
    // Set up conditions
    if ($CFG->enableavailability) {
        condition_info::update_cm_from_form((object) array('id' => $fromform->coursemodule), $fromform, false);
    }
    $eventname = 'mod_created';
    add_to_log($course->id, "course", "add mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}");
    add_to_log($course->id, $fromform->modulename, "add", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule);
    // Trigger mod_created/mod_updated event with information about this module.
    $eventdata = new stdClass();
    $eventdata->modulename = $fromform->modulename;
    $eventdata->name = $fromform->name;
    $eventdata->cmid = $fromform->coursemodule;
    $eventdata->courseid = $course->id;
    $eventdata->userid = $USER->id;
    events_trigger($eventname, $eventdata);
    rebuild_course_cache($course->id);
    return 1;
}
Beispiel #2
0
/**
 * Retrieve all metadata for the requested modules
 *
 * @param object $course The Course
 * @param array $modnames An array containing the list of modules and their
 * names
 * @param int $sectionreturn The section to return to
 * @return array A list of stdClass objects containing metadata about each
 * module
 */
function get_module_metadata($course, $modnames, $sectionreturn = null)
{
    global $CFG, $OUTPUT;
    // get_module_metadata will be called once per section on the page and courses may show
    // different modules to one another
    static $modlist = array();
    if (!isset($modlist[$course->id])) {
        $modlist[$course->id] = array();
    }
    $return = array();
    $urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
    if ($sectionreturn !== null) {
        $urlbase->param('sr', $sectionreturn);
    }
    foreach ($modnames as $modname => $modnamestr) {
        if (!course_allowed_module($course, $modname)) {
            continue;
        }
        if (isset($modlist[$course->id][$modname])) {
            // This module is already cached
            $return[$modname] = $modlist[$course->id][$modname];
            continue;
        }
        // Include the module lib
        $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
        if (!file_exists($libfile)) {
            continue;
        }
        include_once $libfile;
        // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
        $gettypesfunc = $modname . '_get_types';
        $types = MOD_SUBTYPE_NO_CHILDREN;
        if (function_exists($gettypesfunc)) {
            $types = $gettypesfunc();
        }
        if ($types !== MOD_SUBTYPE_NO_CHILDREN) {
            if (is_array($types) && count($types) > 0) {
                $group = new stdClass();
                $group->name = $modname;
                $group->icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
                foreach ($types as $type) {
                    if ($type->typestr === '--') {
                        continue;
                    }
                    if (strpos($type->typestr, '--') === 0) {
                        $group->title = str_replace('--', '', $type->typestr);
                        continue;
                    }
                    // Set the Sub Type metadata
                    $subtype = new stdClass();
                    $subtype->title = $type->typestr;
                    $subtype->type = str_replace('&', '&', $type->type);
                    $subtype->name = preg_replace('/.*type=/', '', $subtype->type);
                    $subtype->archetype = $type->modclass;
                    // The group archetype should match the subtype archetypes and all subtypes
                    // should have the same archetype
                    $group->archetype = $subtype->archetype;
                    if (!empty($type->help)) {
                        $subtype->help = $type->help;
                    } else {
                        if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
                            $subtype->help = get_string('help' . $subtype->name, $modname);
                        }
                    }
                    $subtype->link = new moodle_url($urlbase, array('add' => $modname, 'type' => $subtype->name));
                    $group->types[] = $subtype;
                }
                $modlist[$course->id][$modname] = $group;
            }
        } else {
            $module = new stdClass();
            $module->title = $modnamestr;
            $module->name = $modname;
            $module->link = new moodle_url($urlbase, array('add' => $modname));
            $module->icon = $OUTPUT->pix_icon('icon', '', $module->name, array('class' => 'icon'));
            $sm = get_string_manager();
            if ($sm->string_exists('modulename_help', $modname)) {
                $module->help = get_string('modulename_help', $modname);
                if ($sm->string_exists('modulename_link', $modname)) {
                    // Link to further info in Moodle docs
                    $link = get_string('modulename_link', $modname);
                    $linktext = get_string('morehelp');
                    $module->help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
                }
            }
            $module->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
            $modlist[$course->id][$modname] = $module;
        }
        if (isset($modlist[$course->id][$modname])) {
            $return[$modname] = $modlist[$course->id][$modname];
        } else {
            debugging("Invalid module metadata configuration for {$modname}");
        }
    }
    return $return;
}
Beispiel #3
0
/**
 * Prints the menus to add activities and resources.
 */
function print_section_add_menus($course, $section, $modnames, $vertical = false, $return = false)
{
    global $CFG;
    // check to see if user can add menus
    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
        return false;
    }
    static $resources = false;
    static $activities = false;
    if ($resources === false) {
        $resources = array();
        $activities = array();
        foreach ($modnames as $modname => $modnamestr) {
            if (!course_allowed_module($course, $modname)) {
                continue;
            }
            $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
            if (!file_exists($libfile)) {
                continue;
            }
            include_once $libfile;
            $gettypesfunc = $modname . '_get_types';
            if (function_exists($gettypesfunc)) {
                $types = $gettypesfunc();
                foreach ($types as $type) {
                    if (!isset($type->modclass) or !isset($type->typestr)) {
                        debugging('Incorrect activity type in ' . $modname);
                        continue;
                    }
                    if ($type->modclass == MOD_CLASS_RESOURCE) {
                        $resources[$type->type] = $type->typestr;
                    } else {
                        $activities[$type->type] = $type->typestr;
                    }
                }
            } else {
                // all mods without type are considered activity
                $activities[$modname] = $modnamestr;
            }
        }
    }
    $straddactivity = get_string('addactivity');
    $straddresource = get_string('addresource');
    $output = '<div class="section_add_menus">';
    if (!$vertical) {
        $output .= '<div class="horizontal">';
    }
    if (!empty($resources)) {
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $resources, "ressection{$section}", "", $straddresource, 'resource/types', $straddresource, true);
    }
    if (!empty($activities)) {
        $output .= ' ';
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $activities, "section{$section}", "", $straddactivity, 'mods', $straddactivity, true);
    }
    if (!$vertical) {
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Beispiel #4
0
/**
 * Check that the user can add a module. Also returns some information like the module, context and course section info.
 * The fucntion create the course section if it doesn't exist.
 *
 * @param object $course the course of the module
 * @param object $modulename the module name
 * @param object $section the section of the module
 * @return array list containing module, context, course section.
 * @throws moodle_exception if user is not allowed to perform the action or module is not allowed in this course
 */
function can_add_moduleinfo($course, $modulename, $section)
{
    global $DB;
    $module = $DB->get_record('modules', array('name' => $modulename), '*', MUST_EXIST);
    $context = context_course::instance($course->id);
    require_capability('moodle/course:manageactivities', $context);
    course_create_sections_if_missing($course, $section);
    $cw = get_fast_modinfo($course)->get_section_info($section);
    if (!course_allowed_module($course, $module->name)) {
        print_error('moduledisable');
    }
    return array($module, $context, $cw);
}
Beispiel #5
0
             }
             break;
     }
     break;
 case 'resource':
     switch ($field) {
         case 'visible':
             require_capability('moodle/course:activityvisibility', $modcontext);
             set_coursemodule_visible($cm->id, $value);
             \core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
             break;
         case 'duplicate':
             require_capability('moodle/course:manageactivities', $modcontext);
             require_capability('moodle/backup:backuptargetimport', $modcontext);
             require_capability('moodle/restore:restoretargetimport', $modcontext);
             if (!course_allowed_module($course, $cm->modname)) {
                 throw new moodle_exception('No permission to create that activity');
             }
             $sr = optional_param('sr', null, PARAM_INT);
             $result = mod_duplicate_activity($course, $cm, $sr);
             echo json_encode($result);
             break;
         case 'groupmode':
             require_capability('moodle/course:manageactivities', $modcontext);
             set_coursemodule_groupmode($cm->id, $value);
             \core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
             break;
         case 'indent':
             require_capability('moodle/course:manageactivities', $modcontext);
             $cm->indent = $value;
             if ($cm->indent >= 0) {
Beispiel #6
0
/**
 * Prints the menus to add activities and resources.
 */
function print_section_add_menus($course, $section, $modnames, $vertical = false, $return = false)
{
    global $USER, $CFG;
    // check to see if user can add menus
    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
        return false;
    }
    // TODO predelat na nejakou rozumejsi konfiguraci
    $samouk_res = array("resource&amp;type=text", "resource&amp;type=textandvideo", "resource&amp;type=file", "quiz", "workshop");
    $samouk_act = array('resource&amp;type=html', 'assignment&amp;type=upload', 'label', 'resource&amp;type=directory', 'dimdim');
    $samouk_hw = array('assignment&amp;type=upload', 'assignment&amp;type=online', 'assignment&amp;type=uploadsingle', 'assignment&amp;type=offline');
    static $resources = false;
    static $activities = false;
    static $homeworks = false;
    if ($resources === false) {
        $resources = array();
        $activities = array();
        $homeworks = array();
        foreach ($modnames as $modname => $modnamestr) {
            if (!course_allowed_module($course, $modname)) {
                continue;
            }
            require_once "{$CFG->dirroot}/mod/{$modname}/lib.php";
            $gettypesfunc = $modname . '_get_types';
            // assign activities to different popups....
            if (function_exists($gettypesfunc)) {
                // ...by type if exist
                $types = $gettypesfunc();
                foreach ($types as $type) {
                    // kowy - put type to proper dropdown box
                    if (in_array($type->type, $samouk_res)) {
                        $resources[$type->type] = $type->typestr;
                    } else {
                        if (in_array($type->type, $samouk_act)) {
                            $activities[$type->type] = $type->typestr;
                        } else {
                            if (in_array($type->type, $samouk_hw)) {
                                $homeworks[$type->type] = $type->typestr;
                            }
                        }
                    }
                }
            } else {
                // ...or by name
                if (in_array($modname, $samouk_res)) {
                    $resources[$modname] = $modnamestr;
                } else {
                    if (in_array($modname, $samouk_act)) {
                        $activities[$modname] = $modnamestr;
                    } else {
                        if (in_array($modname, $samouk_hw)) {
                            $homeworks[$modname] = $modnamestr;
                        }
                    }
                }
            }
        }
    }
    $straddactivity = get_string('addactivity');
    $straddresource = get_string('addresource');
    $straddhomework = get_string('modulenameplural', 'assignment');
    $output = '<div class="section_add_menus">';
    if (!$vertical) {
        $output .= '<div class="horizontal">';
    }
    if (!empty($resources)) {
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $resources, "ressection{$section}", "", $straddresource, 'resource/types', $straddresource, true);
    }
    if (!empty($activities) && $USER->su_isadvanced) {
        $output .= ' ';
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $activities, "section{$section}", "", $straddactivity, 'mods', $straddactivity, true);
    }
    if (!empty($homeworks) && $USER->su_isadvanced) {
        $output .= ' ';
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $homeworks, "hwsection{$section}", "", $straddhomework, 'mods', $straddhomework, true);
    }
    if (!$vertical) {
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
/**
 * Add course module.
 *
 * The function does not check user capabilities.
 * The function creates course module, module instance, add the module to the correct section.
 * It also trigger common action that need to be done after adding/updating a module.
 *
 * @param object $moduleinfo the moudle data
 * @param object $course the course of the module
 * @param object $mform this is required by an existing hack to deal with files during MODULENAME_add_instance()
 * @return object the updated module info
 */
function local_ltiprovider_add_moduleinfo($moduleinfo, $course, $mform = null)
{
    global $DB, $CFG;
    $moduleinfo->course = $course->id;
    $moduleinfo = local_ltiprovider_set_moduleinfo_defaults($moduleinfo);
    if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
        $moduleinfo->groupmode = 0;
        // Do not set groupmode.
    }
    if (!course_allowed_module($course, $moduleinfo->modulename)) {
        print_error('moduledisable', '', '', $moduleinfo->modulename);
    }
    // First add course_module record because we need the context.
    $newcm = new stdClass();
    $newcm->course = $course->id;
    $newcm->module = $moduleinfo->module;
    $newcm->instance = 0;
    // Not known yet, will be updated later (this is similar to restore code).
    $newcm->visible = $moduleinfo->visible;
    $newcm->visibleold = $moduleinfo->visible;
    $newcm->groupmode = $moduleinfo->groupmode;
    $newcm->groupingid = $moduleinfo->groupingid;
    $newcm->groupmembersonly = $moduleinfo->groupmembersonly;
    $completion = new completion_info($course);
    if ($completion->is_enabled()) {
        $newcm->completion = $moduleinfo->completion;
        $newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
        $newcm->completionview = $moduleinfo->completionview;
        $newcm->completionexpected = $moduleinfo->completionexpected;
    }
    if (!empty($CFG->enableavailability)) {
        $newcm->availablefrom = $moduleinfo->availablefrom;
        $newcm->availableuntil = $moduleinfo->availableuntil;
        $newcm->showavailability = $moduleinfo->showavailability;
    }
    if (isset($moduleinfo->showdescription)) {
        $newcm->showdescription = $moduleinfo->showdescription;
    } else {
        $newcm->showdescription = 0;
    }
    if (!($moduleinfo->coursemodule = add_course_module($newcm))) {
        print_error('cannotaddcoursemodule');
    }
    if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) {
        $introeditor = $moduleinfo->introeditor;
        unset($moduleinfo->introeditor);
        $moduleinfo->intro = $introeditor['text'];
        $moduleinfo->introformat = $introeditor['format'];
    }
    $addinstancefunction = $moduleinfo->modulename . "_add_instance";
    $returnfromfunc = $addinstancefunction($moduleinfo, $mform);
    if (!$returnfromfunc or !is_number($returnfromfunc)) {
        // Undo everything we can.
        $modcontext = context_module::instance($moduleinfo->coursemodule);
        delete_context(CONTEXT_MODULE, $moduleinfo->coursemodule);
        $DB->delete_records('course_modules', array('id' => $moduleinfo->coursemodule));
        if (!is_number($returnfromfunc)) {
            print_error('invalidfunction', '', course_get_url($course, $cw->section));
        } else {
            print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $moduleinfo->modulename);
        }
    }
    $moduleinfo->instance = $returnfromfunc;
    $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $moduleinfo->coursemodule));
    // Update embedded links and save files.
    $modcontext = context_module::instance($moduleinfo->coursemodule);
    if (!empty($introeditor)) {
        $moduleinfo->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $moduleinfo->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
        $DB->set_field($moduleinfo->modulename, 'intro', $moduleinfo->intro, array('id' => $moduleinfo->instance));
    }
    // Course_modules and course_sections each contain a reference to each other.
    // So we have to update one of them twice.
    $sectionid = course_add_cm_to_section($course, $moduleinfo->coursemodule, $moduleinfo->section);
    // Make sure visibility is set correctly (in particular in calendar).
    // Note: allow them to set it even without moodle/course:activityvisibility.
    set_coursemodule_visible($moduleinfo->coursemodule, $moduleinfo->visible);
    if (isset($moduleinfo->cmidnumber)) {
        // Label.
        // Set cm idnumber - uniqueness is already verified by form validation.
        set_coursemodule_idnumber($moduleinfo->coursemodule, $moduleinfo->cmidnumber);
    }
    // Set up conditions.
    if ($CFG->enableavailability) {
        condition_info::update_cm_from_form((object) array('id' => $moduleinfo->coursemodule), $moduleinfo, false);
    }
    $eventname = 'mod_created';
    add_to_log($course->id, "course", "add mod", "../mod/{$moduleinfo->modulename}/view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->modulename} {$moduleinfo->instance}");
    add_to_log($course->id, $moduleinfo->modulename, "add", "view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->instance}", $moduleinfo->coursemodule);
    $moduleinfo = local_ltiprovider_edit_module_post_actions($moduleinfo, $course, 'mod_created');
    return $moduleinfo;
}
Beispiel #8
0
 /**
  * Checks if the current user can add the activity of the specified type to this course.
  *
  * @return bool
  */
 protected function can_add_activity()
 {
     global $CFG;
     if (!($modname = $this->get_activitytype())) {
         return false;
     }
     if (!has_capability('moodle/course:manageactivities', context_course::instance($this->courseid))) {
         return false;
     }
     if (!course_allowed_module($this->get_course(), $modname)) {
         return false;
     }
     $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
     if (!file_exists($libfile)) {
         return null;
     }
     return true;
 }
function RWSCMUCourse($r_cid, $r_cqa = false)
{
    global $DB;
    global $CFG;
    global $RWSUID;
    $r_rcd = $DB->get_record("course", array("id" => $r_cid));
    if ($r_rcd === false) {
        RWSSErr("2011");
    }
    if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
        $r_ctx = context_course::instance($r_cid);
    } else {
        $r_ctx = get_context_instance(CONTEXT_COURSE, $r_cid);
    }
    if ($r_cqa) {
        if (respondusws_floatcompare($CFG->version, 2012062501.07, 2) >= 0) {
            if (!has_capability("mod/quiz:addinstance", $r_ctx, $RWSUID)) {
                RWSSErr("2012");
            }
        } else {
            if (!course_allowed_module($r_rcd, "quiz")) {
                RWSSErr("2012");
            }
        }
    }
    if (!RWSIUMCourse($r_cid)) {
        RWSSErr("2013");
    }
    return $r_rcd;
}
     var $timestart;
     var $timeduration;
     var $visible;
     var $instance;
     var $eventtype;
     var $timemodified;
     var $sequence = 1;
 }
 if (isset($SESSION->modform)) {
     // Variables are stored in the session
     $mod = $SESSION->modform;
     unset($SESSION->modform);
 } else {
     $mod = (object) $_POST;
 }
 if (isset($course) && !course_allowed_module($course, $mod->modulename)) {
     error("This module ({$mod->modulename}) has been disabled for this particular course");
 }
 if (!isset($mod->name) || trim($mod->name) == '') {
     $mod->name = get_string("modulename", $mod->modulename);
 }
 // Finally create the actual webclass at Sclipo
 $webclass->title = stripslashes($_POST["title"]);
 $webclass->description = stripslashes($_POST["description"]);
 $webclass->tags = stripslashes($_POST["tags"]);
 $webclass->class_date = $_POST["method_face_date"];
 $webclass->time = $_POST["timeEntry"];
 $webclass->duration = $_POST["duration"];
 $webclass->max_students = $_POST["max_students"];
 $webclass->ref = $_POST["ref"];
 if (isset($_POST['publicwebclass'])) {
Beispiel #11
0
 /**
  * Create the coursemodule to hold the file/content that has been uploaded
  */
 protected function create_course_module()
 {
     global $CFG;
     if (!course_allowed_module($this->course, $this->module->name)) {
         throw new coding_exception("The module {$this->module->name} is not allowed to be added to this course");
     }
     $this->cm = new stdClass();
     $this->cm->course = $this->course->id;
     $this->cm->section = $this->section;
     $this->cm->module = $this->module->id;
     $this->cm->modulename = $this->module->name;
     $this->cm->instance = 0;
     // This will be filled in after we create the instance.
     $this->cm->visible = 1;
     $this->cm->groupmode = $this->course->groupmode;
     $this->cm->groupingid = $this->course->defaultgroupingid;
     // Set the correct default for completion tracking.
     $this->cm->completion = COMPLETION_TRACKING_NONE;
     $completion = new completion_info($this->course);
     if ($completion->is_enabled() && $CFG->completiondefault) {
         if (plugin_supports('mod', $this->cm->modulename, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
             $this->cm->completion = COMPLETION_TRACKING_MANUAL;
         }
     }
     if (!($this->cm->id = add_course_module($this->cm))) {
         throw new coding_exception("Unable to create the course module");
     }
     $this->cm->coursemodule = $this->cm->id;
 }
     $eventdata = new stdClass();
     $eventdata->modulename = $fromform->modulename;
     $eventdata->name = $fromform->name;
     $eventdata->cmid = $fromform->coursemodule;
     $eventdata->courseid = $course->id;
     $eventdata->userid = $USER->id;
     events_trigger('mod_updated', $eventdata);
     add_to_log($course->id, "course", "update mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}");
     add_to_log($course->id, $fromform->modulename, "update", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule);
 } else {
     if (!empty($fromform->add)) {
         if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
             $fromform->groupmode = 0;
             // do not set groupmode
         }
         if (!course_allowed_module($course, $fromform->modulename)) {
             print_error('moduledisable', '', '', $fromform->modulename);
         }
         // first add course_module record because we need the context
         $newcm = new stdClass();
         $newcm->course = $course->id;
         $newcm->module = $fromform->module;
         $newcm->instance = 0;
         // not known yet, will be updated later (this is similar to restore code)
         $newcm->visible = $fromform->visible;
         $newcm->groupmode = $fromform->groupmode;
         $newcm->groupingid = $fromform->groupingid;
         $newcm->groupmembersonly = $fromform->groupmembersonly;
         $completion = new completion_info($course);
         if ($completion->is_enabled()) {
             $newcm->completion = $fromform->completion;
/**
 * Prints the menus to add activities and resources. Creates on combo box for both activities and resources.
 * Resources to be included in format are stored in $allowedresources; Activities to be included in format are stored in $allowedactivities
 */
function print_section_add_menus_format($course, $section, $modnames, $vertical = false, $return = false)
{
    global $CFG;
    // check to see if user can add menus
    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
        return false;
    }
    static $allowedresources = array('resource&amp;type=html', 'resource&amp;type=file', 'resource&amp;type=directory', 'label');
    // Add resources as needed
    static $allowedactivities = array('questionnaire', 'wiki', 'glossary', 'simpleblog', 'game', 'forum', 'chat', 'choice', 'lesson', 'quiz', 'swf');
    // Add activities as needed
    static $resources = false;
    static $activities = false;
    static $tasks = false;
    if ($resources === false) {
        $resources = array();
        $activities = array();
        $tasks = array();
        // for activities who's $type->modclass != MOD_CLASS_RESOURCE
        /* begin with optgroup name*/
        $resources[] = '--' . get_string('resources');
        $activities[] = '--' . get_string('activities');
        foreach ($modnames as $modname => $modnamestr) {
            if (!course_allowed_module($course, $modname)) {
                continue;
            }
            $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
            if (!file_exists($libfile)) {
                continue;
            }
            include_once $libfile;
            $gettypesfunc = $modname . '_get_types';
            if (function_exists($gettypesfunc)) {
                $types = $gettypesfunc();
                foreach ($types as $type) {
                    if (!isset($type->modclass) or !isset($type->typestr)) {
                        debugging('Incorrect activity type in ' . $modname);
                        continue;
                    }
                    if ($type->modclass == MOD_CLASS_RESOURCE) {
                        if (in_array($type->type, $allowedresources)) {
                            // filter resources according to list in $allowedresources
                            $resources[$type->type] = $type->typestr;
                        }
                    } else {
                        $tasks[$type->type] = $type->typestr;
                    }
                }
            } else {
                // all mods without type are considered activity
                // filter activities according to list in $allowedactivities
                if (in_array($modname, $allowedactivities)) {
                    $activities[$modname] = $modnamestr;
                }
            }
        }
    }
    $straddcontenttype = get_string('addcontenttype');
    $output = '<div class="section_add_menus">';
    if (!$vertical) {
        $output .= '<div class="horizontal">';
    }
    // End optgroups
    $resources[] = '--';
    $activities[] = '--';
    //  combine activities and resources, and group accordingly
    $contenttype = array_merge($resources, $activities, $tasks);
    if (!empty($contenttype)) {
        $output .= popup_form("{$CFG->wwwroot}/course/mod.php?id={$course->id}&amp;section={$section}&amp;sesskey=" . sesskey() . "&amp;add=", $contenttype, "ressection{$section}", "", $straddcontenttype, 'resource/types', $straddcontenttype, true);
    }
    if (!$vertical) {
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Beispiel #14
0
 /**
  * Create the coursemodule to hold the file/content that has been uploaded
  */
 protected function create_course_module()
 {
     if (!course_allowed_module($this->course, $this->module->name)) {
         throw new coding_exception("The module {$this->module->name} is not allowed to be added to this course");
     }
     $this->cm = new stdClass();
     $this->cm->course = $this->course->id;
     $this->cm->section = $this->section;
     $this->cm->module = $this->module->id;
     $this->cm->modulename = $this->module->name;
     $this->cm->instance = 0;
     // This will be filled in after we create the instance.
     $this->cm->visible = 1;
     $this->cm->groupmode = $this->course->groupmode;
     $this->cm->groupingid = $this->course->defaultgroupingid;
     if (!($this->cm->id = add_course_module($this->cm))) {
         throw new coding_exception("Unable to create the course module");
     }
     // The following are used inside some few core functions, so may as well set them here.
     $this->cm->coursemodule = $this->cm->id;
     $groupbuttons = ($this->course->groupmode or !$this->course->groupmodeforce);
     if ($groupbuttons and plugin_supports('mod', $this->module->name, FEATURE_GROUPS, 0)) {
         $this->cm->groupmodelink = !$this->course->groupmodeforce;
     } else {
         $this->cm->groupmodelink = false;
         $this->cm->groupmode = false;
     }
 }
Beispiel #15
0
/**
 * Retrieve all metadata for the requested modules
 *
 * @param object $course The Course
 * @param array $modnames An array containing the list of modules and their
 * names
 * @param int $sectionreturn The section to return to
 * @return array A list of stdClass objects containing metadata about each
 * module
 */
function get_module_metadata($course, $modnames, $sectionreturn = null)
{
    global $OUTPUT;
    // get_module_metadata will be called once per section on the page and courses may show
    // different modules to one another
    static $modlist = array();
    if (!isset($modlist[$course->id])) {
        $modlist[$course->id] = array();
    }
    $return = array();
    $urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
    if ($sectionreturn !== null) {
        $urlbase->param('sr', $sectionreturn);
    }
    foreach ($modnames as $modname => $modnamestr) {
        if (!course_allowed_module($course, $modname)) {
            continue;
        }
        if (isset($modlist[$course->id][$modname])) {
            // This module is already cached
            $return += $modlist[$course->id][$modname];
            continue;
        }
        $modlist[$course->id][$modname] = array();
        // Create an object for a default representation of this module type in the activity chooser. It will be used
        // if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
        $defaultmodule = new stdClass();
        $defaultmodule->title = $modnamestr;
        $defaultmodule->name = $modname;
        $defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
        $defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
        $sm = get_string_manager();
        if ($sm->string_exists('modulename_help', $modname)) {
            $defaultmodule->help = get_string('modulename_help', $modname);
            if ($sm->string_exists('modulename_link', $modname)) {
                // Link to further info in Moodle docs.
                $link = get_string('modulename_link', $modname);
                $linktext = get_string('morehelp');
                $defaultmodule->help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
            }
        }
        $defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
        // Legacy support for callback get_types() - do not use any more, use get_shortcuts() instead!
        $typescallbackexists = component_callback_exists($modname, 'get_types');
        // Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
        // of elements to be added to activity chooser.
        $items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
        if ($items !== null) {
            foreach ($items as $item) {
                // Add all items to the return array. All items must have different links, use them as a key in the return array.
                if (!isset($item->archetype)) {
                    $item->archetype = $defaultmodule->archetype;
                }
                if (!isset($item->icon)) {
                    $item->icon = $defaultmodule->icon;
                }
                // If plugin returned the only one item with the same link as default item - cache it as $modname,
                // otherwise append the link url to the module name.
                $item->name = count($items) == 1 && $item->link->out() === $defaultmodule->link->out() ? $modname : $modname . ':' . $item->link;
                // If the module provides the helptext property, append it to the help text to match the look and feel
                // of the default course modules.
                if (isset($item->help) && isset($item->helplink)) {
                    $linktext = get_string('morehelp');
                    $item->help .= html_writer::tag('div', $OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
                }
                $modlist[$course->id][$modname][$item->name] = $item;
            }
            $return += $modlist[$course->id][$modname];
            if ($typescallbackexists) {
                debugging('Both callbacks get_shortcuts() and get_types() are found in module ' . $modname . '. Callback get_types() will be completely ignored', DEBUG_DEVELOPER);
            }
            // If get_shortcuts() callback is defined, the default module action is not added.
            // It is a responsibility of the callback to add it to the return value unless it is not needed.
            continue;
        }
        if ($typescallbackexists) {
            debugging('Callback get_types() is found in module ' . $modname . ', this functionality is deprecated, ' . 'please use callback get_shortcuts() instead', DEBUG_DEVELOPER);
        }
        $types = component_callback($modname, 'get_types', array(), MOD_SUBTYPE_NO_CHILDREN);
        if ($types !== MOD_SUBTYPE_NO_CHILDREN) {
            // Legacy support for deprecated callback get_types(). To be removed in Moodle 3.5. TODO MDL-53697.
            if (is_array($types) && count($types) > 0) {
                $grouptitle = $modnamestr;
                $icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
                foreach ($types as $type) {
                    if ($type->typestr === '--') {
                        continue;
                    }
                    if (strpos($type->typestr, '--') === 0) {
                        $grouptitle = str_replace('--', '', $type->typestr);
                        continue;
                    }
                    // Set the Sub Type metadata.
                    $subtype = new stdClass();
                    $subtype->title = get_string('activitytypetitle', '', (object) ['activity' => $grouptitle, 'type' => $type->typestr]);
                    $subtype->type = str_replace('&amp;', '&', $type->type);
                    $typename = preg_replace('/.*type=/', '', $subtype->type);
                    $subtype->archetype = $type->modclass;
                    if (!empty($type->help)) {
                        $subtype->help = $type->help;
                    } else {
                        if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
                            $subtype->help = get_string('help' . $subtype->name, $modname);
                        }
                    }
                    $subtype->link = new moodle_url($urlbase, array('add' => $modname, 'type' => $typename));
                    $subtype->name = $modname . ':' . $subtype->link;
                    $subtype->icon = $icon;
                    $modlist[$course->id][$modname][$subtype->name] = $subtype;
                }
                $return += $modlist[$course->id][$modname];
            }
        } else {
            // Neither get_shortcuts() nor get_types() callbacks found, use the default item for the activity chooser.
            $modlist[$course->id][$modname][$modname] = $defaultmodule;
            $return[$modname] = $defaultmodule;
        }
    }
    core_collator::asort_objects_by_property($return, 'title');
    return $return;
}
Beispiel #16
0
/**
 * Retrieve all metadata for the requested modules
 *
 * @param object $course The Course
 * @param array $modnames An array containing the list of modules and their
 * names
 * @return array A list of stdClass objects containing metadata about each
 * module
 */
function get_module_metadata($course, $modnames)
{
    global $CFG, $OUTPUT;
    // get_module_metadata will be called once per section on the page and courses may show
    // different modules to one another
    static $modlist = array();
    if (!isset($modlist[$course->id])) {
        $modlist[$course->id] = array();
    }
    $return = array();
    $urlbase = "/course/mod.php?id={$course->id}&sesskey=" . sesskey() . '&add=';
    foreach ($modnames as $modname => $modnamestr) {
        if (!course_allowed_module($course, $modname)) {
            continue;
        }
        if (isset($modlist[$modname])) {
            // This module is already cached
            $return[$modname] = $modlist[$course->id][$modname];
            continue;
        }
        // Include the module lib
        $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
        if (!file_exists($libfile)) {
            continue;
        }
        include_once $libfile;
        // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
        $gettypesfunc = $modname . '_get_types';
        if (function_exists($gettypesfunc)) {
            if ($types = $gettypesfunc()) {
                $group = new stdClass();
                $group->name = $modname;
                $group->icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
                foreach ($types as $type) {
                    if ($type->typestr === '--') {
                        continue;
                    }
                    if (strpos($type->typestr, '--') === 0) {
                        $group->title = str_replace('--', '', $type->typestr);
                        continue;
                    }
                    // Set the Sub Type metadata
                    $subtype = new stdClass();
                    $subtype->title = $type->typestr;
                    $subtype->type = str_replace('&amp;', '&', $type->type);
                    $subtype->name = preg_replace('/.*type=/', '', $subtype->type);
                    $subtype->archetype = $type->modclass;
                    // The group archetype should match the subtype archetypes and all subtypes
                    // should have the same archetype
                    $group->archetype = $subtype->archetype;
                    if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
                        $subtype->help = get_string('help' . $subtype->name, $modname);
                    }
                    $subtype->link = $urlbase . $subtype->type;
                    $group->types[] = $subtype;
                }
                $modlist[$course->id][$modname] = $group;
            }
        } else {
            $module = new stdClass();
            $module->title = get_string('modulename', $modname);
            $module->name = $modname;
            $module->link = $urlbase . $modname;
            $module->icon = $OUTPUT->pix_icon('icon', '', $module->name, array('class' => 'icon'));
            if (get_string_manager()->string_exists('modulename_help', $modname)) {
                $module->help = get_string('modulename_help', $modname);
            }
            $module->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
            $modlist[$course->id][$modname] = $module;
        }
        $return[$modname] = $modlist[$course->id][$modname];
    }
    return $return;
}
 /**
  * Create the coursemodule to hold the file/content that has been uploaded
  */
 protected function create_course_module()
 {
     if (!course_allowed_module($this->course, $this->module->name)) {
         throw new coding_exception("The module {$this->module->name} is not allowed to be added to this course");
     }
     $this->cm = new stdClass();
     $this->cm->course = $this->course->id;
     $this->cm->section = $this->section;
     $this->cm->module = $this->module->id;
     $this->cm->modulename = $this->module->name;
     $this->cm->instance = 0;
     // This will be filled in after we create the instance.
     $this->cm->visible = 1;
     $this->cm->groupmode = $this->course->groupmode;
     $this->cm->groupingid = $this->course->defaultgroupingid;
     // Set the correct default for completion tracking.
     $this->cm->completion = COMPLETION_TRACKING_NONE;
     $completion = new completion_info($this->course);
     if ($completion->is_enabled()) {
         if (plugin_supports('mod', $this->cm->modulename, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
             $this->cm->completion = COMPLETION_TRACKING_MANUAL;
         }
     }
     if (!($this->cm->id = add_course_module($this->cm))) {
         throw new coding_exception("Unable to create the course module");
     }
     // The following are used inside some few core functions, so may as well set them here.
     $this->cm->coursemodule = $this->cm->id;
     $groupbuttons = ($this->course->groupmode or !$this->course->groupmodeforce);
     if ($groupbuttons and plugin_supports('mod', $this->module->name, FEATURE_GROUPS, 0)) {
         $this->cm->groupmodelink = !$this->course->groupmodeforce;
     } else {
         $this->cm->groupmodelink = false;
         $this->cm->groupmode = false;
     }
 }
Beispiel #18
0
     }
     $strnav = "<a href=\"{$CFG->wwwroot}/mod/{$module->name}/view.php?id={$cm->id}\">{$form->name}</a> ->";
     $CFG->pagepath = 'mod/' . $module->name . '/mod';
 } else {
     if (!empty($add) and confirm_sesskey()) {
         $id = required_param('id', PARAM_INT);
         $section = required_param('section', PARAM_INT);
         if (!($course = get_record("course", "id", $id))) {
             error("This course doesn't exist");
         }
         if (!($module = get_record("modules", "name", $add))) {
             error("This module type doesn't exist");
         }
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         require_capability('moodle/course:manageactivities', $context);
         if (!course_allowed_module($course, $module->id)) {
             error("This module has been disabled for this particular course");
         }
         require_login($course->id);
         // needed to setup proper $COURSE
         $form->section = $section;
         // The section number itself
         $form->course = $course->id;
         $form->module = $module->id;
         $form->modulename = $module->name;
         $form->instance = "";
         $form->coursemodule = "";
         $form->mode = "add";
         $form->sesskey = !empty($USER->id) ? $USER->sesskey : '';
         if (!empty($type)) {
             $form->type = $type;
Beispiel #19
0
/**
 * Prints the menus to add activities and resources.
 */
function print_section_add_menus($course, $section, $modnames, $vertical = false, $return = false)
{
    global $CFG, $OUTPUT;
    // check to see if user can add menus
    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
        return false;
    }
    $urlbase = "/course/mod.php?id={$course->id}&section={$section}&sesskey=" . sesskey() . '&add=';
    $resources = array();
    $activities = array();
    foreach ($modnames as $modname => $modnamestr) {
        if (!course_allowed_module($course, $modname)) {
            continue;
        }
        $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
        if (!file_exists($libfile)) {
            continue;
        }
        include_once $libfile;
        $gettypesfunc = $modname . '_get_types';
        if (function_exists($gettypesfunc)) {
            // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
            if ($types = $gettypesfunc()) {
                $menu = array();
                $atype = null;
                $groupname = null;
                foreach ($types as $type) {
                    if ($type->typestr === '--') {
                        continue;
                    }
                    if (strpos($type->typestr, '--') === 0) {
                        $groupname = str_replace('--', '', $type->typestr);
                        continue;
                    }
                    $type->type = str_replace('&amp;', '&', $type->type);
                    if ($type->modclass == MOD_CLASS_RESOURCE) {
                        $atype = MOD_CLASS_RESOURCE;
                    }
                    $menu[$urlbase . $type->type] = $type->typestr;
                }
                if (!is_null($groupname)) {
                    if ($atype == MOD_CLASS_RESOURCE) {
                        $resources[] = array($groupname => $menu);
                    } else {
                        $activities[] = array($groupname => $menu);
                    }
                } else {
                    if ($atype == MOD_CLASS_RESOURCE) {
                        $resources = array_merge($resources, $menu);
                    } else {
                        $activities = array_merge($activities, $menu);
                    }
                }
            }
        } else {
            $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
            if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                $resources[$urlbase . $modname] = $modnamestr;
            } else {
                // all other archetypes are considered activity
                $activities[$urlbase . $modname] = $modnamestr;
            }
        }
    }
    $straddactivity = get_string('addactivity');
    $straddresource = get_string('addresource');
    $output = '<div class="section_add_menus">';
    if (!$vertical) {
        $output .= '<div class="horizontal">';
    }
    if (!empty($resources)) {
        $select = new url_select($resources, '', array('' => $straddresource), "ressection{$section}");
        $select->set_help_icon('resources');
        $output .= $OUTPUT->render($select);
    }
    if (!empty($activities)) {
        $select = new url_select($activities, '', array('' => $straddactivity), "section{$section}");
        $select->set_help_icon('activities');
        $output .= $OUTPUT->render($select);
    }
    if (!$vertical) {
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
 /**
  * Generate the list of modules for the given course.
  *
  * @param stdClass $course The course to get modules for
  */
 protected function get_course_modules($course)
 {
     global $CFG;
     $mods = $modnames = $modnamesplural = $modnamesused = array();
     // This function is included when we include course/lib.php at the top
     // of this file
     get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
     $resources = array();
     $activities = array();
     foreach ($modnames as $modname => $modnamestr) {
         if (!course_allowed_module($course, $modname)) {
             continue;
         }
         $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
         if (!file_exists($libfile)) {
             continue;
         }
         include_once $libfile;
         $gettypesfunc = $modname . '_get_types';
         if (function_exists($gettypesfunc)) {
             $types = $gettypesfunc();
             foreach ($types as $type) {
                 if (!isset($type->modclass) || !isset($type->typestr)) {
                     debugging('Incorrect activity type in ' . $modname);
                     continue;
                 }
                 if ($type->modclass == MOD_CLASS_RESOURCE) {
                     $resources[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
                 } else {
                     $activities[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
                 }
             }
         } else {
             $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
             if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                 $resources[$modname] = $modnamestr;
             } else {
                 // all other archetypes are considered activity
                 $activities[$modname] = $modnamestr;
             }
         }
     }
     return array($resources, $activities);
 }
Beispiel #21
0
/**
 * Prints the menus to add activities and resources.
 */
function print_section_add_menus($course, $section, $modnames, $vertical = false, $return = false)
{
    global $CFG, $OUTPUT;
    // check to see if user can add menus
    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
        return false;
    }
    static $resources = false;
    static $activities = false;
    if ($resources === false) {
        $resources = array();
        $activities = array();
        foreach ($modnames as $modname => $modnamestr) {
            if (!course_allowed_module($course, $modname)) {
                continue;
            }
            $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
            if (!file_exists($libfile)) {
                continue;
            }
            include_once $libfile;
            $gettypesfunc = $modname . '_get_types';
            if (function_exists($gettypesfunc)) {
                $types = $gettypesfunc();
                foreach ($types as $type) {
                    $type->type = str_replace('&amp;', '&', $type->type);
                    if (!isset($type->modclass) or !isset($type->typestr)) {
                        debugging('Incorrect activity type in ' . $modname);
                        continue;
                    }
                    if ($type->modclass == MOD_CLASS_RESOURCE) {
                        $resources[$type->type] = $type->typestr;
                    } else {
                        $activities[$type->type] = $type->typestr;
                    }
                }
            } else {
                $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                    $resources[$modname] = $modnamestr;
                } else {
                    // all other archetypes are considered activity
                    $activities[$modname] = $modnamestr;
                }
            }
        }
    }
    $straddactivity = get_string('addactivity');
    $straddresource = get_string('addresource');
    $output = '<div class="section_add_menus">';
    if (!$vertical) {
        $output .= '<div class="horizontal">';
    }
    $popupurl = "{$CFG->wwwroot}/course/mod.php?id={$course->id}&section={$section}&sesskey=" . sesskey();
    if (!empty($resources)) {
        $select = html_select::make_popup_form($popupurl, 'add', $resources, "ressection{$section}", null);
        $select->nothinglabel = $straddresource;
        $select->set_help_icon('resource/types', $straddresource);
        $output .= $OUTPUT->select($select);
    }
    if (!empty($activities)) {
        $select = html_select::make_popup_form($popupurl, 'add', $activities, "section{$section}", null);
        $select->nothinglabel = $straddactivity;
        $select->set_help_icon('mods', $straddactivity);
        $output .= $OUTPUT->select($select);
    }
    if (!$vertical) {
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}