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


PHP add_course_module函数代码示例

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


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

示例1: xmldb_oublog_install

function xmldb_oublog_install()
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/course/lib.php';
    // Setup the global blog.
    $oublog = new stdClass();
    $oublog->course = SITEID;
    $oublog->name = 'Personal Blogs';
    $oublog->intro = '';
    $oublog->introformat = FORMAT_HTML;
    $oublog->accesstoken = md5(uniqid(rand(), true));
    $oublog->maxvisibility = 300;
    // OUBLOG_VISIBILITY_PUBLIC.
    $oublog->global = 1;
    $oublog->allowcomments = 2;
    // OUBLOG_COMMENTS_ALLOWPUBLIC.
    if (!($oublog->id = $DB->insert_record('oublog', $oublog))) {
        return false;
    }
    $mod = new stdClass();
    $mod->course = SITEID;
    $mod->module = $DB->get_field('modules', 'id', array('name' => 'oublog'));
    $mod->instance = $oublog->id;
    $mod->visible = 1;
    $mod->visibleold = 0;
    $mod->section = 1;
    if (!($cm = add_course_module($mod))) {
        return true;
    }
    set_config('oublogsetup', null);
    // For unit tests to work, it's necessary to create context now.
    context_module::instance($cm);
    return true;
}
开发者ID:eugeneventer,项目名称:moodle-mod_oublog,代码行数:34,代码来源:install.php

示例2: create_cm

 /**
  * Create a course module object.
  *
  * @param  stdClass $course     The course to apply to.
  * @param  stdClass $section    The section to apply to.
  * @param  stdClass $module     The module to apply to.
  * @param  stdClass $instance   The instance to apply to.
  * @param  stdClass $data       The original data we extracted.
  */
 private function create_cm($course, $section, $module, $instance, $data)
 {
     // Create a module container.
     $cm = new \stdClass();
     $cm->course = $course->id;
     $cm->module = $module->id;
     $cm->instance = $instance->id;
     $cm->section = $section->id;
     $cm->visible = 1;
     if (isset($data->showdescription)) {
         $cm->showdescription = $data->showdescription;
     }
     // Create the module.
     $cm->id = add_course_module($cm);
     return $cm;
 }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:25,代码来源:activity.php

