コード例 #1
0
ファイル: model.php プロジェクト: lorea/Hydra-dev
function event_calendar_set_event_from_form($event_guid, $group_guid)
{
    $event_calendar_times = elgg_get_plugin_setting('times', 'event_calendar');
    $event_calendar_region_display = elgg_get_plugin_setting('region_display', 'event_calendar');
    $event_calendar_type_display = elgg_get_plugin_setting('type_display', 'event_calendar');
    $event_calendar_spots_display = elgg_get_plugin_setting('spots_display', 'event_calendar');
    $event_calendar_hide_end = elgg_get_plugin_setting('hide_end', 'event_calendar');
    $event_calendar_more_required = elgg_get_plugin_setting('more_required', 'event_calendar');
    $event_calendar_personal_manage = elgg_get_plugin_setting('personal_manage', 'event_calendar');
    $event_calendar_repeating_events = elgg_get_plugin_setting('repeating_events', 'event_calendar');
    $schedule_type = get_input('schedule_type');
    if ($event_calendar_more_required == 'yes') {
        $required_fields = array('title', 'venue', 'start_date', 'brief_description', 'fees', 'contact', 'organiser', 'tags');
        if ($event_calendar_times != 'no') {
            $required_fields[] = 'start_time';
            if ($event_calendar_hide_end != 'yes') {
                $required_fields[] = 'end_time';
            }
        }
        if ($event_calendar_region_display == 'yes') {
            $required_fields[] = 'region';
        }
        if ($event_calendar_type_display == 'yes') {
            $required_fields[] = 'event_type';
        }
        if ($event_calendar_spots_display == 'yes') {
            $required_fields[] = 'spots';
        }
    } else {
        $required_fields = array('title');
    }
    if ($event_guid) {
        $event = get_entity($event_guid);
        if (!elgg_instanceof($event, 'object', 'event_calendar')) {
            // do nothing because this is a bad event guid
            return FALSE;
        }
    } else {
        $user_guid = elgg_get_logged_in_user_guid();
        $event = new ElggObject();
        $event->subtype = 'event_calendar';
        $event->owner_guid = $user_guid;
        if ($group_guid) {
            $event->container_guid = $group_guid;
        } else {
            $event->container_guid = $event->owner_guid;
        }
    }
    $event->access_id = get_input('access_id');
    $event->title = get_input('title');
    $event->description = get_input('description');
    $event->venue = get_input('venue');
    if ($schedule_type != 'poll') {
        $start_date_text = trim(get_input('start_date'));
        /*$event->original_start_date = get_input('start_date');
        		//$end_date = trim(get_input('end_date',''));
        		// convert start date from current server time to GMT
        		$start_date_text = gmdate("Y-m-d",$start_date);
        		//$event->munged_start_date_string = $start_date_text." ".date_default_timezone_get();*/
        // TODO: is the timezone bit necessary?
        $event->start_date = strtotime($start_date_text . " GMT");
        $end_date_text = trim(get_input('end_date', ''));
        //$event->original_end_date = get_input('end_date');
        if ($end_date_text) {
            $event->end_date = strtotime($end_date_text . " GMT");
            //$event->munged_end_date_string = $end_date_text." ".date_default_timezone_get();
        } else {
            $event->end_date = '';
        }
        if ($event_calendar_times != 'no') {
            $hour = get_input('start_time_hour', '');
            $minute = get_input('start_time_minute', '');
            $meridian = get_input('start_time_meridian', '');
            if (is_numeric($hour) && is_numeric($minute)) {
                $event->start_time = event_calendar_convert_to_time($hour, $minute, $meridian);
            } else {
                $event->start_time = '';
            }
            $hour = get_input('end_time_hour', '');
            $minute = get_input('end_time_minute', '');
            $meridian = get_input('end_time_meridian', '');
            if (is_numeric($hour) && is_numeric($minute)) {
                $event->end_time = event_calendar_convert_to_time($hour, $minute, $meridian);
            } else {
                $event->end_time = '';
            }
            if (is_numeric($event->start_date) && is_numeric($event->start_time)) {
                // Set start date to the Unix start time, if set.
                // This allows sorting by date *and* time.
                $event->start_date += $event->start_time * 60;
            }
        }
    }
    if ($event_calendar_spots_display == 'yes') {
        $event->spots = trim(get_input('spots'));
    }
    if ($event_calendar_region_display == 'yes') {
        $event->region = get_input('region');
    }
    if ($event_calendar_type_display == 'yes') {
        $event->event_type = get_input('event_type');
    }
    if ($event_calendar_personal_manage == 'by_event') {
        $event->personal_manage = get_input('personal_manage');
    }
    if ($event_calendar_repeating_events != 'no') {
        $repeats = get_input('repeats');
        $event->repeats = $repeats;
        if ($repeats == 'yes') {
            $event->repeat_interval = get_input('repeat_interval');
            $dow = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
            foreach ($dow as $w) {
                $v = 'event-calendar-repeating-' . $w . '-value';
                $event->{$v} = get_input($v);
            }
        }
    }
    $event->fees = get_input('fees');
    $event->contact = get_input('contact');
    $event->organiser = get_input('organiser');
    $event->tags = string_to_tag_array(get_input('tags'));
    $event->long_description = get_input('long_description');
    $event->schedule_type = $schedule_type;
    $event->send_reminder = get_input('send_reminder');
    $event->reminder_number = get_input('reminder_number');
    $event->reminder_interval = get_input('reminder_interval');
    $event->web_conference = get_input('web_conference');
    $event->real_end_time = event_calendar_get_end_time($event);
    foreach ($required_fields as $fn) {
        if (!trim($event->{$fn})) {
            return FALSE;
            break;
        }
    }
    if ($event->save()) {
        if (!$event_guid && $event->web_conference) {
            if (!event_calendar_create_bbb_conf($event)) {
                register_error(elgg_echo('event_calendar:conference_create_error'));
            }
        }
        if ($group_guid && elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes') {
            event_calendar_add_personal_events_from_group($event->guid, $group_guid);
        }
        if (elgg_get_plugin_setting('add_users', 'event_calendar') == 'yes') {
            if (function_exists('autocomplete_member_to_user')) {
                $addusers = get_input('adduser', array());
                foreach ($addusers as $adduser) {
                    if ($adduser) {
                        $user = autocomplete_member_to_user($adduser);
                        $user_id = $user->guid;
                        event_calendar_add_personal_event($event->guid, $user_id);
                        if (elgg_get_plugin_setting('add_users_notify', 'event_calendar') == 'yes') {
                            notify_user($user_id, $CONFIG->site->guid, elgg_echo('event_calendar:add_users_notify:subject'), sprintf(elgg_echo('event_calendar:add_users_notify:body'), $user->name, $event->title, $event->getURL()));
                        }
                    }
                }
            }
        }
    }
    return $event;
}
コード例 #2
0
<?php

