예제 #1
0
/**
 * Clean up operations on calendar delete
 *
 * @param string     $event  "delete"
 * @param string     $type   "object"
 * @param ElggEntity $entity Entity being deleted
 */
function delete_event_handler($event, $type, $entity)
{
    if ($entity instanceof Calendar) {
        // Do not allow users to delete publi calendars
        if ($entity->isPublicCalendar() && !elgg_is_admin_logged_in()) {
            register_error(elgg_echo('events:error:public_calendar_delete'));
            return false;
        }
        // Move all orphaned events to the public calendar
        $owner = $entity->getContainerEntity();
        $public_calendar = Calendar::getPublicCalendar($owner);
        if (!$public_calendar) {
            register_error(elgg_echo('events:error:no_public_for_orphans'));
            return false;
        }
        $dbprefix = elgg_get_config('dbprefix');
        $relationship_name = sanitize_string(Calendar::EVENT_CALENDAR_RELATIONSHIP);
        $calendar_subtype_id = (int) get_subtype_id('object', Calendar::SUBTYPE);
        // Get all events that do not appear on container's other calendars
        $events = new ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => Event::SUBTYPE, 'relationship' => Calendar::EVENT_CALENDAR_RELATIONSHIP, 'relationship_guid' => $entity->guid, 'inverse_relationship' => true, 'limit' => 0, 'wheres' => array("NOT EXISTS(SELECT * FROM {$dbprefix}entity_relationships er2\n\t\t\t\t\tJOIN {$dbprefix}entities e2 ON er2.guid_two = e2.guid\n\t\t\t\t\tWHERE er2.relationship = '{$relationship_name}'\n\t\t\t\t\t\tAND er2.guid_one = e.guid\n\t\t\t\t\t\tAND er2.guid_two != {$entity->guid}\n\t\t\t\t\t\tAND e2.container_guid = {$entity->container_guid}\n\t\t\t\t\t\tAND e2.type = 'object' AND e2.subtype = {$calendar_subtype_id})")));
        foreach ($events as $event) {
            /* @var Event $event */
            $public_calendar->addEvent($event);
        }
    }
    return true;
}
예제 #2
0
/**
 * Adds group events to the default calendar of interested members
 * 
 * @param int $event_guid GUID of the event
 * @param int $group_guid GUID of the group
 * @return void
 */
function autosync_group_event($event_guid, $group_guid)
{
    $ia = elgg_set_ignore_access(true);
    // note that this function can be called after shutdown with vroom
    // using guids for params so that we're not performing operations on potentially stale entities
    $event = get_entity($event_guid);
    $group = get_entity($group_guid);
    if (!$event instanceof Event || !$group instanceof ElggGroup) {
        return false;
    }
    // get group members
    $options = array('type' => 'user', 'relationship' => 'member', 'relationship_guid' => $group->guid, 'inverse_relationship' => true, 'limit' => false);
    $users = new ElggBatch('elgg_get_entities_from_relationship', $options);
    foreach ($users as $u) {
        // only add to the calendar if they have not opted out
        if (!check_entity_relationship($u->guid, 'calendar_nosync', $group->guid)) {
            // they have not opted out, we should add it to their calendars
            $calendar = Calendar::getPublicCalendar($u);
            $calendar->addEvent($event);
        }
    }
    elgg_set_ignore_access($ia);
}
예제 #3
0
<?php

$event_guid = get_input('event_guid');
$user_guid = get_input('user_guid');
$event = get_entity($event_guid);
$user = get_entity($user_guid);
if (!$user || !$event instanceof \Events\API\Event) {
    register_error(elgg_echo('events:rsvp:not_found'));
    forward(REFERRER, '404');
}
if (!$event->canEdit()) {
    register_error(elgg_echo('events:rsvp:permission_denied'));
    forward(REFERRER, '403');
}
$options = events_rsvp_options();
foreach ($options as $option) {
    remove_entity_relationship($user->guid, $option, $event->guid);
}
remove_entity_relationship($event->guid, 'access_grant', $user->guid);
$calendar = \Events\API\Calendar::getPublicCalendar($user);
$calendar->removeEvent($event);
system_message(elgg_echo('events:rsvp:remove:success'));
예제 #4
0
 /**
  * Retrieves user's or group's public calendar
  *
  * @param ElggEntity $container User or group
  * @return Calendar|false
  */
 public static function getPublicCalendar($container)
 {
     if (!$container instanceof ElggEntity) {
         return false;
     }
     $calendars = elgg_get_entities(array('type' => 'object', 'subtype' => Calendar::SUBTYPE, 'container_guid' => $container->guid, 'limit' => 1, 'metadata_name_value_pairs' => array('name' => '__public_calendar', 'value' => true), 'order_by' => 'e.time_created ASC'));
     return empty($calendars) ? Calendar::createPublicCalendar($container) : $calendars[0];
 }
예제 #5
0
<?php