示例3: add_instance

 function add_instance($resource)
 {
     $result = parent::add_instance($resource);
     $entry = new kaltura_entry();
     $entry->entry_id = $resource->alltext;
     $entry->dimensions = $_POST['dimensions'];
     $entry->size = $_POST['size'];
     $entry->custom_width = $_POST['custom_width'];
     $entry->design = $_POST['design'];
     $entry->title = $_POST['title'];
     $entry->context = "R_" . $result;
     $entry->entry_type = KalturaEntryType::DOCUMENT;
     $entry->media_type = KalturaMediaType::VIDEO;
     $entry->id = insert_record('kaltura_entries', $entry);
     //for backup we need a to tell moolde that kaltura is connected to this course
     $mod = new object();
     $mod->course = $this->course->id;
     $mod->module = get_field('modules', 'id', 'name', 'kaltura');
     $mod->instance = $entry->id;
     $mod->section = 0;
     add_course_module($mod);
     return $result;
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:23,代码来源:resource.class.php

示例4: add_item_to_course

 /**
  *
  * @param unknown $user
  * @param unknown $courseid
  * @param unknown $sectionid
  * @param unknown $itemUuid
  * @param unknown $itemVersion
  * @param unknown $url
  * @param unknown $title
  * @param unknown $description
  * @param unknown $attachmentUuid
  * @return array
  */
 public static function add_item_to_course($username, $courseid, $sectionnum, $itemUuid, $itemVersion, $url, $title, $description, $attachmentUuid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::add_item_to_course_parameters(), array('user' => $username, 'courseid' => $courseid, 'sectionid' => $sectionnum, 'itemUuid' => $itemUuid, 'itemVersion' => $itemVersion, 'url' => $url, 'title' => $title, 'description' => $description, 'attachmentUuid' => $attachmentUuid));
     self::check_modify_permissions($username, $courseid);
     $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
     $modname = 'equella';
     $module = $DB->get_record('modules', array('name' => $modname));
     $eq = new stdClass();
     $eq->course = $courseid;
     $eq->module = $module->id;
     $eq->name = $title;
     $eq->intro = $description;
     $eq->introformat = FORMAT_HTML;
     $eq->url = $url;
     $eq->uuid = $itemUuid;
     $eq->version = $itemVersion;
     $eq->mimetype = mimeinfo('type', $title);
     if (!empty($attachmentUuid)) {
         $eq->filename = $title;
         $eq->attachmentuuid = $attachmentUuid;
     }
     $eqid = equella_add_instance($eq);
     $cmid = null;
     $mod = new stdClass();
     $mod->course = $courseid;
     $mod->module = $module->id;
     $mod->instance = $eqid;
     $mod->modulename = $modname;
     $mod->section = 0;
     if (!($cmid = add_course_module($mod))) {
         throw new moodle_exception('cannotaddcoursemodule');
     }
     if (!($addedsectionid = course_add_cm_to_section($courseid, $cmid, $sectionnum))) {
         throw new moodle_exception('cannotaddcoursemoduletosection');
     }
     set_coursemodule_visible($cmid, true);
     if (class_exists('core\\event\\course_module_created')) {
         $cm = get_coursemodule_from_id('equella', $cmid, 0, false, MUST_EXIST);
         $event = \core\event\course_module_created::create_from_cm($cm);
         $event->trigger();
     } else {
         $eventdata = new stdClass();
         $eventdata->modulename = $modname;
         $eventdata->name = $eq->name;
         $eventdata->cmid = $cmid;
         $eventdata->courseid = $eq->course;
         $eventdata->userid = $USER->id;
         events_trigger('mod_created', $eventdata);
         add_to_log($eq->course, "course", "add mod", "../mod/{$modname}/view.php?id={$cmid}", "{$modname} {$eqid}");
         add_to_log($eq->course, $modname, "add equella resource", "view.php?id={$cmid}", "{$eqid}", $cmid);
     }
     $result = array('courseid' => $courseid, 'coursename' => $course->fullname, 'sectionid' => $params['sectionid'], 'sectionname' => get_section_name($courseid, $sectionnum));
     //flog("DB queries: " . $DB->perf_get_queries());
     return $result;
 }
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:69,代码来源:externallib.php

示例5: assignment_type_online_upgrade

