本文整理汇总了PHP中calendar_edit_event_allowed函数的典型用法代码示例。如果您正苦于以下问题:PHP calendar_edit_event_allowed函数的具体用法?PHP calendar_edit_event_allowed怎么用?PHP calendar_edit_event_allowed使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了calendar_edit_event_allowed函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calendar_print_event
function calendar_print_event($event)
{
global $CFG, $USER;
static $strftimetime;
$event = calendar_add_event_metadata($event);
echo '<a name="event_' . $event->id . '"></a><table class="event" cellspacing="0">';
echo '<tr><td class="picture">';
if (!empty($event->icon)) {
echo $event->icon;
} else {
print_spacer(16, 16);
}
echo '</td>';
echo '<td class="topic">';
if (!empty($event->referer)) {
echo '<div class="referer">' . $event->referer . '</div>';
} else {
echo '<div class="name">' . $event->name . "</div>";
}
if (!empty($event->courselink)) {
echo '<div class="course">' . $event->courselink . ' </div>';
}
if (!empty($event->time)) {
echo '<span class="date">' . $event->time . '</span>';
} else {
echo '<span class="date">' . calendar_time_representation($event->timestart) . '</span>';
}
echo '</td></tr>';
echo '<tr><td class="side"> </td>';
if (isset($event->cssclass)) {
echo '<td class="description ' . $event->cssclass . '">';
} else {
echo '<td class="description">';
}
echo format_text($event->description, FORMAT_HTML);
if (calendar_edit_event_allowed($event)) {
echo '<div class="commands">';
$calendarcourseid = '';
if (!empty($event->calendarcourseid)) {
$calendarcourseid = '&course=' . $event->calendarcourseid;
}
if (empty($event->cmid)) {
$editlink = CALENDAR_URL . 'event.php?action=edit&id=' . $event->id . $calendarcourseid;
$deletelink = CALENDAR_URL . 'event.php?action=delete&id=' . $event->id . $calendarcourseid;
} else {
$editlink = $CFG->wwwroot . '/course/mod.php?update=' . $event->cmid . '&return=true&sesskey=' . $USER->sesskey;
$deletelink = '';
// deleting activities directly from calendar is dangerous/confusing - see MDL-11843
}
echo ' <a href="' . $editlink . '"><img
src="' . $CFG->pixpath . '/t/edit.gif" alt="' . get_string('tt_editevent', 'calendar') . '"
title="' . get_string('tt_editevent', 'calendar') . '" /></a>';
if ($deletelink) {
echo ' <a href="' . $deletelink . '"><img
src="' . $CFG->pixpath . '/t/delete.gif" alt="' . get_string('tt_deleteevent', 'calendar') . '"
title="' . get_string('tt_deleteevent', 'calendar') . '" /></a>';
}
echo '</div>';
}
echo '</td></tr></table>';
}
示例2: 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);
}
示例3: event
/**
* Displays an event
*
* @param calendar_event $event
* @param bool $showactions
* @return string
*/
public function event(calendar_event $event, $showactions = true)
{
global $CFG;
$event = calendar_add_event_metadata($event);
$context = $event->context;
$anchor = html_writer::tag('a', '', array('name' => 'event_' . $event->id));
$table = new html_table();
$table->attributes = array('class' => 'event', 'cellspacing' => '0');
$table->data = array(0 => new html_table_row(), 1 => new html_table_row());
if (!empty($event->icon)) {
$table->data[0]->cells[0] = new html_table_cell($anchor . $event->icon);
} else {
$table->data[0]->cells[0] = new html_table_cell($anchor . $this->output->spacer(array('height' => 16, 'width' => 16, 'br' => true)));
}
$table->data[0]->cells[0]->attributes['class'] .= ' picture';
$table->data[0]->cells[1] = new html_table_cell();
$table->data[0]->cells[1]->attributes['class'] .= ' topic';
if (!empty($event->referer)) {
$table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class' => 'referer'));
} else {
$table->data[0]->cells[1]->text .= html_writer::tag('div', format_string($event->name, false, array('context' => $context)), array('class' => 'name'));
}
if (!empty($event->courselink)) {
$table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
}
// Show subscription source if needed.
if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
if (!empty($event->subscription->url)) {
$source = html_writer::link($event->subscription->url, get_string('subsource', 'calendar', $event->subscription));
} else {
// File based ical.
$source = get_string('subsource', 'calendar', $event->subscription);
}
$table->data[0]->cells[1]->text .= html_writer::tag('div', $source, array('class' => 'subscription'));
}
if (!empty($event->time)) {
$table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class' => 'date'));
} else {
$table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class' => 'date'));
}
$table->data[1]->cells[0] = new html_table_cell(' ');
$table->data[1]->cells[0]->attributes['class'] .= 'side';
$table->data[1]->cells[1] = new html_table_cell(format_text($event->description, $event->format, array('context' => $context)));
$table->data[1]->cells[1]->attributes['class'] .= ' description';
if (isset($event->cssclass)) {
$table->data[1]->cells[1]->attributes['class'] .= ' ' . $event->cssclass;
}
if (calendar_edit_event_allowed($event) && $showactions) {
if (empty($event->cmid)) {
$editlink = new moodle_url(CALENDAR_URL . 'event.php', array('action' => 'edit', 'id' => $event->id));
$deletelink = new moodle_url(CALENDAR_URL . 'delete.php', array('id' => $event->id));
if (!empty($event->calendarcourseid)) {
$editlink->param('course', $event->calendarcourseid);
$deletelink->param('course', $event->calendarcourseid);
}
} else {
$editlink = new moodle_url('/course/mod.php', array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey()));
$deletelink = null;
}
$commands = html_writer::start_tag('div', array('class' => 'commands'));
$commands .= html_writer::start_tag('a', array('href' => $editlink));
$commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'alt' => get_string('tt_editevent', 'calendar'), 'title' => get_string('tt_editevent', 'calendar')));
$commands .= html_writer::end_tag('a');
if ($deletelink != null) {
$commands .= html_writer::start_tag('a', array('href' => $deletelink));
$commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/delete'), 'alt' => get_string('tt_deleteevent', 'calendar'), 'title' => get_string('tt_deleteevent', 'calendar')));
$commands .= html_writer::end_tag('a');
}
$commands .= html_writer::end_tag('div');
$table->data[1]->cells[1]->text .= $commands;
}
return html_writer::table($table);
}
示例4: 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;
}
}
示例5: get_record
$event = get_record('event', 'id', $eventid);
if ($event === false) {
error('Invalid event');
}
if (!calendar_edit_event_allowed($event)) {
error('You are not authorized to do this');
}
break;
case 'edit':
$title = get_string('editevent', 'calendar');
$event = get_record('event', 'id', $eventid);
$repeats = optional_param('repeats', 0, PARAM_INT);
if ($event === false) {
error('Invalid event');
}
if (!calendar_edit_event_allowed($event)) {
error('You are not authorized to do this');
}
if ($form = data_submitted() and confirm_sesskey()) {
$form->name = clean_param(strip_tags($form->name, '<lang><span>'), PARAM_CLEAN);
$form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin);
if ($form->duration == 1) {
$form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart;
if ($form->timeduration < 0) {
$form->timeduration = 0;
}
} else {
if ($form->duration == 2) {
$form->timeduration = $form->minutes * MINSECS;
} else {
$form->timeduration = 0;
示例6: event
/**
* Displays an event
*
* @param calendar_event $event
* @param bool $showactions
* @return string
*/
public function event(calendar_event $event, $showactions = true)
{
global $CFG;
$event = calendar_add_event_metadata($event);
$context = $event->context;
$output = '';
if (!empty($event->icon)) {
$output .= $event->icon;
} else {
$output .= $this->output->spacer(array('height' => 16, 'width' => 16));
}
if (!empty($event->referer)) {
$output .= $this->output->heading($event->referer, 3, array('class' => 'referer'));
} else {
$output .= $this->output->heading(format_string($event->name, false, array('context' => $context)), 3, array('class' => 'name'));
}
if (!empty($event->courselink)) {
$output .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
}
// Show subscription source if needed.
if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
if (!empty($event->subscription->url)) {
$source = html_writer::link($event->subscription->url, get_string('subsource', 'calendar', $event->subscription));
} else {
// File based ical.
$source = get_string('subsource', 'calendar', $event->subscription);
}
$output .= html_writer::tag('div', $source, array('class' => 'subscription'));
}
if (!empty($event->time)) {
$output .= html_writer::tag('span', $event->time, array('class' => 'date'));
} else {
$output .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class' => 'date'));
}
$eventdetailshtml = '';
$eventdetailsclasses = '';
$eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context));
$eventdetailsclasses .= 'description';
if (isset($event->cssclass)) {
$eventdetailsclasses .= ' ' . $event->cssclass;
}
$output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses));
if (calendar_edit_event_allowed($event) && $showactions) {
if (empty($event->cmid)) {
$editlink = new moodle_url(CALENDAR_URL . 'event.php', array('action' => 'edit', 'id' => $event->id));
$deletelink = new moodle_url(CALENDAR_URL . 'delete.php', array('id' => $event->id));
if (!empty($event->calendarcourseid)) {
$editlink->param('course', $event->calendarcourseid);
$deletelink->param('course', $event->calendarcourseid);
}
} else {
$editlink = new moodle_url('/course/mod.php', array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey()));
$deletelink = null;
}
$commands = html_writer::start_tag('div', array('class' => 'commands'));
$commands .= html_writer::start_tag('a', array('href' => $editlink));
$commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'alt' => get_string('tt_editevent', 'calendar'), 'title' => get_string('tt_editevent', 'calendar')));
$commands .= html_writer::end_tag('a');
if ($deletelink != null) {
$commands .= html_writer::start_tag('a', array('href' => $deletelink));
$commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/delete'), 'alt' => get_string('tt_deleteevent', 'calendar'), 'title' => get_string('tt_deleteevent', 'calendar')));
$commands .= html_writer::end_tag('a');
}
$commands .= html_writer::end_tag('div');
$output .= $commands;
}
return html_writer::tag('div', $output, array('class' => 'event', 'id' => 'event_' . $event->id));
}