<?php /** * Elgg event_calendar group profile content * * @package event_calendar * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Kevin Jardine <*****@*****.**> * @copyright Radagast Solutions 2008 * @link http://radagast.biz/ * */ elgg_load_library('elgg:event_calendar'); $page_owner_entity = elgg_get_page_owner_entity(); if (event_calendar_activated_for_group($page_owner_entity)) { $num = 4; // Get the upcoming events $start_date = time(); // now $end_date = $start_date + 60 * 60 * 24 * 365 * 2; // maximum is two years from now $events = event_calendar_get_events_between($start_date, $end_date, false, $num, 0, elgg_get_page_owner_guid()); // If there are any events to view, view them if (is_array($events) && sizeof($events) > 0) { foreach ($events as $event) { echo elgg_view("object/event_calendar", array('entity' => $event['event'])); } } }
$start_date = get_input('start_date', date('Y-n-j')); $end_date = get_input('end_date', date('Y-n-j')); $start_ts = strtotime($start_date . " " . date_default_timezone_get()); $end_ts = strtotime($end_date . " " . date_default_timezone_get()) + 60 * 60 * 24 - 1; $user_guid = elgg_get_logged_in_user_guid(); switch ($filter) { case 'mine': $events = event_calendar_get_events_for_user_between($start_ts, $end_ts, false, 0, 0, $user_guid, $container_guid, $region); break; case 'friends': $events = event_calendar_get_events_for_friends_between($start_ts, $end_ts, false, 0, 0, $user_guid, $container_guid, $region); break; case 'site': $container_guid = 0; case 'all': $events = event_calendar_get_events_between($start_ts, $end_ts, false, 0, 0, $container_guid, $region); break; default: // see if we're exporting just a single event $events = false; $event = get_entity($filter); if (elgg_instanceof($event, 'object', 'event_calendar')) { $events = array(array('event' => $event)); } break; } if (!$events) { register_error(elgg_echo('event_calendar:no_events_found')); forward(REFERER); } $events = event_calendar_flatten_event_structure($events);
function event_calendar_generate_listing_params($page_type, $container_guid, $original_start_date, $display_mode, $filter, $region = '-') { $event_calendar_listing_format = elgg_get_plugin_setting('listing_format', 'event_calendar'); $event_calendar_spots_display = trim(elgg_get_plugin_setting('spots_display', 'event_calendar')); $event_calendar_first_date = trim(elgg_get_plugin_setting('first_date', 'event_calendar')); $event_calendar_last_date = trim(elgg_get_plugin_setting('last_date', 'event_calendar')); if (!$original_start_date) { $original_start_date = date('Y-m-d'); } if ($event_calendar_first_date && $original_start_date < $event_calendar_first_date) { $original_start_date = $event_calendar_first_date; } if ($event_calendar_last_date && $original_start_date > $event_calendar_last_date) { $original_start_date = $event_calendar_first_date; } if ($event_calendar_listing_format == 'paged') { $start_ts = strtotime($original_start_date); $start_date = $original_start_date; if ($event_calendar_last_date) { $end_ts = strtotime($event_calendar_last_date); } else { // set to a large number $end_ts = 2000000000; } $mode = 'paged'; } else { // the default interval is one month $day = 60 * 60 * 24; $week = 7 * $day; $month = 31 * $day; $mode = trim($display_mode); if (!$mode) { $mode = 'month'; } if ($mode == "day") { $start_date = $original_start_date; $end_date = $start_date; $start_ts = strtotime($start_date); $end_ts = strtotime($end_date) + $day - 1; } else { if ($mode == "week") { // need to adjust start_date to be the beginning of the week $start_ts = strtotime($original_start_date); $start_ts -= date("w", $start_ts) * $day; $end_ts = $start_ts + 6 * $day; $start_date = date('Y-m-d', $start_ts); $end_date = date('Y-m-d', $end_ts); } else { $start_ts = strtotime($original_start_date); $month = date('m', $start_ts); $year = date('Y', $start_ts); $start_date = $year . '-' . $month . '-1'; $end_date = $year . '-' . $month . '-' . getLastDayOfMonth($month, $year); } } if ($event_calendar_first_date && $start_date < $event_calendar_first_date) { $start_date = $event_calendar_first_date; } if ($event_calendar_last_date && $end_date > $event_calendar_last_date) { $end_date = $event_calendar_last_date; } $start_ts = strtotime($start_date); if ($mode == "day") { $end_ts = strtotime($end_date) + $day - 1; $subtitle = elgg_echo('event_calendar:day_label') . ': ' . date('j F Y', strtotime($start_date)); } else { if ($mode == "week") { // KJ - fix for end date bug //$end_ts = $start_ts + 6*$day; $end_ts = $start_ts + 7 * $day; $subtitle = elgg_echo('event_calendar:week_label') . ': ' . date('j F', $start_ts) . ' - ' . date('j F Y', $end_ts); } else { // KJ - fix for end date bug //$end_ts = strtotime($end_date); $end_ts = strtotime($end_date) + 24 * 60 * 60 - 1; $subtitle = date('F Y', $start_ts); } } } $current_user_guid = elgg_get_logged_in_user_guid(); $access_status = elgg_get_ignore_access(); if ($page_type == 'owner') { $container = get_entity($container_guid); if (elgg_instanceof($container, 'user')) { $auth_token = get_input('auth_token'); if ($auth_token) { $secret_key = event_calendar_get_secret_key(); if ($secret_key && $auth_token === sha1($container->username . $secret_key)) { elgg_set_ignore_access(TRUE); } } if ($container->canEdit()) { $user_guid = $container_guid; $group_guid = 0; } else { register_error('event_calendar:owner:permissions_error'); forward(); exit; } } else { register_error('event_calendar:owner:permissions_error'); forward(); exit; } } else { $user_guid = $current_user_guid; $group_guid = $container_guid; } $offset = get_input('offset'); $limit = get_input('limit', 15); if ($event_calendar_spots_display == 'yes') { if (!$filter) { $filter = 'open'; } } else { if (!$filter) { $filter = 'all'; } } if ($filter == 'all') { $count = event_calendar_get_events_between($start_ts, $end_ts, true, $limit, $offset, $container_guid, $region); $events = event_calendar_get_events_between($start_ts, $end_ts, false, $limit, $offset, $container_guid, $region); } else { if ($filter == 'open') { $count = event_calendar_get_open_events_between($start_ts, $end_ts, true, $limit, $offset, $container_guid, $region); $events = event_calendar_get_open_events_between($start_ts, $end_ts, false, $limit, $offset, $container_guid, $region); } else { if ($filter == 'friends') { $count = event_calendar_get_events_for_friends_between($start_ts, $end_ts, true, $limit, $offset, $user_guid, $container_guid, $region); $events = event_calendar_get_events_for_friends_between($start_ts, $end_ts, false, $limit, $offset, $user_guid, $container_guid, $region); } else { if ($filter == 'mine') { $count = event_calendar_get_events_for_user_between2($start_ts, $end_ts, true, $limit, $offset, $user_guid, $container_guid, $region); $events = event_calendar_get_events_for_user_between2($start_ts, $end_ts, false, $limit, $offset, $user_guid, $container_guid, $region); } } } } $vars = array('original_start_date' => $original_start_date, 'start_date' => $start_date, 'end_date' => $end_date, 'first_date' => $event_calendar_first_date, 'last_date' => $event_calendar_last_date, 'mode' => $mode, 'events' => $events, 'count' => $count, 'offset' => $offset, 'limit' => $limit, 'group_guid' => $group_guid, 'filter' => $filter, 'region' => $region, 'listing_format' => $event_calendar_listing_format); $content = elgg_view('event_calendar/show_events', $vars); if ($page_type == 'owner') { $filter_override = ''; } else { $filter_override = elgg_view('event_calendar/filter_menu', $vars); } if ($event_calendar_listing_format == 'paged') { $title = elgg_echo('event_calendar:upcoming_events_title'); } else { if ($page_type == 'group') { $title = elgg_echo('event_calendar:group') . ' (' . $subtitle . ')'; } else { $title = elgg_echo('event_calendar:listing_title:' . $filter) . ' (' . $subtitle . ')'; } } $params = array('title' => $title, 'content' => $content, 'filter_override' => $filter_override); elgg_set_ignore_access($access_status); return $params; }
function event_calendar_queue_reminders() { // game plan - get all events up to 60 days ahead // with no reminder sent // compute reminder period // if <= current time, set reminder_queued flag and queue the // notification message using the message_queue plugin if (elgg_plugin_exists('message_queue')) { $now = time(); // oops - this does not work for repeated events // need extra stuff for that /*$options = array( 'type' => 'object', 'subtype' => 'event_calendar', 'metadata_name_value_pairs' => array( array('name' => 'reminder_queued', 'value' => 'no'), array('name' => 'send_reminder', 'value' => 1), array('name' => 'start_date', 'value' => $now + 60*24*60*60, 'operand' => '>='), ), 'limit' => 0, ); $events = elgg_get_entities_from_metadata($options); */ $event_list = event_calendar_get_events_between($now, $now + 60 * 24 * 60 * 60, FALSE, 0); foreach ($event_list as $es) { $e = $es['event']; if ($e->send_reminder) { $reminder_period = 60 * $e->reminder_interval * $e->reminder_number; if ($e->repeats) { // repeated events require more complex handing foreach ($es['data'] as $d) { // if event falls in the reminder period if ($d->start_time - $reminder_period >= $now) { // and the reminder has not already been queued if (!event_calendar_repeat_reminder_logged($e, $d->start_time)) { // set the reminder queued flag event_calendar_repeat_reminder_log($e, $d->start_time); // queue the reminder for sending event_calendar_queue_reminder($e); } break; } } } else { // if this is just a normal non-repeated event, then we just need to set a flag and queue the reminder if ($e->reminder_queued != 'yes' && $e->start_date - $now <= $reminder_period) { $e->reminder_queued = 'yes'; event_calendar_queue_reminder($e); } } } } } }
/** * Notify users before an event if the message_queue plugin is installed * * Game plan - get all events up to 60 days ahead with no reminder sent compute * reminder period if <= current time, set reminder_queued flag and queue the * notification message using the message_queue plugin. */ function event_calendar_queue_reminders() { if (!elgg_is_active_plugin('message_queue')) { return; } $now = time(); $ia = elgg_set_ignore_access(true); $event_list = event_calendar_get_events_between($now, $now + 60 * 24 * 60 * 60, false, 0); foreach ($event_list as $es) { $e = $es['event']; if ($e->send_reminder) { $reminder_period = 60 * $e->reminder_interval * $e->reminder_number; if ($e->repeats) { // repeated events require more complex handing foreach ($es['data'] as $d) { // if event falls in the reminder period if ($d->start_time - $reminder_period >= $now) { // and the reminder has not already been queued if (!event_calendar_repeat_reminder_logged($e, $d->start_time)) { // set the reminder queued flag event_calendar_repeat_reminder_log($e, $d->start_time); // queue the reminder for sending event_calendar_queue_reminder($e); } break; } } } else { // if this is just a normal non-repeated event, then we just need to set a flag and queue the reminder if ($e->reminder_queued != 'yes' && $e->start_date - $now <= $reminder_period) { $e->reminder_queued = 'yes'; event_calendar_queue_reminder($e); } } } } elgg_set_ignore_access($ia); }
function webinar_is_free($slot, $container_guid) { return event_calendar_get_events_between($slot->start_date, $slot->end_date, true, 10, 0, $container_guid) > 0 ? false : true; }