namespace Events\UI;

use Events\API\Calendar;
if (!elgg_is_logged_in()) {
    return;
}
$calendars = Calendar::getCalendars(elgg_get_logged_in_user_entity());
$options = array();
$value = array();
foreach ($calendars as $c) {
    /* @var $c Calendar */
    $title = $c->getDisplayName();
    $options[$title] = $c->guid;
    if ($c->hasEvent($vars['entity'])) {
        $value[] = $c->guid;
    }
}
$body .= elgg_view('output/longtext', array('value' => elgg_echo('events:calendar:picker:help'), 'class' => 'elgg-subtext'));
$body .= elgg_view('input/checkboxes', array('name' => 'calendars', 'value' => $value, 'options' => $options));
$body .= '<div class="elgg-foot mtm">';
$body .= elgg_view('input/hidden', array('name' => 'event_guid', 'value' => $vars['guid']));
$body .= elgg_view('input/submit', array('value' => elgg_echo('submit')));
$body .= '</div>';
$form = elgg_view('input/form', array('action' => 'action/calendar/add_event', 'method' => 'post', 'body' => $body, 'class' => 'elgg-form-calendar-add-event'));
$title = elgg_echo('events:calendar:picker:title');
echo elgg_view_module('info', $title, $form);
예제 #6
0
 /**
  * Validates a token
  * 
  * @param string $token Token
  * @return bool
  */
 public function validateToken($token)
 {
     return $token == $this->calendar->getUserToken($this->user->guid);
 }
예제 #7
0
function event_calendar_migration()
{
    $ia = elgg_set_ignore_access(true);
    // don't want to send notifications for these events
    elgg_unregister_event_handler('events_api', 'add_to_calendar', __NAMESPACE__ . '\\add_to_calendar');
    $dbprefix = elgg_get_config('dbprefix');
    $options = array('type' => 'object', 'subtype' => 'event_calendar', 'limit' => false);
    $old_events = new \ElggBatch('elgg_get_entities', $options, null, 25, false);
    foreach ($old_events as $old_event) {
        elgg_set_plugin_setting('migration_process', time(), 'events_ui');
        $container = $old_event->getContainerEntity();
        if (!$container) {
            // nothing we can do about this
            $old_event->delete();
            continue;
        }
        $tza = DateTimeZone::listAbbreviations();
        $tzlist = array();
        foreach ($tza as $zone) {
            foreach ($zone as $item) {
                if (is_string($item['timezone_id']) && $item['timezone_id'] != '') {
                    $tzlist[] = $item['timezone_id'];
                }
            }
        }
        // a list of all valid timezones
        $tzlist = array_unique($tzlist);
        $event = new Event();
        $event->owner_guid = $old_event->owner_guid;
        $event->container_guid = $old_event->container_guid;
        $event->access_id = $old_event->access_id;
        $event->title = $old_event->title;
        $event->description = $old_event->long_description ? $old_event->long_description : $old_event->description;
        $event->location = $old_event->location;
        $event->tags = $old_event->tags;
        // date and time
        $start_date = $old_event->start_date ? date('Y-m-d', $old_event->start_date) : date('Y-m-d', $old_event->time_created);
        $event->start_date = $start_date;
        $end_date = $old_event->end_date ? date('Y-m-d', $old_event->end_date) : $start_date;
        $event->end_date = $end_date;
        if ($old_event->start_time !== '') {
            $hr = floor((int) $old_event->start_time / 15 / 4);
            $min = (int) $old_event->start_time / 15 % 4 * 15;
            $am = $hr < 12 ? 'am' : 'pm';
            if ($hr > 12) {
                $hr -= 12;
            }
            if ($hr == 0) {
                $hr = 12;
            }
            if (!$min) {
                $min = '00';
            }
            $start_time = $hr . ":" . $min . $am;
        } else {
            $start_time = '12:00am';
            $end_time = '1:00am';
        }
        if ($old_event->end_time !== '') {
            $hr = floor((int) $old_event->end_time / 15 / 4);
            $min = (int) $old_event->end_time / 15 % 4 * 15;
            $am = $hr < 12 ? 'am' : 'pm';
            if ($hr > 12) {
                $hr -= 12;
            }
            if ($hr == 0) {
                $hr = 12;
            }
            if (!$min) {
                $min = '00';
            }
            $end_time = $hr . ":" . $min . $am;
        } else {
            if (!$end_time) {
                $hr++;
                $am = $hr < 12 ? 'am' : 'pm';
                if ($hr > 12) {
                    $hr -= 12;
                }
                if ($hr == 0) {
                    $hr = 12;
                }
                $end_time = $hr . ":" . $min . $am;
            }
        }
        $event->start_time = $start_time;
        $event->end_time = $end_time;
        $timezone = in_array($old_event->time_zone, $tzlist) ? $old_event->time_zone : 'America/New_York';
        // event calendar used some invalid timezones...
        // default to UTC if it fails
        try {
            $dt = new DateTime(null, new DateTimeZone($timezone));
        } catch (Exception $exc) {
            $dt = new DateTime(null, new DateTimeZone('America/New_York'));
            $timezone = 'America/New_York';
            // good as any, and requested by client
        }
        $start_timestamp = $dt->modify("{$start_date} {$start_time}")->getTimestamp();
        $start_timestamp_iso = $dt->format('c');
        $end_timestamp = $dt->modify("{$end_date} {$end_time}")->getTimestamp();
        $end_timestamp_iso = $dt->format('c');
        $event->start_timestamp = $start_timestamp;
        $event->end_timestamp = $end_timestamp;
        $event->start_timestamp_iso = $start_timestamp_iso;
        $event->end_timestamp_iso = $end_timestamp_iso;
        $event->timezone = $timezone;
        $event->all_day = 0;
        $event->end_delta = abs($end_timestamp - $start_timestamp);
        $event->repeat = 0;
        if (!$event->save()) {
            // something went wrong
            continue;
        }
        $event->repeat_end_timestamp = $event->calculateRepeatEndTimestamp();
        $event->time_created = $old_event->time_created;
        // might as well preserve this
        $event->save();
        // time_created can only be updated, not set on creation
        // now we need to add the event to calendars
        // first add to the container calendar
        $calendar = Calendar::getPublicCalendar($container);
        $calendar->addEvent($event);
        // now add to any other calendars
        $user_options = array('type' => 'user', 'joins' => array("JOIN {$dbprefix}entity_relationships r ON r.guid_one = e.guid"), 'wheres' => array("r.relationship = 'personal_event' AND r.guid_two = {$old_event->guid}"), 'limit' => false);
        $users = new \ElggBatch('elgg_get_entities', $user_options);
        foreach ($users as $u) {
            $ucal = Calendar::getPublicCalendar($u);
            $ucal->addEvent($event);
        }
        // all done, lets kill the old event
        $old_event->delete();
    }
    elgg_set_plugin_setting('migration_process', 0, 'events_ui');
    elgg_set_ignore_access($ia);
}
예제 #8
0
<?php

