当前位置: 首页>>代码示例>>PHP>>正文


PHP course_allowed_module函数代码示例

本文整理汇总了PHP中course_allowed_module函数的典型用法代码示例。如果您正苦于以下问题:PHP course_allowed_module函数的具体用法?PHP course_allowed_module怎么用?PHP course_allowed_module使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了course_allowed_module函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: link_to_gdoc

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');
//.........这里部分代码省略.........
开发者ID:rlorenzo,项目名称:moodle-block_morsle,代码行数:101,代码来源:morslelib.php

示例2: get_module_metadata

/**
 * 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];
//.........这里部分代码省略.........
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:101,代码来源:lib.php

示例3: print_section_add_menus

/**
 * 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;
    }
}
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:67,代码来源:lib.php

示例4: can_add_moduleinfo

/**
 * 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);
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:23,代码来源:modlib.php

示例5: switch

             }
             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) {
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:31,代码来源:rest.php

示例6: local_ltiprovider_add_moduleinfo

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:gabrielrosset,项目名称:moodle-local_ltiprovider,代码行数:101,代码来源:locallib.php

示例7: can_add_activity

 /**
  * 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;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:23,代码来源:lib.php

示例8: RWSCMUCourse

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;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:30,代码来源:servicelib.php

示例9: unset

     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'])) {
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:edit_webclass.php

示例10: create_course_module

 /**
  * 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;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:32,代码来源:dnduploadlib.php

示例11: stdClass

     $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;
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:31,代码来源:modedit.php

示例12: print_section_add_menus_format

/**
 * 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;
    }
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:84,代码来源:lib.php

示例13: create_course_module

 /**
  * 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;
     }
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:31,代码来源:dnduploadlib.php

示例14: get_module_metadata

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:janeklb,项目名称:moodle,代码行数:101,代码来源:lib.php

示例15: get_module_metadata

/**
 * 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;
}
开发者ID:numbas,项目名称:moodle,代码行数:83,代码来源:lib.php


注:本文中的course_allowed_module函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。