本文整理汇总了PHP中calendar_event::format_external_text方法的典型用法代码示例。如果您正苦于以下问题:PHP calendar_event::format_external_text方法的具体用法?PHP calendar_event::format_external_text怎么用?PHP calendar_event::format_external_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar_event
的用法示例。
在下文中一共展示了calendar_event::format_external_text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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('id');
$courses = array_keys($courses);
foreach ($params['events']['courseids'] as $id) {
try {
$context = context_course::instance($id);
self::validate_context($context);
$funcparam['courses'][] = $id;
} catch (Exception $e) {
$warnings[] = array('item' => 'course', 'itemid' => $id, 'warningcode' => 'nopermissions', 'message' => 'No access rights in course context ' . $e->getMessage() . $e->getTraceAsString());
}
}
} 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;
}
// Event list does not check visibility and permissions, we'll check that later.
$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();
// We need to get events asked for eventids.
if ($eventsbyid = calendar_get_events_by_id($params['events']['eventids'])) {
$eventlist += $eventsbyid;
}
foreach ($eventlist as $eventid => $eventobj) {
$event = (array) $eventobj;
// Description formatting.
$calendareventobj = new calendar_event($event);
list($event['description'], $event['format']) = $calendareventobj->format_external_text();
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);
}