本文整理汇总了PHP中calendar_event::load方法的典型用法代码示例。如果您正苦于以下问题:PHP calendar_event::load方法的具体用法?PHP calendar_event::load怎么用?PHP calendar_event::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar_event
的用法示例。
在下文中一共展示了calendar_event::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_event_timedue
/**
*
*/
public static function update_event_timedue($data)
{
global $DB;
if (!empty($data->timedue)) {
$event = new \stdClass();
$event->name = $data->name;
$event->description = format_module_intro('dataform', $data, $data->coursemodule);
$event->timestart = $data->timedue;
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'dataform', 'instance' => $data->id))) {
$calendarevent = \calendar_event::load($event->id);
$calendarevent->update($event);
} else {
$event->courseid = $data->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'dataform';
$event->instance = $data->id;
$event->eventtype = 'due';
$event->timeduration = 0;
$event->visible = $DB->get_field('course_modules', 'visible', array('module' => $data->module, 'instance' => $data->id));
\calendar_event::create($event);
}
} else {
$DB->delete_records('event', array('modulename' => 'dataform', 'instance' => $data->id, 'eventtype' => 'due'));
}
}
示例2: xmldb_workshop_upgrade
/**
* Performs upgrade of the database structure and data
*
* Workshop supports upgrades from version 1.9.0 and higher only. During 1.9 > 2.0 upgrade,
* there are significant database changes.
*
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_workshop_upgrade($oldversion)
{
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
if ($oldversion < 2012033100) {
// add the field 'phaseswitchassessment' to the 'workshop' table
$table = new xmldb_table('workshop');
$field = new xmldb_field('phaseswitchassessment', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'assessmentend');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2012033100, 'workshop');
}
/**
* Remove all workshop calendar events
*/
if ($oldversion < 2012041700) {
require_once $CFG->dirroot . '/calendar/lib.php';
$events = $DB->get_records('event', array('modulename' => 'workshop'));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
upgrade_mod_savepoint(true, 2012041700, 'workshop');
}
/**
* Recreate all workshop calendar events
*/
if ($oldversion < 2012041701) {
require_once dirname(dirname(__FILE__)) . '/lib.php';
$sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,\n w.submissionend, w.assessmentstart, w.assessmentend,\n cm.id AS cmid\n FROM {workshop} w\n JOIN {modules} m ON m.name = 'workshop'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $workshop) {
$cmid = $workshop->cmid;
unset($workshop->cmid);
workshop_calendar_update($workshop, $cmid);
}
$rs->close();
upgrade_mod_savepoint(true, 2012041701, 'workshop');
}
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
return true;
}
示例3: geogebra_after_add_or_update
function geogebra_after_add_or_update($geogebra, $mform)
{
global $DB;
if ($mform->get_data()->filetype === GEOGEBRA_FILE_TYPE_LOCAL) {
$filename = geogebra_set_mainfile($geogebra);
$geogebra->url = $filename;
$result = $DB->update_record('geogebra', $geogebra);
}
if ($geogebra->timedue) {
$event = new stdClass();
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'geogebra', 'instance' => $geogebra->id))) {
$event->name = $geogebra->name;
$event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
$event->timestart = $geogebra->timedue;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
$event = new stdClass();
$event->name = $geogebra->name;
$event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
$event->courseid = $geogebra->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'geogebra';
$event->instance = $geogebra->id;
$event->eventtype = 'due';
$event->timestart = $geogebra->timedue;
$event->timeduration = 0;
calendar_event::create($event);
}
} else {
$DB->delete_records('event', array('modulename' => 'geogebra', 'instance' => $geogebra->id));
}
// get existing grade item
geogebra_grade_item_update($geogebra);
return true;
}
示例4: update_event
/**
* Call this function to update an event in the calendar table
* the event will be identified by the id field of the $event object.
*
* @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
* @return bool Success
* @deprecated please calendar_event->update() instead.
*/
function update_event($event)
{
global $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
$event = (object) $event;
$calendarevent = calendar_event::load($event->id);
return $calendarevent->update($event);
}
示例5: workshop_calendar_update
/**
* Updates the calendar events associated to the given workshop
*
* @param stdClass $workshop the workshop instance record
* @param int $cmid course module id
*/
function workshop_calendar_update(stdClass $workshop, $cmid) {
global $DB;
// get the currently registered events so that we can re-use their ids
$currentevents = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
// the common properties for all events
$base = new stdClass();
$base->description = format_module_intro('workshop', $workshop, $cmid, false);
$base->courseid = $workshop->course;
$base->groupid = 0;
$base->userid = 0;
$base->modulename = 'workshop';
$base->eventtype = 'pluginname';
$base->instance = $workshop->id;
$base->visible = instance_is_visible('workshop', $workshop);
$base->timeduration = 0;
if ($workshop->submissionstart) {
$event = clone($base);
$event->name = get_string('submissionstartevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->submissionstart;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// update() will reuse a db record if the id field is set
$eventobj = new calendar_event($event);
$eventobj->update($event, false);
}
if ($workshop->submissionend) {
$event = clone($base);
$event->name = get_string('submissionendevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->submissionend;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// update() will reuse a db record if the id field is set
$eventobj = new calendar_event($event);
$eventobj->update($event, false);
}
if ($workshop->assessmentstart) {
$event = clone($base);
$event->name = get_string('assessmentstartevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->assessmentstart;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// update() will reuse a db record if the id field is set
$eventobj = new calendar_event($event);
$eventobj->update($event, false);
}
if ($workshop->assessmentend) {
$event = clone($base);
$event->name = get_string('assessmentendevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->assessmentend;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// update() will reuse a db record if the id field is set
$eventobj = new calendar_event($event);
$eventobj->update($event, false);
}
// delete any leftover events
foreach ($currentevents as $oldevent) {
$oldevent = calendar_event::load($oldevent);
$oldevent->delete();
}
}
示例6: chat_update_chat_times
/**
* Updates chat records so that the next chat time is correct
*
* @global object
* @param int $chatid
* @return void
*/
function chat_update_chat_times($chatid = 0)
{
// Updates chat records so that the next chat time is correct.
global $DB;
$timenow = time();
$params = array('timenow' => $timenow, 'chatid' => $chatid);
if ($chatid) {
if (!($chats[] = $DB->get_record_select("chat", "id = :chatid AND chattime <= :timenow AND schedule > 0", $params))) {
return;
}
} else {
if (!($chats = $DB->get_records_select("chat", "chattime <= :timenow AND schedule > 0", $params))) {
return;
}
}
foreach ($chats as $chat) {
switch ($chat->schedule) {
case 1:
// Single event - turn off schedule and disable.
$chat->chattime = 0;
$chat->schedule = 0;
break;
case 2:
// Repeat daily.
while ($chat->chattime <= $timenow) {
$chat->chattime += 24 * 3600;
}
break;
case 3:
// Repeat weekly.
while ($chat->chattime <= $timenow) {
$chat->chattime += 7 * 24 * 3600;
}
break;
}
$DB->update_record("chat", $chat);
$event = new stdClass();
// Update calendar too.
$cond = "modulename='chat' AND instance = :chatid AND timestart <> :chattime";
$params = array('chattime' => $chat->chattime, 'chatid' => $chatid);
if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) {
$event->timestart = $chat->chattime;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event, false);
}
}
}
示例7: simplecertificate_send_event
/**
* Update the event if it exists, else create
*/
function simplecertificate_send_event($certificate)
{
global $DB, $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
if ($event = $DB->get_record('event', array('modulename' => 'simplecertificate', 'instance' => $certificate->id))) {
$calendarevent = calendar_event::load($event->id);
$calendarevent->name = $certificate->name;
$calendarevent->update($calendarevent);
} else {
$event = new stdClass();
$event->name = $certificate->name;
$event->description = '';
$event->courseid = $certificate->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'simplecertificate';
$event->instance = $certificate->id;
calendar_event::create($event);
}
}
示例8: update
//.........这里部分代码省略.........
$this->properties->groupid = 0;
$this->properties->userid = $USER->id;
break;
case 'course':
$this->properties->groupid = 0;
$this->properties->userid = $USER->id;
break;
case 'group':
$this->properties->userid = $USER->id;
break;
default:
// Ewww we should NEVER get here, but just incase we do lets
// fail gracefully
$usingeditor = false;
break;
}
// If we are actually using the editor, we recalculate the context because some default values
// were set when calculate_context() was called from the constructor.
if ($usingeditor) {
$this->properties->context = $this->calculate_context($this->properties);
$this->editorcontext = $this->properties->context;
}
$editor = $this->properties->description;
$this->properties->format = $this->properties->description['format'];
$this->properties->description = $this->properties->description['text'];
}
// Insert the event into the database
$this->properties->id = $DB->insert_record('event', $this->properties);
if ($usingeditor) {
$this->properties->description = file_save_draft_area_files($editor['itemid'], $this->editorcontext->id, 'calendar', 'event_description', $this->properties->id, $this->editoroptions, $editor['text'], $this->editoroptions['forcehttps']);
$DB->set_field('event', 'description', $this->properties->description, array('id' => $this->properties->id));
}
// Log the event entry.
add_to_log($this->properties->courseid, 'calendar', 'add', 'event.php?action=edit&id=' . $this->properties->id, $this->properties->name);
$repeatedids = array();
if (!empty($this->properties->repeat)) {
$this->properties->repeatid = $this->properties->id;
$DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id' => $this->properties->id));
$eventcopy = clone $this->properties;
unset($eventcopy->id);
for ($i = 1; $i < $eventcopy->repeats; $i++) {
$eventcopy->timestart = $eventcopy->timestart + WEEKSECS + dst_offset_on($eventcopy->timestart) - dst_offset_on($eventcopy->timestart + WEEKSECS);
// Get the event id for the log record.
$eventcopyid = $DB->insert_record('event', $eventcopy);
// If the context has been set delete all associated files
if ($usingeditor) {
$fs = get_file_storage();
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
foreach ($files as $file) {
$fs->create_file_from_storedfile(array('itemid' => $eventcopyid), $file);
}
}
$repeatedids[] = $eventcopyid;
// Log the event entry.
add_to_log($eventcopy->courseid, 'calendar', 'add', 'event.php?action=edit&id=' . $eventcopyid, $eventcopy->name);
}
}
// Hook for tracking added events
self::calendar_event_hook('add_event', array($this->properties, $repeatedids));
return true;
} else {
if ($checkcapability) {
if (!calendar_edit_event_allowed($this->properties)) {
print_error('nopermissiontoupdatecalendar');
}
}
if ($usingeditor) {
if ($this->editorcontext !== null) {
$this->properties->description = file_save_draft_area_files($this->properties->description['itemid'], $this->editorcontext->id, 'calendar', 'event_description', $this->properties->id, $this->editoroptions, $this->properties->description['text'], $this->editoroptions['forcehttps']);
} else {
$this->properties->format = $this->properties->description['format'];
$this->properties->description = $this->properties->description['text'];
}
}
$event = $DB->get_record('event', array('id' => $this->properties->id));
$updaterepeated = !empty($this->properties->repeatid) && !empty($this->properties->repeateditall);
if ($updaterepeated) {
// Update all
if ($this->properties->timestart != $event->timestart) {
$timestartoffset = $this->properties->timestart - $event->timestart;
$sql = "UPDATE {event}\n SET name = ?,\n description = ?,\n timestart = timestart + ?,\n timeduration = ?,\n timemodified = ?\n WHERE repeatid = ?";
$params = array($this->properties->name, $this->properties->description, $timestartoffset, $this->properties->timeduration, time(), $event->repeatid);
} else {
$sql = "UPDATE {event} SET name = ?, description = ?, timeduration = ?, timemodified = ? WHERE repeatid = ?";
$params = array($this->properties->name, $this->properties->description, $this->properties->timeduration, time(), $event->repeatid);
}
$DB->execute($sql, $params);
// Log the event update.
add_to_log($this->properties->courseid, 'calendar', 'edit all', 'event.php?action=edit&id=' . $this->properties->id, $this->properties->name);
} else {
$DB->update_record('event', $this->properties);
$event = calendar_event::load($this->properties->id);
$this->properties = $event->properties();
add_to_log($this->properties->courseid, 'calendar', 'edit', 'event.php?action=edit&id=' . $this->properties->id, $this->properties->name);
}
// Hook for tracking event updates
self::calendar_event_hook('update_event', array($this->properties, $updaterepeated));
return true;
}
}
示例9: update_calendar
/**
* Update the calendar entries for this assignment.
*
* @param int $coursemoduleid - Required to pass this in because it might
* not exist in the database yet.
* @return bool
*/
public function update_calendar($coursemoduleid)
{
global $DB, $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
// Special case for add_instance as the coursemodule has not been set yet.
$instance = $this->get_instance();
if ($instance->duedate) {
$event = new stdClass();
$params = array('modulename' => 'assign', 'instance' => $instance->id);
$event->id = $DB->get_field('event', 'id', $params);
$event->name = $instance->name;
$event->timestart = $instance->duedate;
// Convert the links to pluginfile. It is a bit hacky but at this stage the files
// might not have been saved in the module area yet.
$intro = $instance->intro;
if ($draftid = file_get_submitted_draft_itemid('introeditor')) {
$intro = file_rewrite_urls_to_pluginfile($intro, $draftid);
}
// We need to remove the links to files as the calendar is not ready
// to support module events with file areas.
$intro = strip_pluginfile_content($intro);
if ($this->show_intro()) {
$event->description = array('text' => $intro, 'format' => $instance->introformat);
} else {
$event->description = array('text' => '', 'format' => $instance->introformat);
}
if ($event->id) {
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
unset($event->id);
$event->courseid = $instance->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'assign';
$event->instance = $instance->id;
$event->eventtype = 'due';
$event->timeduration = 0;
calendar_event::create($event);
}
} else {
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id));
}
}
示例10: lesson_process_post_save
/**
* Runs any processes that must be run
* after a lesson insert/update
*
* @global object
* @param object $lesson Lesson form data
* @return void
**/
function lesson_process_post_save(&$lesson)
{
global $DB, $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
require_once $CFG->dirroot . '/mod/lesson/locallib.php';
if ($events = $DB->get_records('event', array('modulename' => 'lesson', 'instance' => $lesson->id))) {
foreach ($events as $event) {
$event = calendar_event::load($event->id);
$event->delete();
}
}
$event = new stdClass();
$event->description = $lesson->name;
$event->courseid = $lesson->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'lesson';
$event->instance = $lesson->id;
$event->eventtype = 'open';
$event->timestart = $lesson->available;
$event->visible = instance_is_visible('lesson', $lesson);
$event->timeduration = $lesson->deadline - $lesson->available;
if ($lesson->deadline and $lesson->available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
// Single event for the whole lesson.
$event->name = $lesson->name;
calendar_event::create(clone $event);
} else {
// Separate start and end events.
$event->timeduration = 0;
if ($lesson->available) {
$event->name = $lesson->name . ' (' . get_string('lessonopens', 'lesson') . ')';
calendar_event::create(clone $event);
}
if ($lesson->deadline) {
$event->name = $lesson->name . ' (' . get_string('lessoncloses', 'lesson') . ')';
$event->timestart = $lesson->deadline;
$event->eventtype = 'close';
calendar_event::create(clone $event);
}
}
}
示例11: course_delete_module
/**
* This function will handles the whole deletion process of a module. This includes calling
* the modules delete_instance function, deleting files, events, grades, conditional data,
* the data in the course_module and course_sections table and adding a module deletion
* event to the DB.
*
* @param int $cmid the course module id
* @since 2.5
*/
function course_delete_module($cmid)
{
global $CFG, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/blog/lib.php';
require_once $CFG->dirroot . '/calendar/lib.php';
// Get the course module.
if (!($cm = $DB->get_record('course_modules', array('id' => $cmid)))) {
return true;
}
// Get the module context.
$modcontext = context_module::instance($cm->id);
// Get the course module name.
$modulename = $DB->get_field('modules', 'name', array('id' => $cm->module), MUST_EXIST);
// Get the file location of the delete_instance function for this module.
$modlib = "{$CFG->dirroot}/mod/{$modulename}/lib.php";
// Include the file required to call the delete_instance function for this module.
if (file_exists($modlib)) {
require_once $modlib;
} else {
throw new moodle_exception('cannotdeletemodulemissinglib', '', '', null, "Cannot delete this module as the file mod/{$modulename}/lib.php is missing.");
}
$deleteinstancefunction = $modulename . '_delete_instance';
// Ensure the delete_instance function exists for this module.
if (!function_exists($deleteinstancefunction)) {
throw new moodle_exception('cannotdeletemodulemissingfunc', '', '', null, "Cannot delete this module as the function {$modulename}_delete_instance is missing in mod/{$modulename}/lib.php.");
}
// Call the delete_instance function, if it returns false throw an exception.
if (!$deleteinstancefunction($cm->instance)) {
throw new moodle_exception('cannotdeletemoduleinstance', '', '', null, "Cannot delete the module {$modulename} (instance).");
}
// Remove all module files in case modules forget to do that.
$fs = get_file_storage();
$fs->delete_area_files($modcontext->id);
// Delete events from calendar.
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
foreach ($events as $event) {
$calendarevent = calendar_event::load($event->id);
$calendarevent->delete();
}
}
// Delete grade items, outcome items and grades attached to modules.
if ($grade_items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $cm->instance, 'courseid' => $cm->course))) {
foreach ($grade_items as $grade_item) {
$grade_item->delete('moddelete');
}
}
// Delete completion and availability data; it is better to do this even if the
// features are not turned on, in case they were turned on previously (these will be
// very quick on an empty table).
$DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
$DB->delete_records('course_modules_availability', array('coursemoduleid' => $cm->id));
$DB->delete_records('course_modules_avail_fields', array('coursemoduleid' => $cm->id));
$DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
// Delete the context.
context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
// Delete the module from the course_modules table.
$DB->delete_records('course_modules', array('id' => $cm->id));
// Delete module from that section.
if (!delete_mod_from_section($cm->id, $cm->section)) {
throw new moodle_exception('cannotdeletemodulefromsection', '', '', null, "Cannot delete the module {$modulename} (instance) from section.");
}
// Trigger event for course module delete action.
$event = \core\event\course_module_deleted::create(array('courseid' => $cm->course, 'context' => $modcontext, 'objectid' => $cm->id, 'other' => array('modulename' => $modulename, 'instanceid' => $cm->instance)));
$event->add_record_snapshot('course_modules', $cm);
$event->trigger();
rebuild_course_cache($cm->course, true);
}
示例12: adobeconnect_delete_instance
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id Id of the module instance
* @return boolean Success/Failure
*/
function adobeconnect_delete_instance($id)
{
global $DB;
$param = array('id' => $id);
if (!($adobeconnect = $DB->get_record('adobeconnect', $param))) {
return false;
}
$result = true;
// Remove meeting from Adobe connect server
$param = array('instanceid' => $adobeconnect->id);
$adbmeetings = $DB->get_records('adobeconnect_meeting_groups', $param);
if (!empty($adbmeetings)) {
$aconnect = aconnect_login();
foreach ($adbmeetings as $meeting) {
// Update calendar event
$param = array('courseid' => $adobeconnect->course, 'instance' => $adobeconnect->id, 'groupid' => $meeting->groupid, 'modulename' => 'adobeconnect');
$eventid = $DB->get_field('event', 'id', $param);
if (!empty($eventid)) {
$event = calendar_event::load($eventid);
$event->delete();
}
aconnect_remove_meeting($aconnect, $meeting->meetingscoid);
}
aconnect_logout($aconnect);
}
$param = array('id' => $adobeconnect->id);
$result &= $DB->delete_records('adobeconnect', $param);
$param = array('instanceid' => $adobeconnect->id);
$result &= $DB->delete_records('adobeconnect_meeting_groups', $param);
return $result;
}
示例13: offlinequiz_update_events
/**
* This function updates the events associated to the offlinequiz.
* If $override is non-zero, then it updates only the events
* associated with the specified override.
*
* @uses OFFLINEQUIZ_MAX_EVENT_LENGTH
* @param object $offlinequiz the offlinequiz object.
* @param object optional $override limit to a specific override
*/
function offlinequiz_update_events($offlinequiz)
{
global $DB, $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
// Load the old events relating to this offlinequiz.
$conds = array('modulename' => 'offlinequiz', 'instance' => $offlinequiz->id);
if (!empty($override)) {
// Only load events for this override.
$conds['groupid'] = isset($override->groupid) ? $override->groupid : 0;
$conds['userid'] = isset($override->userid) ? $override->userid : 0;
}
$oldevents = $DB->get_records('event', $conds);
$groupid = 0;
$userid = 0;
$timeopen = $offlinequiz->timeopen;
$timeclose = $offlinequiz->timeclose;
if ($offlinequiz->time) {
$timeopen = $offlinequiz->time;
}
// Only add open/close events if they differ from the offlinequiz default.
if (!empty($offlinequiz->coursemodule)) {
$cmid = $offlinequiz->coursemodule;
} else {
$cmid = get_coursemodule_from_instance('offlinequiz', $offlinequiz->id, $offlinequiz->course)->id;
}
if (!empty($timeopen)) {
$event = new stdClass();
$event->name = $offlinequiz->name;
$event->description = format_module_intro('offlinequiz', $offlinequiz, $cmid);
// Events module won't show user events when the courseid is nonzero.
$event->courseid = $userid ? 0 : $offlinequiz->course;
$event->groupid = $groupid;
$event->userid = $userid;
$event->modulename = 'offlinequiz';
$event->instance = $offlinequiz->id;
$event->timestart = $timeopen;
$event->timeduration = max($timeclose - $timeopen, 0);
$event->visible = instance_is_visible('offlinequiz', $offlinequiz);
if ($timeopen == $offlinequiz->time) {
$event->name = $offlinequiz->name;
}
if ($timeopen == $offlinequiz->timeopen) {
$event->name = $offlinequiz->name . ' (' . get_string('reportstarts', 'offlinequiz') . ')';
}
calendar_event::create($event);
}
// Delete any leftover events.
foreach ($oldevents as $badevent) {
$badevent = calendar_event::load($badevent);
$badevent->delete();
}
}
示例14: xmldb_workshop_upgrade
/**
* Performs upgrade of the database structure and data
*
* Workshop supports upgrades from version 1.9.0 and higher only. During 1.9 > 2.0 upgrade,
* there are significant database changes.
*
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_workshop_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
if ($oldversion < 2012033100) {
// add the field 'phaseswitchassessment' to the 'workshop' table
$table = new xmldb_table('workshop');
$field = new xmldb_field('phaseswitchassessment', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'assessmentend');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2012033100, 'workshop');
}
/**
* Remove all workshop calendar events
*/
if ($oldversion < 2012041700) {
require_once($CFG->dirroot . '/calendar/lib.php');
$events = $DB->get_records('event', array('modulename' => 'workshop'));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
upgrade_mod_savepoint(true, 2012041700, 'workshop');
}
/**
* Recreate all workshop calendar events
*/
if ($oldversion < 2012041701) {
require_once(dirname(dirname(__FILE__)) . '/lib.php');
$sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,
w.submissionend, w.assessmentstart, w.assessmentend,
cm.id AS cmid
FROM {workshop} w
JOIN {modules} m ON m.name = 'workshop'
JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $workshop) {
$cmid = $workshop->cmid;
unset($workshop->cmid);
workshop_calendar_update($workshop, $cmid);
}
$rs->close();
upgrade_mod_savepoint(true, 2012041701, 'workshop');
}
// Moodle v2.3.0 release upgrade line
/**
* Add new fields conclusion and conclusionformat
*/
if ($oldversion < 2012102400) {
$table = new xmldb_table('workshop');
$field = new xmldb_field('conclusion', XMLDB_TYPE_TEXT, null, null, null, null, null, 'phaseswitchassessment');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('conclusionformat', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '1', 'conclusion');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2012102400, 'workshop');
}
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
/**
* Add overall feedback related fields into the workshop table.
*/
if ($oldversion < 2013032500) {
$table = new xmldb_table('workshop');
$field = new xmldb_field('overallfeedbackmode', XMLDB_TYPE_INTEGER, '3', null, null, null, '1', 'conclusionformat');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('overallfeedbackfiles', XMLDB_TYPE_INTEGER, '3', null, null, null, '0', 'overallfeedbackmode');
//.........这里部分代码省略.........
示例15: delete_override
/**
* Deletes a lesson override from the database and clears any corresponding calendar events
*
* @param int $overrideid The id of the override being deleted
* @return bool true on success
*/
public function delete_override($overrideid)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/calendar/lib.php';
$cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
$override = $DB->get_record('lesson_overrides', array('id' => $overrideid), '*', MUST_EXIST);
// Delete the events.
$conds = array('modulename' => 'lesson', 'instance' => $this->properties->id);
if (isset($override->userid)) {
$conds['userid'] = $override->userid;
} else {
$conds['groupid'] = $override->groupid;
}
$events = $DB->get_records('event', $conds);
foreach ($events as $event) {
$eventold = calendar_event::load($event);
$eventold->delete();
}
$DB->delete_records('lesson_overrides', array('id' => $overrideid));
// Set the common parameters for one of the events we will be triggering.
$params = array('objectid' => $override->id, 'context' => context_module::instance($cm->id), 'other' => array('lessonid' => $override->lessonid));
// Determine which override deleted event to fire.
if (!empty($override->userid)) {
$params['relateduserid'] = $override->userid;
$event = \mod_lesson\event\user_override_deleted::create($params);
} else {
$params['other']['groupid'] = $override->groupid;
$event = \mod_lesson\event\group_override_deleted::create($params);
}
// Trigger the override deleted event.
$event->add_record_snapshot('lesson_overrides', $override);
$event->trigger();
return true;
}