本文整理汇总了PHP中add_mod_to_section函数的典型用法代码示例。如果您正苦于以下问题:PHP add_mod_to_section函数的具体用法?PHP add_mod_to_section怎么用?PHP add_mod_to_section使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_mod_to_section函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make_forumng
function make_forumng($courseid, $starttime, $discussions, $posts, $readpercent, $readusers, &$userids, $subscribepercent, $ratingpercent)
{
$section = get_record('course_sections', 'course', $courseid, 'section', 0);
forum_utils::start_transaction();
// Create course modules record
$mod = new StdClass();
$mod->course = $courseid;
$mod->module = get_field('modules', 'id', 'name', 'forumng');
$mod->section = $section->section;
// was $section->id; logical but incorrect!
$mod->added = $starttime;
$mod->visible = 1;
// course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice.
// Note: This is unbelievable!!! $mod->section MUST BE section number (not id)
// Adds course_module with section number, add_mod_to_section uses
// section number (& course id) to get section id, which is returned
// course module record then updated to replace section number by id!!!
if (!($mod->coursemodule = add_course_module($mod))) {
throw new Exception("Could not add a new course module");
}
if (!($sectionid = add_mod_to_section($mod))) {
throw new Exception("Could not add the new course module to that section");
}
// Create forum object
$forumng = new StdClass();
static $index = 0;
$index++;
$forumng->name = 'Perf test ' . date('Ymd H:j', $starttime) . ' ' . $index;
$forumng->course = $courseid;
$forumng->section = $section;
$forumng->cmidnumber = $mod->coursemodule;
if (!($forumng->id = forumng_add_instance($forumng))) {
throw new forum_exception('Failed to add forum');
}
// Mark cm object as owning it
$updatemod = new stdClass();
$updatemod->id = $mod->coursemodule;
$updatemod->instance = $forumng->id;
$updatemod->section = $sectionid;
forum_utils::update_record('course_modules', $updatemod);
// Make it be random users included in the forum
shuffle($userids);
// OK, forum is created. Let's make discussions
$forum = forum::get_from_id($forumng->id, forum::CLONE_DIRECT);
$count = my_random($discussions);
for ($i = 0; $i < $count; $i++) {
make_discussion($forum, $posts, my_random_percentage($readpercent) ? $readusers : 0, $userids, $ratingpercent);
}
// Add subscribe users
set_time_limit(200);
for ($i = 0; $i < $readusers; $i++) {
if (my_random_percentage($subscribepercent)) {
$forum->subscribe($userids[$i]);
}
}
forum_utils::finish_transaction();
}
示例2: moveto_module
/**
* Move the module object $mod to the specified $section
* If $beforemod exists then that is the module
* before which $modid should be inserted
* All parameters are objects
*/
function moveto_module($mod, $section, $beforemod = NULL)
{
global $DB, $OUTPUT;
/// Remove original module from original section
if (!delete_mod_from_section($mod->id, $mod->section)) {
echo $OUTPUT->notification("Could not delete module from existing section");
}
/// Update module itself if necessary
if ($mod->section != $section->id) {
$mod->section = $section->id;
$DB->update_record("course_modules", $mod);
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
}
}
/// Add the module into the new section
$mod->course = $section->course;
$mod->section = $section->section;
// need relative reference
$mod->coursemodule = $mod->id;
if (!add_mod_to_section($mod, $beforemod)) {
return false;
}
return true;
}
示例3: forum_convert_to_roles
/**
* Converts a forum to use the Roles System
*
* @global object
* @global object
* @param object $forum a forum object with the same attributes as a record
* from the forum database table
* @param int $forummodid the id of the forum module, from the modules table
* @param array $teacherroles array of roles that have archetype teacher
* @param array $studentroles array of roles that have archetype student
* @param array $guestroles array of roles that have archetype guest
* @param int $cmid the course_module id for this forum instance
* @return boolean forum was converted or not
*/
function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
$studentroles=array(), $guestroles=array(), $cmid=NULL) {
global $CFG, $DB, $OUTPUT;
if (!isset($forum->open) && !isset($forum->assesspublic)) {
// We assume that this forum has already been converted to use the
// Roles System. Columns forum.open and forum.assesspublic get dropped
// once the forum module has been upgraded to use Roles.
return false;
}
if ($forum->type == 'teacher') {
// Teacher forums should be converted to normal forums that
// use the Roles System to implement the old behavior.
// Note:
// Seems that teacher forums were never backed up in 1.6 since they
// didn't have an entry in the course_modules table.
require_once($CFG->dirroot.'/course/lib.php');
if ($DB->count_records('forum_discussions', array('forum' => $forum->id)) == 0) {
// Delete empty teacher forums.
$DB->delete_records('forum', array('id' => $forum->id));
} else {
// Create a course module for the forum and assign it to
// section 0 in the course.
$mod = new stdClass();
$mod->course = $forum->course;
$mod->module = $forummodid;
$mod->instance = $forum->id;
$mod->section = 0;
$mod->visible = 0; // Hide the forum
$mod->visibleold = 0; // Hide the forum
$mod->groupmode = 0;
if (!$cmid = add_course_module($mod)) {
print_error('cannotcreateinstanceforteacher', 'forum');
} else {
$mod->coursemodule = $cmid;
if (!$sectionid = add_mod_to_section($mod)) {
print_error('cannotaddteacherforumto', 'forum');
} else {
$DB->set_field('course_modules', 'section', $sectionid, array('id' => $cmid));
}
}
// Change the forum type to general.
$forum->type = 'general';
$DB->update_record('forum', $forum);
$context = get_context_instance(CONTEXT_MODULE, $cmid);
// Create overrides for default student and guest roles (prevent).
foreach ($studentroles as $studentrole) {
assign_capability('mod/forum:viewdiscussion', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:viewhiddentimedposts', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:startdiscussion', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:replypost', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:viewrating', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:viewanyrating', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:rate', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:createattachment', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:deleteownpost', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:deleteanypost', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:splitdiscussions', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:movediscussions', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:editanypost', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:viewqandawithoutposting', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:viewsubscribers', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:managesubscriptions', CAP_PREVENT, $studentrole->id, $context->id);
assign_capability('mod/forum:postwithoutthrottling', CAP_PREVENT, $studentrole->id, $context->id);
}
foreach ($guestroles as $guestrole) {
assign_capability('mod/forum:viewdiscussion', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:viewhiddentimedposts', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:startdiscussion', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:replypost', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:viewrating', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:viewanyrating', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:rate', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:createattachment', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:deleteownpost', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:deleteanypost', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:splitdiscussions', CAP_PREVENT, $guestrole->id, $context->id);
assign_capability('mod/forum:movediscussions', CAP_PREVENT, $guestrole->id, $context->id);
//.........这里部分代码省略.........
示例4: link_to_gdoc
//.........这里部分代码省略.........
$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;
}
示例5: add_file
public function add_file($section, $name, $path, $display = 0)
{
global $DB, $CFG, $USER;
$section = (int) $section;
$display = (int) $display;
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/mod/resource/lib.php';
require_once $CFG->dirroot . '/mod/resource/locallib.php';
$params = self::validate_parameters(self::add_file_parameters(), array('section' => $section, 'name' => $name, 'path' => $path, 'display' => $display));
$section = $DB->get_record('course_sections', array('id' => $section), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
self::require_access($course->id);
// finally create the file item
// first add course_module record because we need the context
$newcm = new stdClass();
$newcm->course = $course->id;
$newcm->module = $DB->get_field('modules', 'id', array('name' => 'resource'));
// not known yet, will be updated later (this is similar to restore code)
$newcm->instance = 0;
$newcm->section = $params['section'];
$newcm->visible = 1;
$newcm->groupmode = 0;
$newcm->groupingid = 0;
$newcm->groupmembersonly = 0;
if (!($coursemodule = add_course_module($newcm))) {
throw new invalid_parameter_exception('Error creating course module');
}
$config = get_config('resource');
$module = new stdClass();
$module->course = $course->id;
$module->name = format_string($params['name']);
$module->intro = '<p></p>';
$module->introformat = 1;
$module->coursemodule = $coursemodule;
if (!$display) {
$module->display = $config->display;
} else {
$module->display = $display;
}
$module->popupwidth = $config->popupwidth;
$module->popupheight = $config->popupheight;
$module->printheading = $config->printheading;
$module->printintro = $config->printintro;
// 'Show size' support only from Moodle 2.3 / OU moodle April 2012
if (isset($config->showsize)) {
$module->showsize = $config->showsize;
$module->showtype = $config->showtype;
}
$module->filterfiles = $config->filterfiles;
$module->section = $section->section;
//check $params['path'] and create files based on that and attach to $module->files
//now check $path and obtain $filename and $filepath
$contextuser = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();
$module->files = 0;
file_prepare_draft_area($module->files, null, null, null, null);
$fileinfo = array('contextid' => $contextuser->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $module->files, 'filepath' => '/', 'filename' => basename($params['path']), 'timecreated' => time(), 'timemodified' => time(), 'mimetype' => mimeinfo('type', $path), 'userid' => $USER->id);
if (strpos($params['path'], '://') === false) {
//this is a path
if (!file_exists($params['path'])) {
throw new invalid_parameter_exception('Error accessing filepath - file may not exist.');
}
$fs->create_file_from_pathname($fileinfo, $params['path']);
} else {
//this is a URL - download the file first.
$content = download_file_content($params['path']);
if ($content === false) {
throw new invalid_parameter_exception('Error accessing file - url may not exist.');
}
$fs->create_file_from_string($fileinfo, $content);
}
$module->instance = resource_add_instance($module, array());
$DB->set_field('course_modules', 'instance', $module->instance, array('id' => $coursemodule));
add_mod_to_section($module);
rebuild_course_cache($course->id, true);
return array('id' => $coursemodule);
}
示例6: while
$quizdata->preferredbehaviour = 'deferredfeedback';
$quizdata->return = 0;
if ($oldquizinstancearr = $DB->get_records_sql("SELECT * FROM {quiz} WHERE course= ? and name= ?", array($courseid, $quizzestoadd_['title']))) {
while (list($key, $oldquizinstanceid) = each($oldquizinstancearr)) {
if ($oldquizinsection = $DB->get_record_sql("SELECT * FROM {course_modules} WHERE course= ? and module= ? and instance= ? and visible=1 ", array($courseid, $module->id, $oldquizinstanceid->id))) {
set_coursemodule_visible($oldquizinsection->id, 0);
}
}
}
$quizdata->questions = '0,';
$quizdata->id = $DB->insert_record("quiz", $quizdata);
$quizdata->instance = $quizdata->id;
if (!($quizdata->coursemodule = add_course_module($quizdata))) {
error("Could not add a new course module");
}
if (!($sectionid = add_mod_to_section($quizdata))) {
error("Could not add the new course module to that section");
}
if (!$DB->set_field("course_modules", "section", $sectionid, array("id" => $quizdata->coursemodule))) {
error("Could not update the course module with the correct section");
}
if (!isset($quizdata->visible)) {
// We get the section's visible field status
$quizdata->visible = $DB->get_field("course_sections", "visible", "id", $sectionid);
}
set_coursemodule_visible($quizdata->coursemodule, $quizdata->visible);
// Trigger mod_updated event with information about this module.
$eventdata = new stdClass();
$eventdata->modulename = $quizdata->modulename;
$eventdata->name = $quizdata->name;
$eventdata->cmid = $quizdata->coursemodule;
示例7: 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;
}
示例8: moveto_module
/**
* Move the module object $mod to the specified $section
* If $beforemod exists then that is the module
* before which $modid should be inserted
* All parameters are objects
*/
function moveto_module($mod, $section, $beforemod=NULL) {
global $DB, $OUTPUT;
/// Remove original module from original section
if (! delete_mod_from_section($mod->id, $mod->section)) {
echo $OUTPUT->notification("Could not delete module from existing section");
}
/// Update module itself if necessary
// If moving to a hidden section then hide module.
if ($mod->section != $section->id) {
if (!$section->visible && $mod->visible) {
// Set this in the object because it is sent as a response to ajax calls.
set_coursemodule_visible($mod->id, 0, true);
$mod->visible = 0;
}
if ($section->visible && !$mod->visible) {
set_coursemodule_visible($mod->id, 1, true);
// Set this in the object because it is sent as a response to ajax calls.
$mod->visible = $mod->visibleold;
}
}
/// Add the module into the new section
$mod->course = $section->course;
$mod->section = $section->section; // need relative reference
$mod->coursemodule = $mod->id;
if (! add_mod_to_section($mod, $beforemod)) {
return false;
}
return true;
}
示例9: tao_create_lp
//.........这里部分代码省略.........
$pagetype = 'course-view';
// first create the summary page
$page = new stdClass();
$page->nameone = get_string('lpsummarypagetitle', 'local');
$page->nametwo = get_string('lpsummarypagetitle', 'local');
$page->courseid = $newcourse->id;
$page->display = 1;
$page->showbuttons = 3;
$summarypageid = insert_record('format_page', $page);
// add the standard blocks for a summary page
$instanceid = tao_add_learningpath_block('tao_learning_path_summary', $pageid, $pagetype, "Learning Stations");
if (!empty($instanceid)) {
tao_add_learningpath_pageitem($summarypageid, $instanceid);
}
// now the station pages
$items = $rafl->get_lp_item_structure(0);
// todo don't hardcode this parameter
foreach ($items as $item) {
// check for existing station/pie, if not there insert as a format_page
$sql = "SELECT id FROM {$CFG->prefix}format_page WHERE courseid = {$newcourse->id} AND rafl_item = {$item->question_item_id}";
$exists = get_records_sql($sql);
if (empty($exists)) {
// add the format page
$page = new stdClass();
$page->nameone = $item->title;
$page->nametwo = $item->title;
$page->courseid = $newcourse->id;
$page->display = 1;
$page->showbuttons = 3;
$page->parent = $summarypageid;
$page->rafl_item = $item->question_item_id;
$formatpageid = insert_record('format_page', $page);
// add the title block
$instanceid = tao_add_learningpath_block('html', $pageid, $pagetype, '', '<h1>' . $item->title . '</h1>');
if (!empty($instanceid)) {
tao_add_learningpath_pageitem($formatpageid, $instanceid);
}
}
}
// now add the question blocks
$country_item_id = $rafl->get_rafl_item_id_by_country('uk');
$items = $rafl->get_lp_item_structure($country_item_id);
// todo find a better way to pass this parameter
foreach ($items as $item) {
// db integrity - at least check for existing station/pie
$sql = "SELECT id FROM {$CFG->prefix}format_page WHERE courseid = {$newcourse->id} AND rafl_item = {$item->pie_item_id}";
$formatpage = get_record_sql($sql);
if (!empty($formatpage)) {
// insert question as a block and format_page item on this page
$instanceid = tao_add_learningpath_block('tao_lp_qa', $pageid, $pagetype, $item->title);
// create a new page item that links to the instance
if (!empty($instanceid)) {
tao_add_learningpath_pageitem($formatpage->id, $instanceid, $item->question_item_id);
}
} else {
debugging("pie {$item->pie_item_id} is not in the database");
}
}
// add the rafl module to the course
$mod = new object();
$mod->course = $newcourse->id;
$mod->name = 'RAFL Authoring Module';
$mod->intro = 'RAFL Authoring Module';
$instanceid = rafl_add_instance($mod);
if (!($module = get_record("modules", "name", 'rafl'))) {
error("This module type doesn't exist");
}
if (!($cs = get_record("course_sections", "section", 0, "course", $newcourse->id))) {
error("This course section doesn't exist");
}
$cm->section = 0;
//$cs->id;
$cm->course = $newcourse->id;
$cm->module = $module->id;
$cm->modulename = $module->name;
$cm->instance = $instanceid;
// connect to course
if (!($cm->coursemodule = add_course_module($cm))) {
error("Could not add a new course module");
}
$sectionid = add_mod_to_section($cm);
set_field("course_modules", "section", $sectionid, "id", $cm->coursemodule);
// create rafl_share
$rafl->create_share($newcourse->id, $author->id);
// if valid
// set course status
if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from RAFL module", $newcourse)) {
error('could not update status');
}
// ensure we can use the course right after creating it
// this means trigger a reload of accessinfo...
mark_context_dirty($context->path);
$author->raflmode = 1;
rebuild_course_cache($newcourse->id);
// redirect to participants page
return $newcourse->id;
} else {
error("invalid authoring mode");
}
}
示例10: liveclassroom_update_instance
function liveclassroom_update_instance($liveclassroom)
{
global $CFG;
// / Given an object containing all the necessary data,
// / (defined by the form in mod.html) this function
// / will update an existing instance with new data.
$liveclassroom->timemodified = time();
$liveclassroom->type = $liveclassroom->resource;
$liveclassroom->id = $liveclassroom->instance;
$api = new LCAction(null, $CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword, $CFG->dataroot);
// May have to add extra stuff in here #
$roomname = $api->getRoomName($liveclassroom->type);
// Need to update the section
// get the course_module instance linked to the liveclassroom instance
if (!($cm = get_coursemodule_from_instance("liveclassroom", $liveclassroom->id, $liveclassroom->course))) {
wimba_add_log(WIMBA_ERROR, WC, "Problem to update the instance : " . $liveclassroom->id);
error("Course Module ID was incorrect");
}
$old_section = $cm->section;
// Find the right section in the course_section
$section = get_record("course_sections", "id", $cm->section);
// delete in the course section
if (!delete_mod_from_section($cm->id, $cm->section)) {
$result = false;
error("Could not delete the {$mod->modulename} from that section");
}
// update the course module section
if (!($sectionid = add_mod_to_section($liveclassroom))) {
wimba_add_log(WIMBA_ERROR, WC, "Problem to update the instance : " . $liveclassroom->id);
error("Could not add the new course module to that section");
}
// update the course modules
if (!set_field("course_modules", "section", $sectionid, "id", $cm->id)) {
wimba_add_log(WIMBA_ERROR, WC, "Problem to update the instance : " . $liveclassroom->id);
error("Could not update the course module with the correct section");
}
if (!isset($liveclassroom->section)) {
$liveclassroom->section = 0;
}
$instanceNumber = update_record("liveclassroom", $liveclassroom);
if ($instanceNumber != false && isset($liveclassroom->calendar_event) && $liveclassroom->calendar_event) {
// no problem
liveclassroom_addCalendarEvent($liveclassroom, $liveclassroom->instance, $roomname);
} else {
liveclassroom_deleteCalendarEvent($liveclassroom->instance);
}
return $instanceNumber;
}
示例11: unset
unset($data->id);
$data->page = array('text' => $contents, 'itemid' => false);
if ($type == 'text') {
$data->page['format'] = FORMAT_PLAIN;
} else {
$data->page['format'] = FORMAT_HTML;
}
$data->printheading = true;
$data->printintro = false;
$data->instance = page_add_instance($data, $data);
}
}
// Update the 'instance' field for the course module
$DB->set_field('course_modules', 'instance', $data->instance, array('id' => $data->coursemodule));
// Add the resource to the correct section
$sectionid = add_mod_to_section($data);
$DB->set_field('course_modules', 'section', $sectionid, array('id' => $data->coursemodule));
set_coursemodule_visible($data->coursemodule, $data->visible);
// START UCLA MOD - CCLE-2769 - Drag and drop file upload block on M2
// default drag/drop uploads to be private
$groupingid = false;
if (class_exists('PublicPrivate_Course') && PublicPrivate_Site::is_enabled()) {
$publicprivate_course = new PublicPrivate_Course($course->id);
if ($publicprivate_course->is_activated()) {
$pp = new PublicPrivate_Module($data->coursemodule);
$pp->enable();
$groupingid = $publicprivate_course->get_grouping();
}
}
// END UCLA MOD - CCLE-2769
// Trigger mod_created event with information about this module.
示例12: duplicate_course_module
/**
* Create a duplicate course module record so we can create the upgraded
* assign module alongside the old assignment module.
*
* @param stdClass $cm The old course module record
* @param int $moduleid The id of the new assign module
* @param int $newinstanceid The id of the new instance of the assign module
* @return mixed stdClass|bool The new course module record or FALSE
*/
private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid)
{
global $DB, $CFG;
$newcm = new stdClass();
$newcm->course = $cm->course;
$newcm->module = $moduleid;
$newcm->instance = $newinstanceid;
$newcm->visible = $cm->visible;
$newcm->section = $cm->section;
$newcm->score = $cm->score;
$newcm->indent = $cm->indent;
$newcm->groupmode = $cm->groupmode;
$newcm->groupingid = $cm->groupingid;
$newcm->groupmembersonly = $cm->groupmembersonly;
$newcm->completion = $cm->completion;
$newcm->completiongradeitemnumber = $cm->completiongradeitemnumber;
$newcm->completionview = $cm->completionview;
$newcm->completionexpected = $cm->completionexpected;
if (!empty($CFG->enableavailability)) {
$newcm->availablefrom = $cm->availablefrom;
$newcm->availableuntil = $cm->availableuntil;
$newcm->showavailability = $cm->showavailability;
}
$newcm->showdescription = $cm->showdescription;
$newcmid = add_course_module($newcm);
$newcm = get_coursemodule_from_id('', $newcmid, $cm->course);
if (!$newcm) {
return false;
}
$section = $DB->get_record("course_sections", array("id" => $newcm->section));
if (!$section) {
return false;
}
$mod = new stdClass();
$mod->course = $newcm->course;
$mod->section = $section->section;
$mod->coursemodule = $newcm->id;
$mod->id = $newcm->id;
$newcm->section = add_mod_to_section($mod, $cm);
// make sure visibility is set correctly (in particular in calendar)
// note: allow them to set it even without moodle/course:activityvisibility
set_coursemodule_visible($newcm->id, $newcm->visible);
return $newcm;
}
示例13: verbose
$module->add = $moduledata->name;
$module->cmidnumber = '';
$add_instance_function = $moduledata->name . '_add_instance';
if (function_exists($add_instance_function)) {
$module->instance = $add_instance_function($module, '');
} else {
verbose("Function {$add_instance_function} does not exist!");
if (!$settings['ignore-errors']) {
die;
}
}
$section = get_course_section($i, $courseid);
$module->section = $section->id;
$module->coursemodule = add_course_module($module);
$module->section = $i;
add_mod_to_section($module);
$module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, '');
verbose("A {$moduledata->name} module was added to section {$i} (id {$module->section}) of course {$courseid}.");
rebuild_course_cache($courseid);
if ($moduledata->name == 'quiz') {
$quiz_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule));
$quiz = $DB->get_record('quiz', array('id' => $quiz_instance));
$quiz->instance = $quiz_instance;
$quizzes[] = $quiz;
} elseif ($moduledata->name == 'assignment') {
$assignment_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule));
$assignment = $DB->get_record('assignment', array('id' => $assignment_instance));
$assignment->instance = $assignment_instance;
$assignments[] = $assignment;
} elseif ($moduledata->name == 'glossary') {
$glossary_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule));
示例14: insert_set_definition
/**
* @desc Read in the set and turn it into a quiz.
* @param array $set The set data.
* @return bool
*/
function insert_set_definition($set)
{
global $COURSE;
//create new quiz object
$quiz = new stdClass();
$quiz->name = $set['name'];
if (isset($set['openDate'])) {
$quiz->timeopen = $set['openDate'];
}
if (isset($set['dueDate'])) {
$quiz->timeclose = $set['dueDate'];
}
$quiz->intro = "WeBWorK Problem Set";
$quiz->timelimitenable = 0;
$quiz->quizpassword = "";
$quiz->course = $COURSE->id;
$quiz->adaptive = 1;
$quiz->attemptonlast = 1;
$quiz->shuffleanswers = 1;
$quiz->feedbackboundarycount = -1;
//review variables
$quiz->responsesimmediately = 1;
$quiz->responsesopen = 1;
$quiz->responsesclosed = 1;
$quiz->scoreimmediately = 1;
$quiz->scoreopen = 1;
$quiz->scoreclosed = 1;
$quiz->feedbackimmediately = 1;
$quiz->feedbackopen = 1;
$quiz->feedbackclosed = 1;
$quiz->answersimmediately = 1;
$quiz->answersopen = 1;
$quiz->answersclosed = 1;
$quiz->solutionsimmediately = 1;
$quiz->solutionsopen = 1;
$quiz->solutionsclosed = 1;
$quiz->generalfeedbackimmediately = 1;
$quiz->generalfeedbackopen = 1;
$quiz->generalfeedbackclosed = 1;
$quiz->questionsperpage = 1;
$quiz->grade = 10;
//duplicate check
$dup = get_field('quiz', 'id', 'course', $quiz->course, 'name', $quiz->name);
if ($dup) {
echo "Already found a quiz {$quiz->name}. <br>";
return false;
}
$result = quiz_add_instance($quiz);
if ($result == false) {
echo "Error on DB addition<br>";
return false;
}
$quizid = $result;
$numquestions = $this->insert_set_definition_questions($set['problemList'], $quizid);
$quiz->sumgrades = $numquestions;
$quiz->id = $quizid;
$quiz->questions = get_field('quiz', 'questions', 'id', $quizid);
update_record('quiz', $quiz);
echo "Created Quiz (" . $quiz->name . ")<br>";
flush();
//Creating module
$mod = new stdClass();
$mod->course = $COURSE->id;
$mod->section = 1;
$mod->module = $this->quizmodnum;
$mod->instance = $quizid;
$mod->modulename = 'quiz';
if (!isset($mod->name) || trim($mod->name) == '') {
$mod->name = get_string("modulename", $mod->modulename);
}
if (!isset($mod->groupmode)) {
// to deal with pre-1.5 modules
$mod->groupmode = $COURSE->groupmode;
/// Default groupmode the same as course
}
if (!($mod->coursemodule = add_course_module($mod))) {
echo "Error: Could not add a new course module<br>";
return false;
}
if (!($sectionid = add_mod_to_section($mod))) {
echo "Error: Could not add the new course module to that section<br>";
return false;
}
if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
echo "Error: Could not update the course module with the correct section<br>";
return false;
}
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);
return true;
}
示例15: moveto_module
function moveto_module($mod, $section, $beforemod = NULL)
{
/// All parameters are objects
/// Move the module object $mod to the specified $section
/// If $beforemod exists then that is the module
/// before which $modid should be inserted
/// Remove original module from original section
if (!delete_mod_from_section($mod->id, $mod->section)) {
notify("Could not delete module from existing section");
}
/// Update module itself if necessary
if ($mod->section != $section->id) {
$mod->section = $section->id;
if (!update_record("course_modules", $mod)) {
return false;
}
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
}
}
/// Add the module into the new section
$mod->course = $section->course;
$mod->section = $section->section;
// need relative reference
$mod->coursemodule = $mod->id;
if (!add_mod_to_section($mod, $beforemod)) {
return false;
}
return true;
}