function assignment_type_online_upgrade($oldversion)
{
    global $CFG, $db;
    if ($oldversion < 2005042900 and empty($CFG->noconvertjournals)) {
        // Phase out Journals, convert them
        $affectedcourses = array();
        // to Online Assignment
        if ($journals = get_records('journal')) {
            require_once $CFG->dirroot . '/course/lib.php';
            $assignmentmodule = get_record('modules', 'name', 'assignment');
            foreach ($journals as $journal) {
                $affectedcourses[$journal->course] = $journal->course;
                /// First create the assignment instance
                $assignment = new object();
                $assignment->course = $journal->course;
                $assignment->name = addslashes($journal->name);
                $assignment->description = addslashes($journal->intro);
                $assignment->format = FORMAT_MOODLE;
                $assignment->assignmenttype = 'online';
                $assignment->resubmit = 1;
                $assignment->preventlate = 0;
                $assignment->emailteachers = 0;
                $assignment->var1 = 1;
                $assignment->var2 = 0;
                $assignment->var3 = 0;
                $assignment->var4 = 0;
                $assignment->var5 = 0;
                $assignment->var5 = 0;
                $assignment->maxbytes = 0;
                $assignment->timedue = 0;
                /// Don't have time to work this out .... :-(
                $assignment->timeavailable = 0;
                $assignment->grade = $journal->assessed;
                $assignment->timemodified = $journal->timemodified;
                $assignment->id = insert_record('assignment', $assignment);
                /// Now create a new course module record
                $oldcm = get_coursemodule_from_instance('journal', $journal->id, $journal->course);
                $newcm = clone $oldcm;
                $newcm->module = $assignmentmodule->id;
                $newcm->instance = $assignment->id;
                $newcm->added = time();
                if (!($newcm->id = add_course_module($newcm))) {
                    error("Could not add a new course module");
                }
                /// And locate it above the old one
                if (!($section = get_record('course_sections', 'id', $oldcm->section))) {
                    $section->section = 0;
                    // So it goes somewhere!
                }
                $newcm->coursemodule = $newcm->id;
                $newcm->section = $section->section;
                // need relative reference
                if (!($sectionid = add_mod_to_section($newcm, $oldcm))) {
                    // Add it before Journal
                    error("Could not add the new course module to that section");
                }
                /// Convert any existing entries from users
                if ($entries = get_records('journal_entries', 'journal', $journal->id)) {
                    foreach ($entries as $entry) {
                        $submission = new object();
                        $submission->assignment = $assignment->id;
                        $submission->userid = $entry->userid;
                        $submission->timecreated = $entry->modified;
                        $submission->timemodified = $entry->modified;
                        $submission->numfiles = 0;
                        $submission->data1 = addslashes($entry->text);
                        $submission->data2 = $entry->format;
                        $submission->grade = $entry->rating;
                        $submission->submissioncomment = addslashes($entry->comment);
                        $submission->format = FORMAT_MOODLE;
                        $submission->teacher = $entry->teacher;
                        $submission->timemarked = $entry->timemarked;
                        $submission->mailed = $entry->mailed;
                        $submission->id = insert_record('assignment_submissions', $submission);
                    }
                }
            }
            /// Clear the cache so this stuff appears
            foreach ($affectedcourses as $courseid) {
                rebuild_course_cache($courseid);
            }
        }
        /// Hide the whole Journal module (but not individual items, just to make undo easier)
        set_field('modules', 'visible', 0, 'name', 'journal');
        if ($journals === false) {
            notify('The Journal module is becoming obsolete and being replaced by the superior Online Assignments, and  
                    it has been disabled on your site.  If you really want Journal back, you can enable it using the 
                    "eye" icon here:  Admin >> Modules >> Journal.');
        } else {
            notify('The Journal module is becoming obsolete and being replaced by the superior Online Assignments.  
                    It has been disabled on your site, and the ' . count($journals) . ' Journal activites you had have been
                    converted into Online Assignments.  If you really want Journal back, you can enable it using the 
                    "eye" icon here:  Admin >> Modules >> Journal.');
        }
    }
    return true;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:97,代码来源:mysql.php

示例6: forum_get_course_forum

/**
 * @global object
 * @global object
 * @param int $courseid
 * @param string $type
 */
function forum_get_course_forum($courseid, $type)
{
    // How to set up special 1-per-course forums
    global $CFG, $DB, $OUTPUT, $USER;
    if ($forums = $DB->get_records_select("forum", "course = ? AND type = ?", array($courseid, $type), "id ASC")) {
        // There should always only be ONE, but with the right combination of
        // errors there might be more.  In this case, just return the oldest one (lowest ID).
        foreach ($forums as $forum) {
            return $forum;
            // ie the first one
        }
    }
    // Doesn't exist, so create one now.
    $forum = new stdClass();
    $forum->course = $courseid;
    $forum->type = "{$type}";
    if (!empty($USER->htmleditor)) {
        $forum->introformat = $USER->htmleditor;
    }
    switch ($forum->type) {
        case "news":
            $forum->name = get_string("namenews", "forum");
            $forum->intro = get_string("intronews", "forum");
            $forum->forcesubscribe = FORUM_FORCESUBSCRIBE;
            $forum->assessed = 0;
            if ($courseid == SITEID) {
                $forum->name = get_string("sitenews");
                $forum->forcesubscribe = 0;
            }
            break;
        case "social":
            $forum->name = get_string("namesocial", "forum");
            $forum->intro = get_string("introsocial", "forum");
            $forum->assessed = 0;
            $forum->forcesubscribe = 0;
            break;
        case "blog":
            $forum->name = get_string('blogforum', 'forum');
            $forum->intro = get_string('introblog', 'forum');
            $forum->assessed = 0;
            $forum->forcesubscribe = 0;
            break;
        default:
            echo $OUTPUT->notification("That forum type doesn't exist!");
            return false;
            break;
    }
    $forum->timemodified = time();
    $forum->id = $DB->insert_record("forum", $forum);
    if (!($module = $DB->get_record("modules", array("name" => "forum")))) {
        echo $OUTPUT->notification("Could not find forum module!!");
        return false;
    }
    $mod = new stdClass();
    $mod->course = $courseid;
    $mod->module = $module->id;
    $mod->instance = $forum->id;
    $mod->section = 0;
    include_once "{$CFG->dirroot}/course/lib.php";
    if (!($mod->coursemodule = add_course_module($mod))) {
        echo $OUTPUT->notification("Could not add a new course module to the course '" . $courseid . "'");
        return false;
    }
    $sectionid = course_add_cm_to_section($courseid, $mod->coursemodule, 0);
    return $DB->get_record("forum", array("id" => "{$forum->id}"));
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:72,代码来源:lib.php

示例7: error

         die;
     }
     error("Could not add a new instance of {$mod->modulename}", "view.php?id={$course->id}");
 }
 if (is_string($return)) {
     error($return, "view.php?id={$course->id}");
 }
 if (!isset($mod->groupmode)) {
     // to deal with pre-1.5 modules
     $mod->groupmode = $course->groupmode;
     /// Default groupmode the same as course
 }
 $mod->instance = $return;
 // course_modules and course_sections each contain a reference
 // to each other, so we have to update one of them twice.
 if (!($mod->coursemodule = add_course_module($mod))) {
     error("Could not add a new course module");
 }
 if (!($sectionid = add_mod_to_section($mod))) {
     error("Could not add the new course module to that section");
 }
 if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
     error("Could not update the course module with the correct section");
 }
 if (!isset($mod->visible)) {
     // We get the section's visible field status
     $mod->visible = get_field("course_sections", "visible", "id", $sectionid);
 }
 // make sure visibility is set correctly (in particular in calendar)
 set_coursemodule_visible($mod->coursemodule, $mod->visible);
 if (isset($mod->redirect)) {
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:mod.php

示例8: 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

示例9: main_upgrade

function main_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($oldversion == 0) {
        execute_sql("\n          CREATE TABLE `config` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `name` varchar(255) NOT NULL default '',\n            `value` varchar(255) NOT NULL default '',\n            PRIMARY KEY  (`id`),\n            UNIQUE KEY `name` (`name`)\n          ) COMMENT='Moodle configuration variables';");
        notify("Created a new table 'config' to hold configuration data");
    }
    if ($oldversion < 2002073100) {
        execute_sql(" DELETE FROM `modules` WHERE `name` = 'chat' ");
    }
    if ($oldversion < 2002080200) {
        execute_sql(" ALTER TABLE `modules` DROP `fullname`  ");
        execute_sql(" ALTER TABLE `modules` DROP `search`  ");
    }
    if ($oldversion < 2002080300) {
        execute_sql(" ALTER TABLE `log_display` CHANGE `table` `mtable` VARCHAR( 20 ) NOT NULL ");
        execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 3 ) DEFAULT '3' NOT NULL ");
    }
    if ($oldversion < 2002082100) {
        execute_sql(" ALTER TABLE `course` CHANGE `guest` `guest` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL ");
    }
    if ($oldversion < 2002082101) {
        execute_sql(" ALTER TABLE `user` ADD `maildisplay` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL AFTER `mailformat` ");
    }
    if ($oldversion < 2002090100) {
        execute_sql(" ALTER TABLE `course_sections` CHANGE `summary` `summary` TEXT NOT NULL ");
    }
    if ($oldversion < 2002090701) {
        execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 10 ) DEFAULT '3' NOT NULL ");
        execute_sql(" ALTER TABLE `user_teachers` ADD `role` VARCHAR(40) NOT NULL AFTER `authority` ");
    }
    if ($oldversion < 2002090800) {
        execute_sql(" ALTER TABLE `course` ADD `teachers` VARCHAR( 100 ) DEFAULT 'Teachers' NOT NULL AFTER `teacher` ");
        execute_sql(" ALTER TABLE `course` ADD `students` VARCHAR( 100 ) DEFAULT 'Students' NOT NULL AFTER `student` ");
    }
    if ($oldversion < 2002091000) {
        execute_sql(" ALTER TABLE `user` CHANGE `personality` `secret` VARCHAR( 15 ) NOT NULL DEFAULT ''  ");
    }
    if ($oldversion < 2002091400) {
        execute_sql(" ALTER TABLE `user` ADD `lang` VARCHAR( 3 ) DEFAULT 'en' NOT NULL AFTER `country`  ");
    }
    if ($oldversion < 2002091900) {
        notify("Most Moodle configuration variables have been moved to the database and can now be edited via the admin page.");
        notify("Although it is not vital that you do so, you might want to edit <U>config.php</U> and remove all the unused settings (except the database, URL and directory definitions).  See <U>config-dist.php</U> for an example of how your new slim config.php should look.");
    }
    if ($oldversion < 2002092000) {
        execute_sql(" ALTER TABLE `user` CHANGE `lang` `lang` VARCHAR(5) DEFAULT 'en' NOT NULL  ");
    }
    if ($oldversion < 2002092100) {
        execute_sql(" ALTER TABLE `user` ADD `deleted` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `confirmed` ");
    }
    if ($oldversion < 2002101001) {
        execute_sql(" ALTER TABLE `user` ADD `htmleditor` TINYINT(1) UNSIGNED DEFAULT '1' NOT NULL AFTER `maildisplay` ");
    }
    if ($oldversion < 2002101701) {
        execute_sql(" ALTER TABLE `reading` RENAME `resource` ");
        // Small line with big consequences!
        execute_sql(" DELETE FROM `log_display` WHERE module = 'reading'");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('resource', 'view', 'resource', 'name') ");
        execute_sql(" UPDATE log SET module = 'resource' WHERE module = 'reading' ");
        execute_sql(" UPDATE modules SET name = 'resource' WHERE name = 'reading' ");
    }
    if ($oldversion < 2002102503) {
        execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
        require_once "{$CFG->dirroot}/mod/forum/lib.php";
        require_once "{$CFG->dirroot}/course/lib.php";
        if (!($module = get_record("modules", "name", "forum"))) {
            notify("Could not find forum module!!");
            return false;
        }
        // First upgrade the site forums
        if ($site = get_site()) {
            print_heading("Making News forums editable for main site (moving to section 1)...");
            if ($news = forum_get_course_forum($site->id, "news")) {
                $mod->course = $site->id;
                $mod->module = $module->id;
                $mod->instance = $news->id;
                $mod->section = 1;
                if (!($mod->coursemodule = add_course_module($mod))) {
                    notify("Could not add a new course module to the site");
                    return false;
                }
                if (!($sectionid = add_mod_to_section($mod))) {
                    notify("Could not add the new course module to that section");
                    return false;
                }
                if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
                    notify("Could not update the course module with the correct section");
                    return false;
                }
            }
        }
        // Now upgrade the courses.
        if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) {
            print_heading("Making News and Social forums editable for each course (moving to section 0)...");
            foreach ($courses as $course) {
                if ($course->format == "social") {
                    // we won't touch them
                    continue;
//.........这里部分代码省略.........
开发者ID:veritech,项目名称:pare-project,代码行数:101,代码来源:mysql.php

示例10: 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;
     // 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;
     }
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:39,代码来源:dnduploadlib.php

示例11: 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

示例12: 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

示例13: 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 add_moduleinfo($moduleinfo, $course, $mform = null)
{
    global $DB, $CFG;
    // Attempt to include module library before we make any changes to DB.
    include_modulelib($moduleinfo->modulename);
    $moduleinfo->course = $course->id;
    $moduleinfo = set_moduleinfo_defaults($moduleinfo);
    if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
        $moduleinfo->groupmode = 0;
        // Do not set groupmode.
    }
    // 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;
    if (isset($moduleinfo->cmidnumber)) {
        $newcm->idnumber = $moduleinfo->cmidnumber;
    }
    $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) && isset($moduleinfo->introeditor)) {
        $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);
        context_helper::delete_instance(CONTEXT_MODULE, $moduleinfo->coursemodule);
        $DB->delete_records('course_modules', array('id' => $moduleinfo->coursemodule));
        if (!is_number($returnfromfunc)) {
            print_error('invalidfunction', '', course_get_url($course, $moduleinfo->section));
        } else {
            print_error('cannotaddnewmodule', '', course_get_url($course, $moduleinfo->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);
    // Set up conditions.
    if ($CFG->enableavailability) {
        condition_info::update_cm_from_form((object) array('id' => $moduleinfo->coursemodule), $moduleinfo, false);
    }
    // Trigger event based on the action we did.
    $event = \core\event\course_module_created::create(array('courseid' => $course->id, 'context' => $modcontext, 'objectid' => $moduleinfo->coursemodule, 'other' => array('modulename' => $moduleinfo->modulename, 'name' => $moduleinfo->name, 'instanceid' => $moduleinfo->instance)));
    $event->trigger();
    add_to_log($course->id, $moduleinfo->modulename, "add", "view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->instance}", $moduleinfo->coursemodule);
    $moduleinfo = edit_module_post_actions($moduleinfo, $course);
    return $moduleinfo;
}
开发者ID:helenagarcia90,项目名称:moodle,代码行数:98,代码来源:modlib.php

示例14: emarking_copy_to_cm

/**
 * Creates a copy of the emarking in the database.
 * 
 * @param unknown $original_emarking
 * @return boolean|multitype:unknown NULL Ambigous <boolean, number>
 */
function emarking_copy_to_cm($original_emarking)
{
    require_once $CFG->dirroot . "/course/lib.php";
    require_once $CFG->dirroot . "/mod/emarking/mod_form.php";
    $emarkingmod = $DB->get_record('modules', array('name' => 'emarking'));
    $emarking = new stdClass();
    $emarking = $original_emarking;
    $emarking->id = null;
    $emarking->id = emarking_add_instance($emarking);
    // Add coursemodule
    $mod = new stdClass();
    $mod->course = $emarking->course;
    $mod->module = $emarkingmod->id;
    $mod->instance = $emarking->id;
    $mod->section = 0;
    $mod->visible = 0;
    // Hide the forum
    $mod->visibleold = 0;
    // Hide the forum
    $mod->groupmode = 0;
    $mod->grade = 100;
    if (!($cmid = add_course_module($mod))) {
        return false;
    }
    $sectionid = course_add_cm_to_section($mod->course, $cmid, 0);
    return array($emarking->id, $cmid, $sectionid);
}
开发者ID:pspro360,项目名称:emarking,代码行数:33,代码来源:lib.php

示例15: RWSAAQuiz

function RWSAAQuiz()
{
    global $CFG;
    global $DB;
    global $RWSLB;
    global $RWSUID;
    RWSCMAuth();
    RWSCRAuth();
    RWSCMUSvc();
    RWSCMMaint();
    $r_pm = RWSGSOpt("courseid", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2057");
    }
    $r_cid = intval($r_pm);
    $r_crs = RWSCMUCourse($r_cid, true);
    $r_si = false;
    $r_pm = RWSGSOpt("sectionid", PARAM_ALPHANUM);
    if ($r_pm !== false && strlen($r_pm) > 0) {
        $r_si = intval($r_pm);
    }
    if ($r_si === false) {
        $r_sr = 0;
    } else {
        $r_sec = $DB->get_record("course_sections", array("id" => $r_si));
        if ($r_sec === false) {
            RWSSErr("2071");
        }
        if ($r_sec->course != $r_cid) {
            RWSSErr("2072");
        }
        $r_sr = $r_sec->section;
    }
    $r_pm = RWSGSOpt("name", PARAM_TEXT);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2073");
    }
    $r_qzn = trim(clean_text(strip_tags($r_pm, "<lang><span>")));
    $r_sfl = RWSGSOpt("sfile", RWSPRF);
    if ($r_sfl === false) {
        $r_sn = RWSGSOpt("sname", PARAM_FILE);
        $r_sd = RWSGSOpt("sdata", PARAM_NOTAGS);
        $r_ecd = true;
    } else {
        $r_sn = $r_sfl->filename;
        $r_sd = $r_sfl->filedata;
        $r_ecd = false;
    }
    $r_imp = false;
    if ($r_sd !== false && strlen($r_sd) > 0) {
        if ($r_sn === false || strlen($r_sn) == 0) {
            RWSSErr("2075");
        }
        $r_sn = clean_filename($r_sn);
        $r_imp = true;
    }
    $r_mr = $DB->get_record("modules", array("name" => "quiz"));
    if ($r_mr === false) {
        RWSSErr("2074");
    }
    $r_qiz = new stdClass();
    $r_qiz->name = $r_qzn;
    $r_qiz->section = $r_sr;
    $r_qiz->course = $r_cid;
    $r_qiz->coursemodule = 0;
    $r_qiz->instance = 0;
    $r_qiz->id = 0;
    $r_qiz->modulename = $r_mr->name;
    $r_qiz->module = $r_mr->id;
    $r_qiz->groupmembersonly = 0;
    if (respondusws_floatcompare($CFG->version, 2011120500.0, 2) >= 0) {
        $r_qiz->showdescription = 0;
    }
    $r_cpl = new completion_info($r_crs);
    if ($r_cpl->is_enabled()) {
        $r_qiz->completion = COMPLETION_TRACKING_NONE;
        $r_qiz->completionview = COMPLETION_VIEW_NOT_REQUIRED;
        $r_qiz->completiongradeitemnumber = null;
        $r_qiz->completionexpected = 0;
    }
    if ($CFG->enableavailability) {
        $r_qiz->availablefrom = 0;
        $r_qiz->availableuntil = 0;
        if ($r_qiz->availableuntil) {
            $r_qiz->availableuntil = strtotime("23:59:59", $r_qiz->availableuntil);
        }
        $r_qiz->showavailability = CONDITION_STUDENTVIEW_HIDE;
    }
    RWSSQDefs($r_qiz);
    if ($r_imp) {
        RWSIQSet($r_qiz, $r_sn, $r_sd, $r_ecd);
    }
    if (is_null($r_qiz->quizpassword) && !is_null($r_qiz->password)) {
        $r_qiz->quizpassword = $r_qiz->password;
    }
    $r_qzmi = add_course_module($r_qiz);
    if (!$r_qzmi) {
        RWSSErr("2077");
    }
    $r_qiz->coursemodule = $r_qzmi;
//.........这里部分代码省略.........
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:101,代码来源:servicelib.php


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