// extended logic for BBB
elgg_load_library('elgg:event_calendar');
$event_guid = get_input('event_guid');
$event = get_entity($event_guid);
if (elgg_instanceof($event, 'object', 'event_calendar')) {
    // make sure that the conference still exists, and if not, try recreating it
    if (event_calendar_conference_exists($event)) {
        event_calendar_join_conference($event);
    } else {
        if (event_calendar_create_bbb_conf($event)) {
            event_calendar_join_conference($event);
        } else {
            register_error(elgg_echo('event_calendar:couldnotjoin'));
            forward($event->getURL());
        }
    }
} else {
    register_error(elgg_echo('event_calendar:error_nosuchevent'));
    forward('event_calendar/list');
}
コード例 #3
0
ファイル: model.php プロジェクト: iionly/event_calendar
function event_calendar_set_event_from_form($event_guid, $group_guid)
{
    $event_calendar_times = elgg_get_plugin_setting('times', 'event_calendar');
    $event_calendar_region_display = elgg_get_plugin_setting('region_display', 'event_calendar');
    $event_calendar_type_display = elgg_get_plugin_setting('type_display', 'event_calendar');
    $event_calendar_spots_display = elgg_get_plugin_setting('spots_display', 'event_calendar');
    $event_calendar_hide_end = elgg_get_plugin_setting('hide_end', 'event_calendar');
    $event_calendar_more_required = elgg_get_plugin_setting('more_required', 'event_calendar');
    $event_calendar_personal_manage = elgg_get_plugin_setting('personal_manage', 'event_calendar');
    $event_calendar_repeating_events = elgg_get_plugin_setting('repeating_events', 'event_calendar');
    // temporary place to store values
    $e = new stdClass();
    $e->schedule_type = get_input('schedule_type');
    if ($event_calendar_more_required == 'yes') {
        $required_fields = array('title', 'venue', 'start_date', 'brief_description', 'fees', 'contact', 'organiser', 'tags');
        if ($event_calendar_times != 'no') {
            $required_fields[] = 'start_time';
            if ($event_calendar_hide_end != 'yes') {
                $required_fields[] = 'end_time';
            }
        }
        if ($event_calendar_region_display == 'yes') {
            $required_fields[] = 'region';
        }
        if ($event_calendar_type_display == 'yes') {
            $required_fields[] = 'event_type';
        }
        if ($event_calendar_spots_display == 'yes') {
            $required_fields[] = 'spots';
        }
    } else {
        $required_fields = array('title');
    }
    if ($event_guid) {
        $event = get_entity($event_guid);
        if (!elgg_instanceof($event, 'object', 'event_calendar')) {
            // do nothing because this is a bad event guid
            return false;
        }
    } else {
        $user_guid = elgg_get_logged_in_user_guid();
        $event = new ElggObject();
        $event->subtype = 'event_calendar';
        $event->owner_guid = $user_guid;
        if ($group_guid) {
            $event->container_guid = $group_guid;
        } else {
            $event->container_guid = $event->owner_guid;
        }
    }
    // Check if repeating event and if yes if day(s) of repeat has been selected
    $repeats = get_input('repeats');
    if ($repeats == 'yes') {
        $no_day_selected = true;
        $dow = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
        foreach ($dow as $w) {
            $v = 'event-calendar-repeating-' . $w . '-value';
            $selected = get_input($v);
            if ($selected) {
                $no_day_selected = false;
            }
        }
        if ($no_day_selected) {
            register_error(elgg_echo('event_calander:repeating_event:error'));
            return false;
        }
    }
    if ($e->schedule_type != 'poll') {
        if ($e->schedule_type == 'all_day') {
            $start_date_text = trim(get_input('start_date_for_all_day'));
        } else {
            $start_date_text = trim(get_input('start_date'));
        }
        // TODO: is the timezone bit necessary?
        $e->start_date = strtotime($start_date_text . " " . date_default_timezone_get());
        $end_date_text = trim(get_input('end_date', ''));
        if ($end_date_text && $e->schedule_type != 'all_day') {
            $e->end_date = strtotime($end_date_text . " " . date_default_timezone_get());
        } else {
            $e->end_date = '';
        }
        if ($e->schedule_type != 'all_day' && $event_calendar_times != 'no') {
            $hour = get_input('start_time_hour', '');
            $minute = get_input('start_time_minute', '');
            $meridian = get_input('start_time_meridian', '');
            if (is_numeric($hour) && is_numeric($minute)) {
                $e->start_time = event_calendar_convert_to_time($hour, $minute, $meridian);
            } else {
                $e->start_time = '';
            }
            $hour = get_input('end_time_hour', '');
            $minute = get_input('end_time_minute', '');
            $meridian = get_input('end_time_meridian', '');
            if (is_numeric($hour) && is_numeric($minute)) {
                $e->end_time = event_calendar_convert_to_time($hour, $minute, $meridian);
            } else {
                $e->end_time = '';
            }
            if (is_numeric($e->start_date) && is_numeric($e->start_time)) {
                // Set start date to the Unix start time, if set.
                // This allows sorting by date *and* time.
                $e->start_date += $e->start_time * 60;
            }
        } else {
            $e->start_time = 0;
            $e->end_time = '';
        }
    }
    $e->access_id = get_input('access_id');
    $e->title = get_input('title');
    $e->description = get_input('description');
    $e->venue = get_input('venue');
    $e->fees = get_input('fees');
    $e->contact = get_input('contact');
    $e->organiser = get_input('organiser');
    $e->tags = string_to_tag_array(get_input('tags'));
    $e->long_description = get_input('long_description');
    $e->send_reminder = get_input('send_reminder');
    $e->reminder_number = get_input('reminder_number');
    $e->reminder_interval = get_input('reminder_interval');
    $e->web_conference = get_input('web_conference');
    $e->real_end_time = event_calendar_get_end_time($e);
    // sanity check
    if ($e->schedule_type == 'fixed' && $e->real_end_time <= $e->start_date) {
        register_error(elgg_echo('event_calander:end_before_start:error'));
        return false;
    }
    foreach ($required_fields as $fn) {
        if (!trim($e->{$fn})) {
            return false;
            break;
        }
    }
    // ok, the input passes the validation so put the values in the real event object
    $keys = array('title', 'description', 'access_id', 'start_date', 'start_time', 'end_date', 'end_time', 'venue', 'fees', 'contact', 'organiser', 'tags', 'long_description', 'send_reminder', 'reminder_number', 'reminder_interval', 'web_conference', 'real_end_time', 'schedule_type');
    foreach ($keys as $key) {
        $event->{$key} = $e->{$key};
    }
    if ($event_calendar_spots_display == 'yes') {
        $event->spots = trim(get_input('spots'));
    }
    if ($event_calendar_region_display == 'yes') {
        $event->region = get_input('region');
    }
    if ($event_calendar_type_display == 'yes') {
        $event->event_type = get_input('event_type');
    }
    if ($event_calendar_personal_manage == 'by_event') {
        $event->personal_manage = get_input('personal_manage');
    }
    if ($event_calendar_repeating_events != 'no') {
        $repeats = get_input('repeats');
        $event->repeats = $repeats;
        if ($repeats == 'yes') {
            $event->repeat_interval = get_input('repeat_interval');
            $dow = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
            foreach ($dow as $w) {
                $v = 'event-calendar-repeating-' . $w . '-value';
                $event->{$v} = get_input($v);
            }
        }
    }
    if ($event->save()) {
        if (!$event_guid && $event->web_conference) {
            if (!event_calendar_create_bbb_conf($event)) {
                register_error(elgg_echo('event_calendar:conference_create_error'));
            }
        }
        if ($group_guid && elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes') {
            event_calendar_add_personal_events_from_group($event->guid, $group_guid);
        }
    }
    return $event;
}