namespace Events\UI;

use Events\API\Calendar;
$guid = get_input('guid');
$entity = get_entity($guid);
if (!$entity) {
    $entity = elgg_get_logged_in_user_entity();
}
if (!$entity instanceof Calendar) {
    $entity = Calendar::getPublicCalendar($entity);
}
if (!$entity) {
    forward('', '404');
}
$container = $entity->getContainerEntity();
elgg_set_page_owner_guid($container->guid);
//elgg_push_breadcrumb(elgg_echo('events:calendar'), "calendar/all");
if (elgg_instanceof($container, 'user')) {
    elgg_push_breadcrumb($container->name, "calendar/owner/{$container->username}");
} else {
    if (elgg_instanceof($container, 'group')) {
        elgg_push_breadcrumb($container->name, "calendar/group/{$container->guid}");
    }
}
$title = $entity->getDisplayName();
elgg_push_breadcrumb($title);
elgg_register_menu_item('title', array('name' => 'feed_view', 'href' => "calendar/feed/{$entity->guid}", 'text' => elgg_echo('events:view:feed'), 'title' => elgg_echo('events:view:feed:switch'), 'link_class' => 'elgg-button elgg-button-action'));
elgg_register_menu_item('title', array('name' => 'ical_view', 'href' => $entity->getIcalURL("calendar/ical/{$entity->guid}/calendar{$entity->guid}.ics"), 'text' => elgg_echo('events:view:ical'), 'title' => elgg_echo('events:view:ical'), 'link_class' => 'elgg-button elgg-button-action js-events-ui-ical-modal-trigger'));
$sidebar = elgg_view('events_ui/sidebar', array('entity' => $entity));
예제 #9
0
$container = get_entity($container_guid);
if (!$container) {
    $container = $user;
}
if (!$container->canWriteToContainer($user->guid, 'object', Event::SUBTYPE)) {
    register_error(elgg_echo('events:error:container_permissions'));
    forward(REFERER);
}
if (!get_input('title')) {
    register_error(elgg_echo('events:error:empty_title'));
    forward(REFERER);
}
$calendar_guid = get_input('calendar');
$calendar = get_entity($calendar_guid);
if (!$calendar instanceof Calendar) {
    $calendar = Calendar::getPublicCalendar($user);
}
$editing = true;
if (!$event instanceof Event) {
    $event = new Event();
    $event->owner_guid = $user->guid;
    $event->container_guid = $container->guid;
    $editing = false;
}
$title = strip_tags(get_input('title', elgg_echo('events:edit:title:placeholder')));
$location = get_input('location');
$description = get_input('description');
$start_date = get_input('start_date');
$end_date = get_input('end_date', $start_date);
$timezone = get_input('timezone', Util::UTC);
$start_time = get_input('start_time', '12:00am');