本文整理汇总了PHP中calendar_event类的典型用法代码示例。如果您正苦于以下问题:PHP calendar_event类的具体用法?PHP calendar_event怎么用?PHP calendar_event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了calendar_event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set up method.
*/
protected function setUp()
{
global $DB, $CFG;
$this->resetAfterTest();
$this->setTimezone('Australia/Perth');
$user = $this->getDataGenerator()->create_user();
$sub = new stdClass();
$sub->url = '';
$sub->courseid = 0;
$sub->groupid = 0;
$sub->userid = $user->id;
$sub->pollinterval = 0;
$subid = $DB->insert_record('event_subscriptions', $sub, true);
$event = new stdClass();
$event->name = 'Event name';
$event->description = '';
$event->timestart = 1385913700;
// A 2013-12-2 Monday event.
$event->timeduration = 3600;
$event->uuid = 'uuid';
$event->subscriptionid = $subid;
$event->userid = $user->id;
$event->groupid = 0;
$event->courseid = 0;
$event->eventtype = 'user';
$eventobj = calendar_event::create($event, false);
$DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id));
$eventobj->repeatid = $eventobj->id;
$this->event = $eventobj;
}
示例2: 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'));
}
}
示例3: execute
/**
* Do the job.
*/
public function execute()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/calendar/lib.php';
// Get calendars set to sync in.
$starttime = time();
\local_o365\feature\calsync\observers::set_event_import(true);
// Using a direct query here so we don't run into static cache issues.
$laststarttime = $DB->get_record('config_plugins', ['plugin' => 'local_o365', 'name' => 'calsyncinlastrun']);
$laststarttime = !empty($laststarttime) && !empty($laststarttime->value) ? $laststarttime->value : 0;
$httpclient = new \local_o365\httpclient();
$clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
$calsubs = $DB->get_recordset_select('local_o365_calsub', 'syncbehav = ? OR syncbehav = ?', ['in', 'both']);
$calsync = new \local_o365\feature\calsync\main($clientdata, $httpclient);
foreach ($calsubs as $i => $calsub) {
try {
$events = $calsync->get_events($calsub->user_id, $calsub->o365calid, $laststarttime);
if (!empty($events) && is_array($events) && isset($events['value']) && is_array($events['value'])) {
if (!empty($events['value'])) {
foreach ($events['value'] as $i => $event) {
if (!isset($event['Id'])) {
mtrace('Skipped an event because of malformed data.');
continue;
}
$idmapexists = $DB->record_exists('local_o365_calidmap', ['outlookeventid' => $event['Id']]);
if ($idmapexists === false) {
// Create Moodle event.
$eventparams = ['name' => $event['Subject'], 'description' => $event['Body']['Content'], 'eventtype' => $calsub->caltype, 'repeatid' => 0, 'modulename' => 0, 'instance' => 0, 'timestart' => strtotime($event['Start']), 'visible' => 1, 'uuid' => '', 'sequence' => 1];
$end = strtotime($event['End']);
$eventparams['timeduration'] = $end - $eventparams['timestart'];
if ($calsub->caltype === 'user') {
$eventparams['userid'] = $calsub->caltypeid;
}
if ($calsub->caltype === 'course') {
$eventparams['courseid'] = $calsub->caltypeid;
}
$moodleevent = \calendar_event::create($eventparams, false);
if (!empty($moodleevent) && !empty($moodleevent->id)) {
$idmaprec = ['eventid' => $moodleevent->id, 'outlookeventid' => $event['Id'], 'origin' => 'o365', 'userid' => $calsub->user_id];
$DB->insert_record('local_o365_calidmap', (object) $idmaprec);
mtrace('Successfully imported event #' . $moodleevent->id);
}
}
}
} else {
mtrace('No new events to sync in.');
}
} else {
mtrace('Bad response received when fetching events.');
}
} catch (\Exception $e) {
mtrace('Error: ' . $e->getMessage());
}
}
$calsubs->close();
\local_o365\feature\calsync\observers::set_event_import(false);
set_config('calsyncinlastrun', $starttime, 'local_o365');
return true;
}
示例4: 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;
}
示例5: appear_add_instance
function appear_add_instance($data)
{
global $DB, $CFG, $USER;
$appear = new stdClass();
$appear->course = $data->course;
$appear->name = $data->name;
$appear->intro = $data->intro;
$appear->revision = $data->revision;
$appear->timemodified = time();
$appear->timecreated = time();
$appear->timestart = $data->starttime;
$appear->id = $DB->insert_record('appear', $appear);
//creating group
$group = new stdClass();
$group->name = $data->name . '_group_' . $appear->id;
$group->courseid = $data->course;
$group->hidepicture = 0;
$group->id = groups_create_group($group);
// creating event subscription
$sub = new stdClass();
$sub->url = $CFG->wwwroot . '/mod/appear/view.php?id=' . $data->coursemodule;
$sub->courseid = $data->course;
$sub->groupid = $group->id;
$sub->userid = $USER->id;
$sub->pollinterval = 0;
$subid = $DB->insert_record('event_subscriptions', $sub, true);
// creating calender event
$event = new stdClass();
$event->name = $data->name;
$event->description = '';
$event->timestart = $data->starttime;
$event->modulename = 'appear';
$event->timeduration = 3600;
$event->uuid = 'uuid';
$event->subscriptionid = $subid;
$event->userid = $USER->id;
$event->groupid = $group->id;
$event->courseid = $data->course;
$event->eventtype = 'feedbackcloses';
$eventobj = calendar_event::create($event, false);
return $appear->id;
}
示例6: 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;
}
示例7: create
/**
* Creates a new event and returns a calendar_event object
*
* @param object|array $properties An object containing event properties
* @return calendar_event|false The event object or false if it failed
*/
public static function create($properties)
{
if (is_array($properties)) {
$properties = (object) $properties;
}
if (!is_object($properties)) {
throw new coding_exception('When creating an event properties should be either an object or an assoc array');
}
$event = new calendar_event($properties);
if ($event->update($properties)) {
return $event;
} else {
return false;
}
}
示例8: turnitintool_update_partnames
//.........这里部分代码省略.........
} else {
$owner = turnitintool_get_owner($turnitintool->course);
}
if (!($course = turnitintool_get_record('course', 'id', $turnitintool->course))) {
turnitintool_print_error('coursegeterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
exit;
}
$loaderbar = new turnitintool_loaderbarclass(3);
$tii = new turnitintool_commclass(turnitintool_getUID($owner), $owner->firstname, $owner->lastname, $owner->email, 2, $loaderbar);
$tii->startSession();
turnitintool_usersetup($owner, get_string('userprocess', 'turnitintool'), $tii, $loaderbar);
turnitintool_classsetup($course, $owner, get_string('classprocess', 'turnitintool'), $tii, $loaderbar);
if ($tii->getRerror()) {
if ($tii->getAPIunavailable()) {
turnitintool_print_error('apiunavailable', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
} else {
turnitintool_print_error($tii->getRmessage(), NULL, NULL, NULL, __FILE__, __LINE__);
}
exit;
}
$tiipost->cid = turnitintool_getCID($turnitintool->course);
$tiipost->assignid = turnitintool_getAID($post['submitted']);
$tiipost->s_view_report = $turnitintool->studentreports;
$tiipost->max_points = $post['maxmarks'];
$tiipost->anon = $turnitintool->anon;
$tiipost->report_gen_speed = $turnitintool->reportgenspeed;
$tiipost->late_accept_flag = $turnitintool->allowlate;
$tiipost->submit_papers_to = $turnitintool->submitpapersto;
$tiipost->s_paper_check = $turnitintool->spapercheck;
$tiipost->internet_check = $turnitintool->internetcheck;
$tiipost->journal_check = $turnitintool->journalcheck;
// Add in Exclude small matches, biblio, quoted etc 20102009
$tiipost->exclude_biblio = $turnitintool->excludebiblio;
$tiipost->exclude_quoted = $turnitintool->excludequoted;
$tiipost->exclude_value = $turnitintool->excludevalue;
$tiipost->exclude_type = $turnitintool->excludetype;
// Add in the erater settings
$tiipost->erater = $turnitintool->erater;
$tiipost->erater_handbook = $turnitintool->erater_handbook;
$tiipost->erater_dictionary = $turnitintool->erater_dictionary;
$tiipost->erater_spelling = $turnitintool->erater_spelling;
$tiipost->erater_grammar = $turnitintool->erater_grammar;
$tiipost->erater_usage = $turnitintool->erater_usage;
$tiipost->erater_mechanics = $turnitintool->erater_mechanics;
$tiipost->erater_style = $turnitintool->erater_style;
$tiipost->transmatch = $turnitintool->transmatch;
$tiipost->name = $turnitintool->name . ' - ' . $post['partname'] . ' (Moodle ' . $tiipost->assignid . ')';
$tiipost->currentassign = $turnitintool->name . ' - ' . turnitintool_partnamefromnum($post['submitted']) . ' (Moodle ' . $tiipost->assignid . ')';
$tii->createAssignment($tiipost, 'UPDATE', get_string('assignmentupdate', 'turnitintool', ''));
if ($tii->getRerror()) {
if ($tii->getRcode() == TURNITINTOOL_DB_UNIQUEID_ERROR) {
$reason = get_string('assignmentdoesnotexist', 'turnitintool');
} else {
$reason = $tii->getAPIunavailable() ? get_string('apiunavailable', 'turnitintool') : $tii->getRmessage();
}
turnitintool_print_error('<strong>' . get_string('updateerror', 'turnitintool') . '</strong><br />' . $reason);
exit;
}
$part = new stdClass();
$part->id = $post['submitted'];
$part->dtstart = $dtstart;
$part->dtdue = $dtdue;
$part->dtpost = $dtpost;
$part->partname = $post['partname'];
$part->maxmarks = $post['maxmarks'];
$part->deleted = 0;
$event = new stdClass();
$event->timestart = $part->dtdue;
$event->name = $turnitintool->name . ' - ' . $part->partname;
$currentevent = $turnitintool->name . ' - ' . turnitintool_partnamefromnum($post['submitted']);
if (!($dbpart = turnitintool_update_record('turnitintool_parts', $part, false))) {
turnitintool_print_error('partdberror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
}
if ($events = turnitintool_get_record_select('event', "modulename='turnitintool' AND instance = ? AND name = ?", array($turnitintool->id, $currentevent))) {
$event->id = $events->id;
if (method_exists('calendar_event', 'update')) {
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
update_event($event);
}
}
@(include_once $CFG->dirroot . "/lib/gradelib.php");
// Set the view time for Grade Book viewing
if (function_exists('grade_update')) {
$lastpart = turnitintool_get_record('turnitintool_parts', 'turnitintoolid', $turnitintool->id, '', '', '', '', 'max(dtpost)');
$lastpart = current($lastpart);
$params['hidden'] = $lastpart;
grade_update('mod/turnitintool', $turnitintool->course, 'mod', 'turnitintool', $turnitintool->id, 0, NULL, $params);
}
$tii->endSession();
turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=intro');
exit;
} else {
return $notice;
}
} else {
turnitintool_print_error('permissiondeniederror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
}
}
示例9: booking_delete_booking_option
/**
* Deletes a booking option and the associated user answers
* @param $bookingid the booking instance
* @param $optionid the booking option
* @return false if not successful, true on success
*/
function booking_delete_booking_option($booking, $optionid)
{
global $DB;
$event = new stdClass();
if (!($option = $DB->get_record("booking_options", array("id" => $optionid)))) {
return false;
}
$result = true;
$params = array('bookingid' => $booking->id, 'optionid' => $optionid);
$userids = $DB->get_fieldset_select('booking_answers', 'userid', 'bookingid = :bookingid AND optionid = :optionid', $params);
foreach ($userids as $userid) {
booking_check_unenrol_user($option, $booking, $userid);
// Unenrol any users enroled via this option.
}
if (!$DB->delete_records("booking_answers", array("bookingid" => $booking->id, "optionid" => $optionid))) {
$result = false;
}
// Delete calendar entry, if any
$event->id = $DB->get_field('booking_options', 'calendarid', array('id' => $optionid));
if ($event->id > 0) {
// Delete event if exist
$event = calendar_event::load($event->id);
$event->delete(true);
}
if (!$DB->delete_records("booking_options", array("id" => $optionid))) {
$result = false;
}
return $result;
}
示例10: feedback_set_events
/**
* This creates new events given as timeopen and closeopen by $feedback.
*
* @global object
* @param object $feedback
* @return void
*/
function feedback_set_events($feedback) {
global $DB;
// adding the feedback to the eventtable (I have seen this at quiz-module)
$DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$feedback->id));
if (!isset($feedback->coursemodule)) {
$cm = get_coursemodule_from_id('feedback', $feedback->id);
$feedback->coursemodule = $cm->id;
}
// the open-event
if ($feedback->timeopen > 0) {
$event = new stdClass();
$event->name = get_string('start', 'feedback').' '.$feedback->name;
$event->description = format_module_intro('feedback', $feedback, $feedback->coursemodule);
$event->courseid = $feedback->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'feedback';
$event->instance = $feedback->id;
$event->eventtype = 'open';
$event->timestart = $feedback->timeopen;
$event->visible = instance_is_visible('feedback', $feedback);
if ($feedback->timeclose > 0) {
$event->timeduration = ($feedback->timeclose - $feedback->timeopen);
} else {
$event->timeduration = 0;
}
calendar_event::create($event);
}
// the close-event
if ($feedback->timeclose > 0) {
$event = new stdClass();
$event->name = get_string('stop', 'feedback').' '.$feedback->name;
$event->description = format_module_intro('feedback', $feedback, $feedback->coursemodule);
$event->courseid = $feedback->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'feedback';
$event->instance = $feedback->id;
$event->eventtype = 'close';
$event->timestart = $feedback->timeclose;
$event->visible = instance_is_visible('feedback', $feedback);
$event->timeduration = 0;
calendar_event::create($event);
}
}
示例11: update_instance
/**
* Updates a new assignment activity
*
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update the assignment instance and return the id number
* The due date is updated in the calendar
* This is common to all assignment types.
*
* @global object
* @global object
* @param object $assignment The data from the form on mod_form.php
* @return bool success
*/
function update_instance($assignment) {
global $COURSE, $DB;
$assignment->timemodified = time();
$assignment->id = $assignment->instance;
$assignment->courseid = $assignment->course;
$DB->update_record('assignment', $assignment);
if ($assignment->timedue) {
$event = new stdClass();
if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {
$event->name = $assignment->name;
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
$event->timestart = $assignment->timedue;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
$event = new stdClass();
$event->name = $assignment->name;
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
$event->courseid = $assignment->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'assignment';
$event->instance = $assignment->id;
$event->eventtype = 'due';
$event->timestart = $assignment->timedue;
$event->timeduration = 0;
calendar_event::create($event);
}
} else {
$DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id));
}
// get existing grade item
assignment_grade_item_update($assignment);
return true;
}
示例12: delete
/**
* Deletes this lesson from the database
*/
public function delete()
{
global $CFG, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/calendar/lib.php';
$cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
$context = context_module::instance($cm->id);
$DB->delete_records("lesson", array("id" => $this->properties->id));
$DB->delete_records("lesson_pages", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_answers", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_attempts", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_grades", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_timer", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_branch", array("lessonid" => $this->properties->id));
$DB->delete_records("lesson_high_scores", array("lessonid" => $this->properties->id));
if ($events = $DB->get_records('event', array("modulename" => 'lesson', "instance" => $this->properties->id))) {
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
}
// Delete files associated with this module.
$fs = get_file_storage();
$fs->delete_area_files($context->id);
grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted' => 1));
return true;
}
示例13: get_calendar_events
/**
* Get Calendar events
*
* @param array $events A list of events
* @param array $options various options
* @return array Array of event details
* @since Moodle 2.5
*/
public static function get_calendar_events($events = array(), $options = array())
{
global $SITE, $DB, $USER, $CFG;
require_once $CFG->dirroot . "/calendar/lib.php";
// Parameter validation.
$params = self::validate_parameters(self::get_calendar_events_parameters(), array('events' => $events, 'options' => $options));
$funcparam = array('courses' => array(), 'groups' => array());
$hassystemcap = has_capability('moodle/calendar:manageentries', context_system::instance());
$warnings = array();
// Let us findout courses that we can return events from.
if (!$hassystemcap) {
$courses = enrol_get_my_courses();
$courses = array_keys($courses);
foreach ($params['events']['courseids'] as $id) {
if (in_array($id, $courses)) {
$funcparam['courses'][] = $id;
} else {
$warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this course');
}
}
} else {
$courses = $params['events']['courseids'];
$funcparam['courses'] = $courses;
}
// Let us findout groups that we can return events from.
if (!$hassystemcap) {
$groups = groups_get_my_groups();
$groups = array_keys($groups);
foreach ($params['events']['groupids'] as $id) {
if (in_array($id, $groups)) {
$funcparam['groups'][] = $id;
} else {
$warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this group');
}
}
} else {
$groups = $params['events']['groupids'];
$funcparam['groups'] = $groups;
}
// Do we need user events?
if (!empty($params['options']['userevents'])) {
$funcparam['users'] = array($USER->id);
} else {
$funcparam['users'] = false;
}
// Do we need site events?
if (!empty($params['options']['siteevents'])) {
$funcparam['courses'][] = $SITE->id;
}
// We treat 0 and null as no end.
if (empty($params['options']['timeend'])) {
$params['options']['timeend'] = PHP_INT_MAX;
}
$eventlist = calendar_get_events($params['options']['timestart'], $params['options']['timeend'], $funcparam['users'], $funcparam['groups'], $funcparam['courses'], true, $params['options']['ignorehidden']);
// WS expects arrays.
$events = array();
foreach ($eventlist as $id => $event) {
$events[$id] = (array) $event;
}
// We need to get events asked for eventids.
$eventsbyid = calendar_get_events_by_id($params['events']['eventids']);
foreach ($eventsbyid as $eventid => $eventobj) {
$event = (array) $eventobj;
if (isset($events[$eventid])) {
continue;
}
if ($hassystemcap) {
// User can see everything, no further check is needed.
$events[$eventid] = $event;
} else {
if (!empty($eventobj->modulename)) {
$cm = get_coursemodule_from_instance($eventobj->modulename, $eventobj->instance);
if (\core_availability\info_module::is_user_visible($cm, 0, false)) {
$events[$eventid] = $event;
}
} else {
// Can the user actually see this event?
$eventobj = calendar_event::load($eventobj);
if ($eventobj->courseid == $SITE->id || !empty($eventobj->groupid) && in_array($eventobj->groupid, $groups) || !empty($eventobj->courseid) && in_array($eventobj->courseid, $courses) || $USER->id == $eventobj->userid || calendar_edit_event_allowed($eventid)) {
$events[$eventid] = $event;
} else {
$warnings[] = array('item' => $eventid, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to view this event');
}
}
}
}
return array('events' => $events, 'warnings' => $warnings);
}
示例14: 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();
}
}
示例15: 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);
}