From 0b25adcd921149b50845647980284e8ab66d8fed Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Tue, 3 Apr 2012 12:31:42 +0200
Subject: major changes to add new features, including a full calendar and
repeating events
---
models/model.php | 456 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 403 insertions(+), 53 deletions(-)
(limited to 'models/model.php')
diff --git a/models/model.php b/models/model.php
index aa97bfddb..b29ad2ad7 100644
--- a/models/model.php
+++ b/models/model.php
@@ -32,6 +32,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
$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');
if ($event_calendar_more_required == 'yes') {
$required_fields = array('title','venue','start_date',
@@ -54,7 +55,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
$required_fields[] = 'spots';
}
} else {
- $required_fields = array('title','venue','start_date');
+ $required_fields = array('title','start_date');
}
if ($event_guid) {
@@ -78,15 +79,21 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
$event->title = get_input('title');
$event->description = get_input('description');
$event->venue = get_input('venue');
- // convert start date from current server time to GMT
+
$start_date = get_input('start_date');
- $start_date_text = date("Y-m-d",$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();
$event->start_date = strtotime($start_date_text." ".date_default_timezone_get());
$end_date = trim(get_input('end_date',''));
+ $event->original_end_date = get_input('end_date');
if ($end_date) {
- $end_date_text = date("Y-m-d",$end_date);
+ $end_date_text = gmdate("Y-m-d",$end_date);
$event->end_date = strtotime($end_date_text." ".date_default_timezone_get());
+ $event->munged_end_date_string = $end_date_text." ".date_default_timezone_get();
} else {
$event->end_date = '';
}
@@ -122,11 +129,29 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
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->all_day = get_input('all_day');
+ $event->schedule_type = get_input('schedule_type');
+ $event->send_reminder = get_input('send_reminder');
+ $event->reminder_number = get_input('reminder_number');
+ $event->reminder_interval = get_input('reminder_interval');
$event->real_end_time = event_calendar_get_end_time($event);
foreach ($required_fields as $fn) {
if (!trim($event->$fn)) {
@@ -171,10 +196,127 @@ function event_calendar_get_events_between($start_date,$end_date,$is_count,$limi
return $count;
} else {
$events = event_calendar_get_entities_from_metadata_between2('start_date','end_date',
- $start_date, $end_date, "object", "event_calendar", 0, $container_guid, $limit,$offset,"",0,false,false,$region);
- //return event_calendar_vsort($events,'start_date');
- return $events;
+ $start_date, $end_date, "object", "event_calendar", 0, $container_guid, $limit,$offset,"",0,false,false,$region);
+ $repeating_events = event_calendar_get_repeating_events_between($start_date,$end_date,$container_guid,$region);
+ $all_events = event_calendar_merge_repeating_events($events, $repeating_events);
+ return $all_events;
+ }
+}
+
+function event_calendar_merge_repeating_events($events, $repeating_events) {
+ $non_repeating_events = array();
+ foreach($events as $e) {
+ if ($e->repeats != 'yes') {
+ $non_repeating_events[] = array('event' => $e,'data' => array(array('start_time' => $e->start_date, 'end_time' => $e->real_end_time)));
+ }
+ }
+
+ return array_merge($non_repeating_events, $repeating_events);
+}
+
+function event_calendar_get_repeating_events_between($start_date,$end_date,$container_guid,$region) {
+ // game plan: get all repeating events with start date <= $end_date and then generate all possible events
+ // sanity check
+ if ($start_date <= $end_date) {
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'event_calendar',
+ 'limit' => 0,
+ 'metadata_name_value_pairs' => array(
+ array(
+ 'name' => 'start_date',
+ 'value' => $end_date,
+ 'operand' => '<='
+ ),
+ array(
+ 'name' => 'repeats',
+ 'value' => 'yes'
+ ),
+ )
+ );
+ if ($container_guid) {
+ if (is_array($container_guid)) {
+ $options['container_guids'] = $container_guid;
+ } else {
+ $options['container_guid'] = $container_guid;
+ }
+ }
+
+ if ($region && $region != '-') {
+ $options['metadata_name_value_pairs'][] = array(
+ 'name' => 'region',
+ 'value' => $region
+ );
+ }
+
+ $events = elgg_get_entities_from_metadata($options);
}
+ return event_calendar_get_repeating_event_structure($events, $start_date, $end_date);
+}
+
+
+function event_calendar_get_repeating_event_structure($events, $start_date, $end_date) {
+ $dow = array('monday','tuesday','wednesday','thursday','friday','saturday','sunday');
+ $repeating_events = array();
+ if ($events) {
+ $incs = array();
+ foreach($events as $e) {
+ $repeat_data = array();
+ $day_num = date('N',$e->start_date)-1;
+ for($d=0;$d<7;$d++) {
+ $fn = 'event-calendar-repeating-'.$dow[$d].'-value';
+ if ($e->$fn) {
+ $increment = $d - $day_num;
+ $incs[] = $increment;
+ }
+ }
+ if ($incs) {
+ sort($incs);
+
+ $repeat_interval = $e->repeat_interval;
+ $event_start_time = $e->start_date;
+ $event_end_time = $e->real_end_time;
+ $week = 0;
+ if ($event_start_time <= $event_end_time) {
+ $more_to_do = TRUE;
+ $cur_start_time = $event_start_time;
+ $cur_end_time = $event_end_time;
+ // keep generating events until after $end_date
+ // repeat_times is a sanity check to prevent infinite loops in case of bad data
+ $repeat_times = 0;
+ do {
+ foreach($incs as $inc) {
+ //$seconds = $inc*60*60*24;
+ if ($inc >=0) {
+ $tinc = "+ " . $inc;
+ } else {
+ $tinc = $inc;
+ }
+ $this_start_time = strtotime($tinc . " day", $cur_start_time);
+ $this_end_time = strtotime($tinc . " day", $cur_end_time);
+ if ($this_start_time > $end_date) {
+ $more_to_do = FALSE;
+ break;
+ }
+ if ($this_start_time >= $event_start_time) {
+ $repeat_data[] = array (
+ 'start_time' => $this_start_time,
+ 'end_time' => $this_end_time,
+ );
+ }
+ }
+ // repeat_interval weeks later
+ $week += $repeat_interval;
+ $cur_start_time = strtotime("+" . $week . " week", $event_start_time);
+ $cur_end_time = strtotime("+" . $week ." week", $event_end_time);
+ $repeat_times += 1;
+ } while ($repeat_times < 1000 && $more_to_do);
+ }
+ }
+ $repeating_events[] = array('event'=>$e,'data'=>$repeat_data);
+ }
+ }
+ return $repeating_events;
}
function event_calendar_get_open_events_between($start_date,$end_date,
@@ -187,10 +329,73 @@ $is_count,$limit=10,$offset=0,$container_guid=0,$region='-', $meta_max = 'spots'
$events = event_calendar_get_entities_from_metadata_between2('start_date','end_date',
$start_date, $end_date, "object", "event_calendar", 0, $container_guid, $limit,$offset,"",0,false,false,$region,$meta_max,$annotation_name);
//return event_calendar_vsort($events,'start_date');
- return $events;
+ $repeating_events = event_calendar_get_open_repeating_events_between($start_date,$end_date,$container_guid,$region);
+ $all_events = event_calendar_merge_repeating_events($events, $repeating_events);
+ return $all_events;
}
}
+function event_calendar_get_open_repeating_events_between($start_date,$end_date,$container_guid,$region) {
+ $db_prefix = elgg_get_config('dbprefix');
+ $meta_max = 'spots';
+ $annotation_name = 'personal_event';
+ $joins = array();
+ $wheres = array();
+ $meta_max_n = get_metastring_id($meta_max);
+ $ann_n = get_metastring_id($annotation_name);
+ if (!$meta_max_n || !$ann_n) {
+ if ($count) {
+ return 0;
+ } else {
+ return false;
+ }
+ }
+
+ $joins[] = "LEFT JOIN {$dbprefix}metadata m4 ON (e.guid = m4.entity_guid AND m4.name_id=$meta_max_n) ";
+ $joins[] = "LEFT JOIN {$dbprefix}metastrings ms4 ON (m4.value_id = ms4.id) ";
+ $wheres[] = "((ms4.string is null) OR (ms4.string = \"\") OR (CONVERT(ms4.string,SIGNED) > (SELECT count(id) FROM {$dbprefix}annotations ann WHERE ann.entity_guid = e.guid AND name_id = $ann_n GROUP BY entity_guid)))";
+
+ // sanity check
+ if ($start_date <= $end_date) {
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'event_calendar',
+ 'limit' => 0,
+ 'metadata_name_value_pairs' => array(
+ array(
+ 'name' => 'start_date',
+ 'value' => $end_date,
+ 'operand' => '<='
+ ),
+ array(
+ 'name' => 'repeats',
+ 'value' => 'yes'
+ ),
+ ),
+ 'joins' => $joins,
+ 'wheres' => $wheres,
+
+ );
+ if ($container_guid) {
+ if (is_array($container_guid)) {
+ $options['container_guids'] = $container_guid;
+ } else {
+ $options['container_guid'] = $container_guid;
+ }
+ }
+
+ if ($region && $region != '-') {
+ $options['metadata_name_value_pairs'][] = array(
+ 'name' => 'region',
+ 'value' => $region
+ );
+ }
+
+ $events = elgg_get_entities_from_metadata($options);
+ }
+ return event_calendar_get_repeating_event_structure($events, $start_date, $end_date);
+}
+
function event_calendar_get_events_for_user_between($start_date,$end_date,$is_count,$limit=10,$offset=0,$user_guid,$container_guid=0,$region='-') {
if ($is_count) {
// old way
@@ -244,14 +449,82 @@ function event_calendar_get_events_for_user_between2($start_date,$end_date,$is_c
//print_r($options_new_way);
$events_new_way = elgg_get_entities_from_relationship($options_new_way);
//return event_calendar_vsort($events,'start_date');
- if (!$events_old_way) {
- return $events_new_way;
- } else if (!$events_new_way) {
- return $events_old_way;
+ $repeating_events = event_calendar_get_repeating_events_for_user_between($user_guid,$start_date,$end_date,$container_guid,$region);
+ $all_events = event_calendar_merge_repeating_events(array_merge($events_old_way,$events_new_way), $repeating_events);
+ return $all_events;
+ }
+}
+
+function event_calendar_get_repeating_events_for_user_between($user_guid,$start_date,$end_date,$container_guid,$region) {
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'event_calendar',
+ 'relationship' => 'personal_event',
+ 'relationship_guid' => $user_guid,
+ 'metadata_name_value_pairs' => array(
+ array(
+ 'name' => 'start_date',
+ 'value' => $end_date,
+ 'operand' => '<='
+ ),
+ array(
+ 'name' => 'repeats',
+ 'value' => 'yes'
+ ),
+ )
+ );
+
+ if ($container_guid) {
+ if (is_array($container_guid)) {
+ $options['container_guids'] = $container_guid;
+ } else {
+ $options['container_guid'] = $container_guid;
+ }
+ }
+
+ if ($region && $region != '-') {
+ $options['metadata_name_value_pairs'][] = array(
+ 'name' => 'region',
+ 'value' => $region
+ );
+ }
+
+ $events = elgg_get_entities_from_relationship($options);
+ return event_calendar_get_repeating_event_structure($events, $start_date, $end_date);
+}
+
+function event_calendar_get_repeating_events_for_friends_between($user_guid,$friend_list,$start_date,$end_date,$container_guid=0,$region='-') {
+
+ $db_prefix = elgg_get_config('dbprefix');
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'event_calendar',
+ 'metadata_name_value_pairs' => array(
+ array( 'name' => 'start_date',
+ 'value' => $end_date,
+ 'operand' => '<='
+ ),
+ array( 'name' => 'repeats',
+ 'value' => 'yes'
+ )
+ ),
+ 'joins' => array("JOIN {$db_prefix}entity_relationships r ON (r.guid_two = e.guid)"),
+ 'wheres' => array("r.relationship = 'personal_event'","r.guid_one IN ($friend_list)"),
+ );
+
+ if ($container_guid) {
+ if (is_array($container_guid)) {
+ $options['container_guids'] = $container_guid;
} else {
- return array_merge($events_old_way,$events_new_way);
+ $options['container_guid'] = $container_guid;
}
}
+ if ($region && $region != '-') {
+ $options['metadata_name_value_pairs'][] = array('name'=>'region','value'=>sanitize_string($region));
+ }
+
+ $events = elgg_get_entities_from_relationship($options);
+ return event_calendar_get_repeating_event_structure($events, $start_date, $end_date);
}
function event_calendar_get_events_for_friends_between($start_date,$end_date,$is_count,$limit=10,$offset=0,$user_guid,$container_guid=0,$region='-') {
@@ -300,13 +573,9 @@ function event_calendar_get_events_for_friends_between($start_date,$end_date,$is
$options_new_way['order_by_metadata'] = array(array('name'=>'start_date','direction'=>'ASC','as'=>'integer'));
//print_r($options_new_way);
$events_new_way = elgg_get_entities_from_metadata($options_new_way);
- if (!$events_old_way) {
- return $events_new_way;
- } else if (!$events_new_way) {
- return $events_old_way;
- } else {
- return array_merge($events_old_way,$events_new_way);
- }
+ $repeating_events = event_calendar_get_repeating_events_for_friends_between($user_guid,$friend_list,$start_date,$end_date,$container_guid,$region);
+ $all_events = event_calendar_merge_repeating_events(array_merge($events_old_way,$events_new_way), $repeating_events);
+ return $all_events;
}
}
}
@@ -469,18 +738,19 @@ function event_calendar_get_entities_from_metadata_between($meta_start_name, $me
$query .= ' and ' . get_access_sql_suffix("m"); // Add access controls
$query .= ' and ' . get_access_sql_suffix("m2"); // Add access controls
-
-
if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ $query .= " order by $order_by";
+ if ($limit) {
+ $query .= " limit $offset, $limit"; // Add order and limit
+ }
$entities = get_data($query, "entity_row_to_elggstar");
if (elgg_get_plugin_setting('add_to_group_calendar', 'event_calendar') == 'yes') {
if (get_entity($container_guid) instanceOf ElggGroup) {
$entities = event_calendar_get_entities_from_metadata_between_related($meta_start_name, $meta_end_name,
- $meta_start_value, $meta_end_value, $entity_type,
- $entity_subtype, $owner_guid, $container_guid,
- $limit = 10, $offset = 0, $order_by = "", $site_guid = 0,
- $filter = false, $count = false, $region='-',$entities);
+ $meta_start_value, $meta_end_value, $entity_type,
+ $entity_subtype, $owner_guid, $container_guid,
+ 0, 0, "", 0,
+ false, false, '-',$entities);
}
}
return $entities;
@@ -557,6 +827,8 @@ $filter = false, $count = false, $region='-',$main_events) {
* @param string $annotation_name annotation name to count
*
* @return int|array A list of entities, or a count if $count is set to true
+ *
+ * TODO: see if the new API is robust enough to avoid this custom query
*/
function event_calendar_get_entities_from_metadata_between2
($meta_start_name, $meta_end_name, $meta_start_value, $meta_end_value,
@@ -690,7 +962,10 @@ $count = false, $region='-', $meta_max = '', $annotation_name = '')
$query .= ' AND ' . get_access_sql_suffix("m2"); // Add access controls
if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ $query .= " order by $order_by";
+ if ($limit) {
+ $query .= " limit $offset, $limit"; // Add order and limit
+ }
return get_data($query, "entity_row_to_elggstar");
} else {
if ($row = get_data_row($query))
@@ -843,28 +1118,6 @@ function event_calendar_get_events_for_group($group_guid) {
return elgg_get_entities($options);
}
-function event_calendar_handle_join($event, $object_type, $object) {
- $group = $object['group'];
- $user = $object['user'];
- $user_guid = $user->getGUID();
- $events = event_calendar_get_events_for_group($group->getGUID());
- foreach ($events as $event) {
- $event_id = $event->getGUID();
- event_calendar_add_personal_event($event_id,$user_guid);
- }
-}
-
-function event_calendar_handle_leave($event, $object_type, $object) {
- $group = $object['group'];
- $user = $object['user'];
- $user_guid = $user->getGUID();
- $events = event_calendar_get_events_for_group($group->getGUID());
- foreach ($events as $event) {
- $event_id = $event->getGUID();
- event_calendar_remove_personal_event($event_id,$user_guid);
- }
-}
-
function event_calendar_convert_time($time) {
$event_calendar_time_format = elgg_get_plugin_setting('timeformat','event_calendar');
if ($event_calendar_time_format == '12') {
@@ -978,17 +1231,35 @@ function event_calendar_get_formatted_time($event) {
$end_date = date($date_format,$event->end_date);
}
if ((!$event->end_date) || ($end_date == $start_date)) {
- if ($event_calendar_times) {
+ if (!$event->all_day && $event_calendar_times) {
$start_date = event_calendar_format_time($start_date,$event->start_time,$event->end_time);
}
$time_bit = $start_date;
} else {
- if ($event_calendar_times) {
+ if (!$event->all_day && $event_calendar_times) {
$start_date = event_calendar_format_time($start_date,$event->start_time);
$end_date = event_calendar_format_time($end_date,$event->end_time);
}
$time_bit = "$start_date - $end_date";
}
+
+ if ($event->repeats == 'yes') {
+ $dow = array('monday','tuesday','wednesday','thursday','friday','saturday','sunday');
+ $r = array();
+ foreach ($dow as $w) {
+ $fn = 'event-calendar-repeating-'.$w.'-value';
+ if ($event->$fn) {
+ $r[] = elgg_echo('event_calendar:dow:full:'.$w);
+ }
+ }
+ $week_bit = implode(", ",$r);
+ if ($event->repeat_interval > 1) {
+ $week_bit .= ' '.elgg_echo('event_calendar:repeated_event:week_interval',array($event->repeat_interval));
+ } else {
+ $week_bit .= ' '.elgg_echo('event_calendar:repeated_event:week_single');
+ }
+ $time_bit = elgg_echo('event_calendar:repeated_event:format',array($time_bit, $week_bit));
+ }
return $time_bit;
}
@@ -1229,6 +1500,7 @@ function event_calendar_get_page_content_list($page_type,$container_guid,$start_
}
function event_calendar_get_page_content_edit($page_type,$guid) {
+ elgg_load_js('elgg.event_calendar');
$vars = array();
$vars['id'] = 'event-calendar-edit';
$vars['name'] = 'event_calendar_edit';
@@ -1311,7 +1583,21 @@ function event_calendar_prepare_edit_form_vars($event = NULL) {
'contact' => NULL,
'organiser' => NULL,
'tags' => NULL,
- 'personal_manage' => NULL,
+ 'all_day' => 0,
+ 'send_reminder' => NULL,
+ 'reminder_number' => 1,
+ 'reminder_interval' => 60,
+ 'schedule_type' => 'fixed',
+ 'repeats' => NULL,
+ 'repeat_interval' => 1,
+ 'event-calendar-repeating-monday-value' => 0,
+ 'event-calendar-repeating-tuesday-value' => 0,
+ 'event-calendar-repeating-wednesday-value' => 0,
+ 'event-calendar-repeating-thursday-value' => 0,
+ 'event-calendar-repeating-friday-value' => 0,
+ 'event-calendar-repeating-saturday-value' => 0,
+ 'event-calendar-repeating-sunday-value' => 0,
+ 'personal_manage' => 'open',
'long_description' => NULL,
'access_id' => ACCESS_DEFAULT,
'group_guid' => NULL,
@@ -1466,6 +1752,7 @@ function event_calendar_generate_listing_params($page_type,$container_guid,$orig
$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);
@@ -1506,6 +1793,8 @@ function event_calendar_generate_listing_params($page_type,$container_guid,$orig
if ($event_calendar_listing_format == 'paged') {
$title = elgg_echo('event_calendar:upcoming_events_title');
+ } else if ($event_calendar_listing_format == 'full') {
+ $title = elgg_echo('event_calendar:show_events_title');
} else if ($page_type == 'group') {
$title = elgg_echo('event_calendar:group'). ' ('.$subtitle.')';
} else {
@@ -1769,3 +2058,64 @@ function event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delt
}
return FALSE;
}
+
+function event_calendar_get_page_content_fullcalendar_events($start_date,$end_date,$filter='all',$container_guid=0,$region='-') {
+ //print "$start_date - $end_date";
+ $start_ts = strtotime($start_date);
+ $end_ts = strtotime($end_date);
+ if ($filter == 'all') {
+ $events = event_calendar_get_events_between($start_ts,$end_ts,false,0,0,$container_guid,$region);
+ } else if ($filter == 'open') {
+ $events = event_calendar_get_open_events_between($start_ts,$end_ts,false,0,0,$container_guid,$region);
+ } else if ($filter == 'friends') {
+ $user_guid = elgg_get_logged_in_user_guid();
+ $events = event_calendar_get_events_for_friends_between($start_ts,$end_ts,false,0,0,$user_guid,$container_guid,$region);
+ } else if ($filter == 'mine') {
+ $user_guid = elgg_get_logged_in_user_guid();
+ $events = event_calendar_get_events_for_user_between2($start_ts,$end_ts,false,0,0,$user_guid,$container_guid,$region);
+ }
+ $event_array = array();
+ $times_supported = elgg_get_plugin_setting('times','event_calendar') != 'no';
+ foreach($events as $e) {
+ $event = $e['event'];
+ $event_data = $e['data'];
+ $c = count($event_data);
+ foreach($event_data as $ed) {
+ $event_item = array(
+ 'id' => $event->guid,
+ 'guid' => $event->guid,
+ 'title' => $event->title,
+ 'url' => $event->getURL(),
+ 'start' => date('c',$ed['start_time']),
+ 'end' => date('c',$ed['end_time']),
+ );
+ if (!$times_supported || $event->all_day) {
+ $event_item['allDay'] = TRUE;
+ } else {
+ $event_item['allDay'] = FALSE;
+ }
+
+ $event_array[] = $event_item;
+ }
+ }
+
+ $json_events_string = json_encode($event_array);
+ return $json_events_string;
+}
+
+// right now this does not return repeated events in sorted order, so repeated events only really work properly for the full calendar
+// TODO: find another solution for displaying repeated events
+
+function event_calendar_flatten_event_structure($events) {
+ $flattened = array();
+ $guids = array();
+ foreach($events as $e) {
+ $this_event = $e['event'];
+ $guid = $this_event->guid;
+ if (!in_array($guid,$guids)) {
+ $guids[] = $guid;
+ $flattened[] = $this_event;
+ }
+ }
+ return $flattened;
+}
\ No newline at end of file
--
cgit v1.2.3
From 58126731fe957c604c1989d59d41534f8fbcf04b Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Fri, 13 Apr 2012 17:20:49 +0200
Subject: added support for event polls (needs the event_poll plugin)
---
actions/event_calendar/edit.php | 4 ++++
models/model.php | 4 ++--
start.php | 12 +++++++++++-
3 files changed, 17 insertions(+), 3 deletions(-)
(limited to 'models/model.php')
diff --git a/actions/event_calendar/edit.php b/actions/event_calendar/edit.php
index 0cc956d73..aef1a59cc 100644
--- a/actions/event_calendar/edit.php
+++ b/actions/event_calendar/edit.php
@@ -34,6 +34,10 @@ if ($event) {
add_to_river('river/object/event_calendar/create','create',$user_guid,$event->guid);
system_message(elgg_echo('event_calendar:add_event_response'));
}
+
+ if ($event->schedule_type == 'poll') {
+ forward('event_poll/add/'.$event->guid);
+ }
forward($event->getURL());
} else {
diff --git a/models/model.php b/models/model.php
index b29ad2ad7..6fe54ab3d 100644
--- a/models/model.php
+++ b/models/model.php
@@ -55,7 +55,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
$required_fields[] = 'spots';
}
} else {
- $required_fields = array('title','start_date');
+ $required_fields = array('title');
}
if ($event_guid) {
@@ -2118,4 +2118,4 @@ function event_calendar_flatten_event_structure($events) {
}
}
return $flattened;
-}
\ No newline at end of file
+}
diff --git a/start.php b/start.php
index 523987154..86a94fbd9 100644
--- a/start.php
+++ b/start.php
@@ -64,7 +64,7 @@ function event_calendar_init() {
elgg_extend_view('css/elgg', 'event_calendar/css');
$event_calendar_listing_format = elgg_get_plugin_setting('listing_format', 'event_calendar');
- if ($event_calendar_listing_format == 'full') {
+ if (elgg_plugin_exists('event_poll') || ($event_calendar_listing_format == 'full')) {
elgg_extend_view('css/elgg', 'fullcalendar/css');
$plugin_js = elgg_get_simplecache_url('js', 'event_calendar/fullcalendar');
elgg_register_js('elgg.full_calendar', $plugin_js);
@@ -287,6 +287,16 @@ function event_calendar_entity_menu_setup($hook, $type, $return, $params) {
if ($handler != 'event_calendar') {
return $return;
}
+ if (elgg_plugin_exists('event_poll') && $entity->canEdit() && $entity->schedule_type == 'poll') {
+ $options = array(
+ 'name' => 'schedule',
+ 'text' => elgg_echo('event_poll:schedule_button'),
+ 'title' => elgg_echo('event_poll:schedule_button'),
+ 'href' => 'event_poll/schedule/'.$entity->guid,
+ 'priority' => 150,
+ );
+ $return[] = ElggMenuItem::factory($options);
+ }
$user_guid = elgg_get_logged_in_user_guid();
if ($user_guid) {
$calendar_status = event_calendar_personal_can_manage($entity,$user_guid);
--
cgit v1.2.3
From a9a76a300972a6451aa45a83e094e697d4c51bf6 Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Thu, 26 Apr 2012 13:17:00 +0200
Subject: Reminder messages are now actually queued for sending (requires
message_queue plugin to actually send).
---
languages/en.php | 14 +++++++-
models/model.php | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
start.php | 7 ++++
3 files changed, 115 insertions(+), 5 deletions(-)
(limited to 'models/model.php')
diff --git a/languages/en.php b/languages/en.php
index cef293be0..d4cb8ac9e 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -305,7 +305,19 @@ You can manage calendar requests for this event here:
'event_calendar:repeated_event:week_single' => "every week.",
'event_calendar:repeated_event:format' => "Starting on %s and repeated on %s",
'event_calendar:settings:repeated_events:title' => "Allow repeated events (currently only works properly in full calendar mode)",
- 'event_calendar:settings:reminders:title' => "Allow sending reminders (To be done - currently does not send reminders)",
+ 'event_calendar:settings:reminders:title' => "Allow sending reminders",
+ 'event_calendar:reminder:subject' => "Reminder for event: %s",
+ 'event_calendar:reminder:body' => "The event
+
+%s
+
+takes place at
+
+%s.
+
+You can visit the event page here:
+%s
+ ",
/**
* Event calendar river
diff --git a/models/model.php b/models/model.php
index 6fe54ab3d..0dd72a595 100644
--- a/models/model.php
+++ b/models/model.php
@@ -85,7 +85,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
//$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();
+ //$event->munged_start_date_string = $start_date_text." ".date_default_timezone_get();
$event->start_date = strtotime($start_date_text." ".date_default_timezone_get());
$end_date = trim(get_input('end_date',''));
@@ -93,7 +93,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
if ($end_date) {
$end_date_text = gmdate("Y-m-d",$end_date);
$event->end_date = strtotime($end_date_text." ".date_default_timezone_get());
- $event->munged_end_date_string = $end_date_text." ".date_default_timezone_get();
+ //$event->munged_end_date_string = $end_date_text." ".date_default_timezone_get();
} else {
$event->end_date = '';
}
@@ -189,7 +189,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
return $event;
}
-function event_calendar_get_events_between($start_date,$end_date,$is_count,$limit=10,$offset=0,$container_guid=0,$region='-') {
+function event_calendar_get_events_between($start_date,$end_date,$is_count=FALSE,$limit=10,$offset=0,$container_guid=0,$region='-') {
if ($is_count) {
$count = event_calendar_get_entities_from_metadata_between2('start_date','end_date',
$start_date, $end_date, "object", "event_calendar", 0, $container_guid, $limit,$offset,"",0,false,true,$region);
@@ -1059,7 +1059,7 @@ function event_calendar_get_personal_events_for_user($user_guid,$limit) {
// the old way used annotations, and the new Elgg 1.8 way uses relationships
// for now this version attempts to bridge the gap by using both methods for older sites
-function event_calendar_get_users_for_event($event_guid,$limit,$offset,$is_count) {
+function event_calendar_get_users_for_event($event_guid,$limit,$offset=0,$is_count=FALSE) {
$options = array(
'type' => 'user',
'relationship' => 'personal_event',
@@ -2119,3 +2119,94 @@ function event_calendar_flatten_event_structure($events) {
}
return $flattened;
}
+
+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);
+ }
+ }
+ }
+ }
+ }
+}
+
+function event_calendar_repeat_reminder_log($e,$start) {
+ // this simple log just uses annotations on the event
+ // TODO - remove log entries for past events
+ create_annotation($e->guid, 'repeat_reminder_log_item', $start, '',0,ACCESS_PUBLIC);
+}
+
+function event_calendar_repeat_reminder_logged($e,$start) {
+ $options = array(
+ 'guid' => $e->guid,
+ 'annotation_name' => 'repeat_reminder_log_item',
+ 'annotation_value' => $start,
+ 'limit' => 1
+ );
+
+ if (elgg_get_annotations($options)) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+function event_calendar_queue_reminder($e) {
+ elgg_load_library('elgg:message_queue');
+ $subject = elgg_echo('event_calendar:reminder:subject',array($e->title));
+ $time_string = event_calendar_get_formatted_time($e);
+ $body = elgg_echo('event_calendar:reminder:body',array($e->title,$time_string,$e->getURL()));
+ $m = message_queue_create_message($subject,$body);
+ if ($m) {
+ $users = event_calendar_get_users_for_event($e->guid,0);
+ foreach($users as $u) {
+ message_queue_add($m->guid,$u->guid);
+ }
+ message_queue_set_for_sending($m->guid);
+ }
+}
diff --git a/start.php b/start.php
index 86a94fbd9..4c17c719b 100644
--- a/start.php
+++ b/start.php
@@ -16,6 +16,8 @@ elgg_register_event_handler('init','system','event_calendar_init');
function event_calendar_init() {
elgg_register_library('elgg:event_calendar', elgg_get_plugins_path() . 'event_calendar/models/model.php');
+
+ elgg_register_plugin_hook_handler('cron', 'fiveminute', 'event_calendar_handle_reminders_cron',400);
// Register a page handler, so we can have nice URLs
elgg_register_page_handler('event_calendar','event_calendar_page_handler');
@@ -400,3 +402,8 @@ function event_calendar_handle_leave($event, $object_type, $object) {
event_calendar_remove_personal_event($event_id,$user_guid);
}
}
+
+function event_calendar_handle_reminders_cron() {
+ elgg_load_library('elgg:event_calendar');
+ event_calendar_queue_reminders();
+}
--
cgit v1.2.3
From 872381995dbcd77b90ac5175ffc7ba51ec75c42a Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Thu, 26 Apr 2012 16:21:00 +0200
Subject: Merges in BBB web conference functionality from now defunct
sched_conf plugin
---
languages/en.php | 10 +++
models/model.php | 79 ++++++++++++++++++++--
views/default/event_calendar/conference_button.php | 32 +++++++++
views/default/forms/event_calendar/edit.php | 9 ++-
views/default/object/event_calendar.php | 4 ++
views/default/plugins/event_calendar/settings.php | 26 +++++++
6 files changed, 152 insertions(+), 8 deletions(-)
create mode 100644 views/default/event_calendar/conference_button.php
(limited to 'models/model.php')
diff --git a/languages/en.php b/languages/en.php
index d4cb8ac9e..e23d78924 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -318,6 +318,16 @@ takes place at
You can visit the event page here:
%s
",
+
+ /**
+ * BBB support
+ */
+
+ 'event_calendar:bbb_server_url' => "Big Blue Button server URL (must end with slash)",
+ 'event_calendar:bbb_security_salt' => "Big Blue Button security salt",
+ 'event_calendar:bbb_create_error' => "Error: unable to create BBB conference, message was: %s",
+ 'event_calendar:bbb_settings_error' => "Error: must set conference URL and salt in plugin settings",
+ 'event_calendar:join_conf_button' => "Join conference",
/**
* Event calendar river
diff --git a/models/model.php b/models/model.php
index 0dd72a595..cf00c4b1c 100644
--- a/models/model.php
+++ b/models/model.php
@@ -152,6 +152,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
$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)) {
@@ -160,6 +161,9 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
}
}
if ($event->save()) {
+ if (!$event_guid && $event->web_conference) {
+ event_calendar_create_bbb_conf($event);
+ }
if ($group_guid && (elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes')) {
event_calendar_add_personal_events_from_group($event->guid,$group_guid);
}
@@ -173,12 +177,12 @@ function event_calendar_set_event_from_form($event_guid,$group_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()
- )
+ sprintf(
+ elgg_echo('event_calendar:add_users_notify:body'),
+ $user->name,
+ $event->title,
+ $event->getURL()
+ )
);
}
}
@@ -1598,6 +1602,7 @@ function event_calendar_prepare_edit_form_vars($event = NULL) {
'event-calendar-repeating-saturday-value' => 0,
'event-calendar-repeating-sunday-value' => 0,
'personal_manage' => 'open',
+ 'web_conference' => NULL,
'long_description' => NULL,
'access_id' => ACCESS_DEFAULT,
'group_guid' => NULL,
@@ -2210,3 +2215,65 @@ function event_calendar_queue_reminder($e) {
message_queue_set_for_sending($m->guid);
}
}
+
+function event_calendar_create_bbb_conf($event) {
+ $bbb_security_salt = elgg_get_plugin_setting('bbb_security_salt','event_calendar');
+ $bbb_server_url = rtrim(elgg_get_plugin_setting('bbb_server_url','event_calendar'), '/') . '/';
+ if ($bbb_security_salt) {
+ $day_in_minutes = 60*24;
+ $duration = (int)(($event->real_end_time-$event->start_date)/60)+$day_in_minutes;
+ $title = urlencode($event->title);
+ $params = "name=$title&meetingID={$event->guid}&duration=$duration";
+ $checksum = sha1('create'.$params.$bbb_security_salt);
+ $params .= "&checksum=$checksum";
+
+ // create curl resource
+ $ch = curl_init();
+
+ // set url
+ curl_setopt($ch, CURLOPT_URL, $bbb_server_url.'api/create?'.$params);
+
+ //return the transfer as a string
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+ // $output contains the output string
+ $output = curl_exec($ch);
+
+ // close curl resource to free up system resources
+ curl_close($ch);
+
+ /*error_log("BBB create request:");
+ error_log($bbb_server_url.'api/create?'.$params);
+
+ error_log("BBB create response:");
+ error_log($output);*/
+
+ $xml = new SimpleXMLElement($output);
+ if ($xml->returncode == 'SUCCESS') {
+ $event->bbb_attendee_password = (string) $xml->attendeePW;
+ $event->bbb_moderator_password = (string) $xml->moderatorPW;
+ } else {
+ register_error(elgg_echo('event_calendar:bbb_create_error',array($xml->message)));
+ }
+ } else {
+ register_error(elgg_echo('event_calendar:bbb_settings_error'));
+ }
+}
+
+function event_calendar_get_join_bbb_url($event) {
+ $bbb_security_salt = elgg_get_plugin_setting('bbb_security_salt','event_calendar');
+ $bbb_server_url = rtrim(elgg_get_plugin_setting('bbb_server_url','event_calendar'), '/') . '/';
+ $user = elgg_get_logged_in_user_entity();
+ $full_name = urlencode($user->name);
+ if ($event->canEdit()) {
+ $password = urlencode($event->bbb_moderator_password);
+ } else {
+ $password = urlencode($event->bbb_attendee_password);
+ }
+ $params = "fullName=$full_name&meetingID={$event->guid}&userID={$user->username}&password=$password";
+ $checksum = sha1('join'.$params.$bbb_security_salt);
+ $params .= "&checksum=$checksum";
+ $url = $bbb_server_url.'api/join?'.$params;
+ return $url;
+}
+
diff --git a/views/default/event_calendar/conference_button.php b/views/default/event_calendar/conference_button.php
new file mode 100644
index 000000000..f6fedf4f6
--- /dev/null
+++ b/views/default/event_calendar/conference_button.php
@@ -0,0 +1,32 @@
+real_end_time + 60*60*24;
+ if ($termination_time < time()) {
+ $in_time_window = FALSE;
+ } else if ($event->canEdit()) {
+ $in_time_window = TRUE;
+ } else if (event_calendar_has_personal_event($event->guid, $user_guid) && ($event->start_date - 15*60) >= time()) {
+ $in_time_window = TRUE;
+ } else {
+ $in_time_window = FALSE;
+ }
+ if ( $in_time_window ) {
+ $button = elgg_view('output/url', array(
+ 'href' => event_calendar_get_join_bbb_url($event),
+ 'text' => elgg_echo('event_calendar:join_conf_button'),
+ 'class' => 'elgg-button elgg-button-action',
+ 'target' => '_blank',
+ ));
+
+ echo ''.$button.'
';
+ }
+}
diff --git a/views/default/forms/event_calendar/edit.php b/views/default/forms/event_calendar/edit.php
index 260e8afe0..79e2a5d0b 100644
--- a/views/default/forms/event_calendar/edit.php
+++ b/views/default/forms/event_calendar/edit.php
@@ -26,6 +26,7 @@ $event_calendar_more_required = elgg_get_plugin_setting('more_required', 'event_
$event_calendar_personal_manage = elgg_get_plugin_setting('personal_manage', 'event_calendar');
$event_calendar_repeated_events = elgg_get_plugin_setting('repeated_events', 'event_calendar');
$event_calendar_reminders = elgg_get_plugin_setting('reminders', 'event_calendar');
+$event_calendar_bbb_server_url = elgg_get_plugin_setting('bbb_server_url', 'event_calendar');
if ($event_calendar_more_required == 'yes') {
$required_fields = array('title','venue','start_date','start_time',
@@ -168,9 +169,13 @@ $body .= elgg_view('event_calendar/container',array('container_guid'=>$vars['con
$body .= '
';
$body .= ''.$prefix['calendar'].elgg_echo('event_calendar:calendar_description').'
';
-if(elgg_plugin_exists('sched_conf')) {
+if($event_calendar_bbb_server_url) {
$body .= '';
- $body .= elgg_view('input/checkbox',array('name'=>'web_conference','value'=>$web_conference,'options_values'=>array('1')));
+ if ($fd['web_conference']) {
+ $body .= elgg_view('input/checkbox',array('name'=>'web_conference','value'=>1,'checked'=>'checked'));
+ } else {
+ $body .= elgg_view('input/checkbox',array('name'=>'web_conference','value'=>1));
+ }
$body .= elgg_echo('event_calendar:web_conference_label');
$body .= '
';
}
diff --git a/views/default/object/event_calendar.php b/views/default/object/event_calendar.php
index 717e2803e..b72c869ea 100644
--- a/views/default/object/event_calendar.php
+++ b/views/default/object/event_calendar.php
@@ -16,6 +16,10 @@ $full = elgg_extract('full_view', $vars, FALSE);
if ($full) {
$body = elgg_view('event_calendar/strapline',$vars);
+ if ($event->web_conference) {
+ $body .= ' ';
+ $body .= elgg_view('event_calendar/conference_button',array('event'=>$event));
+ }
$event_items = event_calendar_get_formatted_full_items($event);
$body .= ' ';
diff --git a/views/default/plugins/event_calendar/settings.php b/views/default/plugins/event_calendar/settings.php
index 908818998..2a2e043de 100644
--- a/views/default/plugins/event_calendar/settings.php
+++ b/views/default/plugins/event_calendar/settings.php
@@ -445,4 +445,30 @@ $body .= elgg_echo('event_calendar:ical_auth_file_name:title');
$body .= ' ';
$body .= elgg_view('input/text',array('name'=>'params[ical_auth_file_name]','value'=>$ical_auth_file_name, 'class'=>'event-calendar-ical-auth-setting'));
+$body .= ' ';
+
+$event_calendar_bbb_server_url = elgg_get_plugin_setting('bbb_server_url', 'event_calendar');
+
+$body .= elgg_echo('event_calendar:bbb_server_url');
+$body .= ' ';
+$body .= elgg_view('input/text', array(
+ 'name' => 'params[bbb_server_url]',
+ 'value' => $event_calendar_bbb_server_url,
+ 'class' => 'text_input',
+));
+
+$body .= ' ';
+
+$event_calendar_bbb_security_salt = elgg_get_plugin_setting('bbb_security_salt', 'event_calendar');
+
+$body .= elgg_echo('event_calendar:bbb_security_salt');
+$body .= ' ';
+$body .= elgg_view('input/text', array(
+ 'name' => 'params[bbb_security_salt]',
+ 'value' => $event_calendar_bbb_security_salt,
+ 'class' => 'text_input',
+));
+
+$body .= ' ';
+
echo $body;
--
cgit v1.2.3
From 7f1d64ed5f005e701af71023798346193a445401 Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Wed, 9 May 2012 18:06:56 +0200
Subject: fixed default group edit bug
---
models/model.php | 4 ++++
views/default/forms/event_calendar/edit.php | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
(limited to 'models/model.php')
diff --git a/models/model.php b/models/model.php
index cf00c4b1c..b3ba4db80 100644
--- a/models/model.php
+++ b/models/model.php
@@ -1519,11 +1519,14 @@ function event_calendar_get_page_content_edit($page_type,$guid) {
if (elgg_instanceof($event, 'object', 'event_calendar') && $event->canEdit()) {
$body_vars['event'] = $event;
$body_vars['form_data'] = event_calendar_prepare_edit_form_vars($event);
+
$event_container = get_entity($event->container_guid);
if (elgg_instanceof($event_container, 'group')) {
elgg_push_breadcrumb(elgg_echo('event_calendar:group_breadcrumb'), 'event_calendar/group/'.$event->container_guid);
+ $body_vars['group_guid'] = $event_container->guid;
} else {
elgg_push_breadcrumb(elgg_echo('event_calendar:show_events_title'),'event_calendar/list');
+ $body_vars['group_guid'] = 0;
}
elgg_push_breadcrumb($event->title,$event->getURL());
elgg_push_breadcrumb(elgg_echo('event_calendar:manage_event_title'));
@@ -1547,6 +1550,7 @@ function event_calendar_get_page_content_edit($page_type,$guid) {
$content = elgg_echo('event_calendar:no_group');
}
} else {
+ $body_vars['group_guid'] = 0;
elgg_push_breadcrumb(elgg_echo('event_calendar:show_events_title'),'event_calendar/list');
elgg_push_breadcrumb(elgg_echo('event_calendar:add_event_title'));
diff --git a/views/default/forms/event_calendar/edit.php b/views/default/forms/event_calendar/edit.php
index 79e2a5d0b..d1c7967c3 100644
--- a/views/default/forms/event_calendar/edit.php
+++ b/views/default/forms/event_calendar/edit.php
@@ -140,7 +140,7 @@ $body = '';
+
+echo $body;
diff --git a/views/default/event_calendar/share_section.php b/views/default/event_calendar/share_section.php
new file mode 100644
index 000000000..134f07656
--- /dev/null
+++ b/views/default/event_calendar/share_section.php
@@ -0,0 +1,26 @@
+';
+$body .= ''.elgg_echo('event_calendar:permissions:header').' ';
+if($event_calendar_hide_access == 'yes') {
+ $event_calendar_default_access = elgg_get_plugin_setting('default_access', 'event_calendar');
+ if($event_calendar_default_access) {
+ $body .= elgg_view("input/hidden",array('name' => 'access_id','value'=>$event_calendar_default_access));
+ } else {
+ $body .= elgg_view("input/hidden",array('name' => 'access_id','value'=>ACCESS_DEFAULT));
+ }
+} else {
+ $body .= ''.elgg_echo('event_calendar:read_access').' ';
+ $body .= elgg_view("input/access",array('name' => 'access_id','value'=>$fd['access_id']));
+ $body .= '
';
+}
+if (elgg_plugin_exists('entity_admins')) {
+ $body .= elgg_echo('event_calendar:share_ownership:label');
+ $body .= ' ';
+ $body .= elgg_echo('event_calendar:share_ownership:description');
+ $body .= elgg_view('input/entity_admins_dropdown',array('entity'=>$vars['event']));
+}
+$body .= '';
+
+echo $body;
diff --git a/views/default/forms/event_calendar/edit.php b/views/default/forms/event_calendar/edit.php
index 278fdddce..6ea06a6b4 100644
--- a/views/default/forms/event_calendar/edit.php
+++ b/views/default/forms/event_calendar/edit.php
@@ -2,17 +2,15 @@
$event = $vars['event'];
$fd = $vars['form_data'];
-$personal_manage_options = array(
- elgg_echo('event_calendar:personal_manage:by_event:open') => 'open',
- elgg_echo('event_calendar:personal_manage:by_event:closed') => 'closed',
- elgg_echo('event_calendar:personal_manage:by_event:private') => 'private',
-);
-
$schedule_options = array(
- elgg_echo('event_calendar:schedule_type:poll')=>'poll',
+ elgg_echo('event_calendar:all_day_label') => 'all_day',
elgg_echo('event_calendar:schedule_type:fixed')=>'fixed',
);
+if (elgg_plugin_exists('event_poll')) {
+ $schedule_options = array_merge(array(elgg_echo('event_calendar:schedule_type:poll')=>'poll'),$schedule_options);
+}
+
$event_calendar_fewer_fields = elgg_get_plugin_setting('fewer_fields', 'event_calendar');
$event_calendar_repeating_events = elgg_get_plugin_setting('repeating_events', 'event_calendar');
@@ -20,12 +18,8 @@ $event_calendar_region_display = elgg_get_plugin_setting('region_display', 'even
$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_add_users = elgg_get_plugin_setting('add_users', 'event_calendar');
-$event_calendar_hide_access = elgg_get_plugin_setting('hide_access', '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_repeated_events = elgg_get_plugin_setting('repeated_events', 'event_calendar');
-$event_calendar_reminders = elgg_get_plugin_setting('reminders', 'event_calendar');
$event_calendar_bbb_server_url = elgg_get_plugin_setting('bbb_server_url', 'event_calendar');
if ($event_calendar_more_required == 'yes') {
@@ -49,53 +43,6 @@ foreach ($all_fields as $fn) {
}
if ($event) {
- /*$title = $event->title;
- $brief_description = $event->description;
- $venue = $event->venue;
- // this is a form redisplay, so take the values as submitted
- $start_date = $event->start_date;
- $end_date = $event->end_date;
-
- if ($event_calendar_region_display) {
- $region = $event->region;
- if (!$region) {
- $region = '-';
- }
- }
-
- if ($event_calendar_spots_display) {
- $spots = trim($event->spots);
- }
- if ($event_calendar_type_display) {
- $event_type = $event->event_type;
- if (!$event_type) {
- $event_type = '-';
- }
- }
- $fees = $event->fees;
- $contact = $event->contact;
- $organiser = $event->organiser;
- if ($event->tags) {
- $event_tags = $event->tags;
- } else {
- // old way
- $event_tags = $event->event_tags;
- }
- $reminder_number = $event->reminder_number;
- $reminder_interval = $event->reminder_interval;
-
- $long_description = $event->long_description;
- $access = $event->access_id;
- if ($event_calendar_times != 'no') {
- $start_time = $event->start_time;
- $end_time = $event->end_time;
- }
- if ($event_calendar_personal_manage == 'by_event') {
- $personal_manage = $event->personal_manage;
- if (!$personal_manage) {
- $personal_manage = 'open';
- }
- }*/
$event_action = 'manage_event';
$event_guid = $event->guid;
} else {
@@ -106,8 +53,7 @@ if ($event) {
$title = $fd['title'];
$brief_description = $fd['description'];
$venue = $fd['venue'];
-$start_date = $fd['start_date'];
-$end_date = $fd['end_date'];
+
$fees = $fd['fees'];
if ($event_calendar_spots_display) {
$spots = $fd['spots'];
@@ -122,19 +68,16 @@ $contact = $fd['contact'];
$organiser = $fd['organiser'];
$event_tags = $fd['tags'];
$all_day = $fd['all_day'];
-$send_reminder = $fd['send_reminder'];
-$reminder_number = $fd['reminder_number'];
-$reminder_interval = $fd['reminder_interval'];
$schedule_type = $fd['schedule_type'];
$long_description = $fd['long_description'];
-$access = $fd['access_id'];
-if ($event_calendar_times != 'no') {
+
+/*if ($event_calendar_times != 'no') {
$start_time = $fd['start_time'];
$end_time = $fd['end_time'];
}
if ($event_calendar_personal_manage == 'by_event') {
$personal_manage = $fd['personal_manage'];
-}
+}*/
$body = '';
@@ -187,15 +130,11 @@ $body .= '
';
$body .= '';
+
+$body .= '
';
$body .= '';
// the following feature has been superceded by the manage subscribers feature
@@ -250,23 +192,27 @@ $body .= '';
$body .= ''.elgg_echo('event_calendar:add_user_description').'
';
}*/
-if ($event_calendar_personal_manage == 'by_event') {
+$body .= elgg_view('event_calendar/personal_manage_section',$vars);
+
+/*if ($event_calendar_personal_manage == 'by_event') {
$body .= '';
-}
+}*/
-$body .= '';*/
if ($event_calendar_region_display == 'yes' || $event_calendar_type_display == 'yes' || $event_calendar_fewer_fields != 'yes') {
$body .= '';
diff --git a/views/default/input/datepicker_inline.php b/views/default/input/datepicker_inline.php
index 1d0a0689d..3fd9c37af 100644
--- a/views/default/input/datepicker_inline.php
+++ b/views/default/input/datepicker_inline.php
@@ -65,7 +65,6 @@ $("#").datepicker({
document.location.href = "".replace('%s', date.substring(0,10));
},
dateFormat: "yy-mm-dd",
-
defaultDate: "",
beforeShowDay: highlightWeek
});
@@ -76,7 +75,7 @@ if ("" == "month") {
end_date += 1;
}
$("#").datepicker("setDate", start_date, end_date);
-var done_loading = true;
+done_loading = true;
});
diff --git a/views/default/input/timepicker.php b/views/default/input/timepicker.php
index ccbb88778..2cc95ced7 100644
--- a/views/default/input/timepicker.php
+++ b/views/default/input/timepicker.php
@@ -1,5 +1,4 @@
'am','pm'=>'pm');
+ if ($hour == 0) {
+ $hour = 12;
+ $meridian = 'am';
+ } else if ($hour == 12) {
+ $meridian = 'pm';
+ } else if ($hour < 12) {
+ $meridian = 'am';
} else {
- $h1 = 0;
- $h2 = 11;
+ $hour -= 12;
+ $meridian = 'pm';
}
- for($h=$h1;$h<=12;$h++) {
- $ht = sprintf("%02d",$h);
- for($m=0;$m<60;$m=$m+15) {
- $mt = sprintf("%02d",$m);
- $t = $h*60+$m;
- if ($h < 12) {
- $dates[$t] = "$ht:$mt am";
- } else {
- $dates[$t] = "$ht:$mt pm";
- }
- }
- }
- for($h=1;$h<$h2;$h++) {
- $ht = sprintf("%02d",$h);
- for($m=0;$m<60;$m=$m+15) {
- $mt = sprintf("%02d",$m);
- $t = 12*60+$h*60+$m;
- $dates[$t] = "$ht:$mt pm";
- }
- }
- if ($event_calendar_restricted_times == 'yes') {
- $m = 0;
- $h = 9;
- $ht = sprintf("%02d",$h);
- $mt = sprintf("%02d",$m);
- $t = 12*60+$h*60+$m;
- $dates[$t] = "$ht:$mt pm";
+ for($h=1;$h<=12;$h++) {
+ $hours[$h] = $h;
}
} else {
- if ($event_calendar_restricted_times == 'yes') {
- $h1 = 6;
- $h2 = 21;
- } else {
- $h1 = 0;
- $h2 = 24;
- }
- for($h=$h1;$h<$h2;$h++) {
- $ht = sprintf("%02d",$h);
- for($m=0;$m<60;$m=$m+15) {
- $mt = sprintf("%02d",$m);
- $t = $h*60+$m;
- $dates[$t] = "$ht:$mt";
- }
- }
- if ($event_calendar_restricted_times == 'yes') {
- $m = 0;
- $h = 21;
- $ht = sprintf("%02d",$h);
- $mt = sprintf("%02d",$m);
- $t = 12*60+$h*60+$m;
- $dates[$t] = "$ht:$mt pm";
+ for($h=0;$h<=23;$h++) {
+ $hours[$h] = $h;
}
-}
+}
-echo elgg_view('input/dropdown',array('name'=>$vars['name'],'value'=>$time,'options_values'=>$dates));
+for($m=0;$m<60;$m=$m+5) {
+ $mt = sprintf("%02d",$m);
+ $minutes[$m] = $mt;
+}
+echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_hour','value'=>$hour,'options_values'=>$hours));
+echo "
: ";
+echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_minute','value'=>$minute,'options_values'=>$minutes));
+if ($time_format == '12') {
+ echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_meridian','value'=>$meridian,'options_values'=>$meridians));
+}
diff --git a/views/default/js/event_calendar/event_calendar.php b/views/default/js/event_calendar/event_calendar.php
index b3ca2cc7b..244846f96 100644
--- a/views/default/js/event_calendar/event_calendar.php
+++ b/views/default/js/event_calendar/event_calendar.php
@@ -10,6 +10,8 @@ elgg.event_calendar.init = function () {
$('.event-calendar-repeating-unselected').live('click',elgg.event_calendar.handleRepeatingSelect);
$('.event-calendar-repeating-selected').live('click',elgg.event_calendar.handleRepeatingUnselect);
$('#event-calendar-edit').submit(elgg.event_calendar.handleEditFormSubmit);
+ $('#event-calendar-edit-schedule-type').click(elgg.event_calendar.handleScheduleType);
+ elgg.event_calendar.handleScheduleType();
var all_day_field = $('[name="all_day"][type="checkbox"]');
if (all_day_field.is(':checked')) {
@@ -21,6 +23,28 @@ elgg.event_calendar.init = function () {
all_day_field.change(elgg.event_calendar.handleAllDayField);
}
+elgg.event_calendar.handleScheduleType = function(e) {
+ var st = $('#event-calendar-edit-schedule-type:checked').val();
+ if (st == 'poll') {
+ $(".event-calendar-edit-date-wrapper").hide();
+ $(".event-calendar-edit-reminder-wrapper").hide();
+ $(".event-calendar-edit-form-membership-block").hide();
+ $(".event-calendar-edit-form-share-block").hide();
+ } else {
+ $(".event-calendar-edit-date-wrapper").show();
+ $(".event-calendar-edit-reminder-wrapper").show();
+ $(".event-calendar-edit-form-membership-block").show();
+ $(".event-calendar-edit-form-share-block").show();
+ if (st == 'all_day') {
+ $("[name='start_time']").hide();
+ $("#event-calendar-to-time-wrapper").hide();
+ } else {
+ $("[name='start_time']").show();
+ $("#event-calendar-to-time-wrapper").show();
+ }
+ }
+}
+
elgg.event_calendar.handleAllDayField = function(e) {
var field = $('[name="start_time"]');
if (field.attr('disabled') == 'disabled') {
--
cgit v1.2.3
From f22f6fd7a985b773bce95accf5172cdc2524575c Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Tue, 29 May 2012 12:35:20 +0200
Subject: added lightbox support for full calendar events
---
models/model.php | 20 ++++++++++++--------
start.php | 3 +++
views/default/event_calendar/full_calendar_view.php | 5 ++++-
3 files changed, 19 insertions(+), 9 deletions(-)
(limited to 'models/model.php')
diff --git a/models/model.php b/models/model.php
index 7de514802..b53471a44 100644
--- a/models/model.php
+++ b/models/model.php
@@ -1855,7 +1855,7 @@ function event_calendar_generate_listing_params($page_type,$container_guid,$orig
return $params;
}
-function event_calendar_get_page_content_view($event_guid) {
+function event_calendar_get_page_content_view($event_guid,$light_box = FALSE) {
// add personal calendar button and links
elgg_push_context('event_calendar:view');
$event = get_entity($event_guid);
@@ -1885,12 +1885,16 @@ function event_calendar_get_page_content_view($event_guid) {
$content .= elgg_view_comments($event);
}
}
-
- $params = array('title' => $title, 'content' => $content,'filter' => '');
-
- $body = elgg_view_layout("content", $params);
-
- return elgg_view_page($title,$body);
+
+ if ($light_box) {
+ return ''.elgg_view_title($title).$content.'
';
+ } else {
+ $params = array('title' => $title, 'content' => $content,'filter' => '');
+
+ $body = elgg_view_layout("content", $params);
+
+ return elgg_view_page($title,$body);
+ }
}
function event_calendar_get_page_content_display_users($event_guid) {
@@ -2135,7 +2139,7 @@ function event_calendar_get_page_content_fullcalendar_events($start_date,$end_da
'id' => $event->guid,
'guid' => $event->guid,
'title' => $event->title,
- 'url' => $event->getURL(),
+ 'url' => elgg_get_site_url().'event_calendar/view_light_box/'.$event->guid,
'start' => date('c',$ed['start_time']),
'end' => date('c',$ed['end_time']),
);
diff --git a/start.php b/start.php
index c9f95c8d6..9d3d45e4d 100644
--- a/start.php
+++ b/start.php
@@ -184,6 +184,9 @@ function event_calendar_page_handler($page) {
case 'view':
echo event_calendar_get_page_content_view($page[1]);
break;
+ case 'view_light_box':
+ echo event_calendar_get_page_content_view($page[1],TRUE);
+ break;
case 'display_users':
echo event_calendar_get_page_content_display_users($page[1]);
break;
diff --git a/views/default/event_calendar/full_calendar_view.php b/views/default/event_calendar/full_calendar_view.php
index 5fffff624..d7b6d97a2 100644
--- a/views/default/event_calendar/full_calendar_view.php
+++ b/views/default/event_calendar/full_calendar_view.php
@@ -1,5 +1,7 @@
@@ -7,7 +9,8 @@ elgg_load_js('elgg.full_calendar');
handleEventClick = function(event) {
if (event.url) {
- window.location.href = event.url;
+ //window.location.href = event.url;
+ $.fancybox({'href':event.url});
return false;
}
};
--
cgit v1.2.3
From 321fbfdb059e39b921e13ba034855b019981fa44 Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Tue, 29 May 2012 18:09:16 +0200
Subject: added click on calendar to preselect new event date
---
models/model.php | 17 ++++++----
start.php | 2 +-
views/default/event_calendar/css.php | 4 +++
.../default/event_calendar/full_calendar_view.php | 39 ++++++++++++++++++++++
4 files changed, 55 insertions(+), 7 deletions(-)
(limited to 'models/model.php')
diff --git a/models/model.php b/models/model.php
index b53471a44..d25c8dca3 100644
--- a/models/model.php
+++ b/models/model.php
@@ -1533,7 +1533,7 @@ function event_calendar_get_page_content_list($page_type,$container_guid,$start_
return elgg_view_page($title,$body);
}
-function event_calendar_get_page_content_edit($page_type,$guid) {
+function event_calendar_get_page_content_edit($page_type,$guid,$start_date='') {
elgg_load_js('elgg.event_calendar');
$vars = array();
$vars['id'] = 'event-calendar-edit';
@@ -1575,7 +1575,7 @@ function event_calendar_get_page_content_edit($page_type,$guid) {
$body_vars['group_guid'] = $guid;
elgg_push_breadcrumb(elgg_echo('event_calendar:group_breadcrumb'), 'event_calendar/group/'.$guid);
elgg_push_breadcrumb(elgg_echo('event_calendar:add_event_title'));
- $body_vars['form_data'] = event_calendar_prepare_edit_form_vars(NULL,$page_type);
+ $body_vars['form_data'] = event_calendar_prepare_edit_form_vars(NULL,$page_type,$start_date);
$content = elgg_view_form('event_calendar/edit', $vars, $body_vars);
} else {
$content = elgg_echo('event_calendar:no_group');
@@ -1585,7 +1585,7 @@ function event_calendar_get_page_content_edit($page_type,$guid) {
elgg_push_breadcrumb(elgg_echo('event_calendar:show_events_title'),'event_calendar/list');
elgg_push_breadcrumb(elgg_echo('event_calendar:add_event_title'));
- $body_vars['form_data'] = event_calendar_prepare_edit_form_vars(NULL,$page_type);
+ $body_vars['form_data'] = event_calendar_prepare_edit_form_vars(NULL,$page_type,$start_date);
$content = elgg_view_form('event_calendar/edit', $vars, $body_vars);
}
@@ -1604,20 +1604,25 @@ function event_calendar_get_page_content_edit($page_type,$guid) {
* @param ElggObject $event
* @return array
*/
-function event_calendar_prepare_edit_form_vars($event = NULL, $page_type = '') {
+function event_calendar_prepare_edit_form_vars($event = NULL, $page_type = '', $start_date = '') {
// input names => defaults
$now = time();
$iso_date = date('Y-m-d',$now);
$now_midnight = strtotime($iso_date);
+ if ($start_date) {
+ $start_date = strtotime($start_date);
+ } else {
+ $start_date = $now+60*60;
+ }
$start_time = floor(($now-$now_midnight)/60) + 60;
$start_time = floor($start_time/5)*5;
$values = array(
'title' => NULL,
'description' => NULL,
'venue' => NULL,
- 'start_date' => $now+60*60,
- 'end_date' => $now+2*60*60,
+ 'start_date' => $start_date,
+ 'end_date' => $start_date+60*60,
'start_time' => $start_time,
'end_time' => $start_time + 60,
'spots' => NULL,
diff --git a/start.php b/start.php
index 9d3d45e4d..8c8bba19b 100644
--- a/start.php
+++ b/start.php
@@ -202,7 +202,7 @@ function event_calendar_page_handler($page) {
gatekeeper();
$group_guid = 0;
}
- echo event_calendar_get_page_content_edit($page_type,$group_guid);
+ echo event_calendar_get_page_content_edit($page_type,$group_guid,$page[2]);
break;
case 'edit':
gatekeeper();
diff --git a/views/default/event_calendar/css.php b/views/default/event_calendar/css.php
index 9461a7fe9..b1e17e4df 100644
--- a/views/default/event_calendar/css.php
+++ b/views/default/event_calendar/css.php
@@ -275,3 +275,7 @@ li.event-calendar-filter-menu-show-only {
clear: both;
margin-bottom: 5px;
}
+
+.event-calendar-date-selected {
+ background-color: #DDDDFF;
+}
diff --git a/views/default/event_calendar/full_calendar_view.php b/views/default/event_calendar/full_calendar_view.php
index d7b6d97a2..d86a3ac27 100644
--- a/views/default/event_calendar/full_calendar_view.php
+++ b/views/default/event_calendar/full_calendar_view.php
@@ -15,6 +15,28 @@ handleEventClick = function(event) {
}
};
+handleDayClick = function(date,allDay,jsEvent,view) {
+ var iso = getISODate(date);
+ var link = $('.elgg-menu-item-event-calendar-0add').find('a').attr('href');
+ var ss = link.split('/');
+ var link = $('.elgg-menu-item-event-calendar-0add').find('a').attr('href');
+ var ss = link.split('/');
+ var last_ss = ss[ss.length-1];
+ var group_guid;
+ if (last_ss == 'add') {
+ group_guid = 0;
+ } else if (last_ss.split('-').length == 3) {
+ group_guid = ss[ss.length-2];
+ } else {
+ group_guid = last_ss;
+ }
+ var url = elgg.get_site_url();
+ $('.elgg-menu-item-event-calendar-0add').find('a').attr('href',url+'event_calendar/add/'+group_guid+'/'+iso);
+ $('.elgg-menu-item-event-calendar-1schedule').find('a').attr('href',url+'event_calendar/schedule/'+group_guid+'/'+iso);
+ $('.fc-widget-content').removeClass('event-calendar-date-selected');
+ $(this).addClass('event-calendar-date-selected');
+}
+
handleEventDrop = function(event,dayDelta,minuteDelta,allDay,revertFunc) {
if (!confirm("")) {
@@ -54,6 +76,22 @@ handleGetEvents = function(start, end, callback) {
callback(events);
}
});
+ // reset date links and classes
+ $('.fc-widget-content').removeClass('event-calendar-date-selected');
+ var link = $('.elgg-menu-item-event-calendar-0add').find('a').attr('href');
+ var ss = link.split('/');
+ var last_ss = ss[ss.length-1];
+ var group_guid;
+ if (last_ss == 'add') {
+ group_guid = 0;
+ } else if (last_ss.split('-').length == 3) {
+ group_guid = ss[ss.length-2];
+ } else {
+ group_guid = last_ss;
+ }
+ var url = elgg.get_site_url();
+ $('.elgg-menu-item-event-calendar-0add').find('a').attr('href',url+'event_calendar/add/'+group_guid);
+ $('.elgg-menu-item-event-calendar-1schedule').find('a').attr('href',url+'event_calendar/schedule/'+group_guid);
}
$(document).ready(function() {
@@ -69,6 +107,7 @@ $(document).ready(function() {
slotMinutes: 15,
eventDrop: handleEventDrop,
eventClick: handleEventClick,
+ dayClick: handleDayClick,
events: handleGetEvents
});
});
--
cgit v1.2.3
From d760deb0117b3a1b1adec1b38c73ebe412d02e1e Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Thu, 21 Jun 2012 15:55:59 +0200
Subject: small tweaks for UF
---
languages/en.php | 3 ++-
models/model.php | 6 +++++-
views/default/event_calendar/full_calendar_view.php | 21 +++++++++++++++++----
3 files changed, 24 insertions(+), 6 deletions(-)
(limited to 'models/model.php')
diff --git a/languages/en.php b/languages/en.php
index 782cd7a72..3d8c94e3f 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -50,7 +50,7 @@
'event_calendar:month_label' => "Month",
'event_calendar:group' => "Group calendar",
'event_calendar:new' => "Add event",
- 'event_calendar:submit' => "Submit",
+ 'event_calendar:submit' => "Save and Continue",
'event_calendar:cancel' => "Cancel",
'event_calendar:widget_title' => "Event calendar",
'event_calendar:widget:description' => "Displays your events.",
@@ -310,6 +310,7 @@ You can manage calendar requests for this event here:
'event_calendar:settings:reminders:title' => "Allow sending reminders",
'event_calendar:reminder:subject' => "Reminder for event: %s",
'event_calendar:poll_suffix' => "(poll)",
+ 'event_calendar:cannot_drag_polls' => "Cannot change event polls.",
'event_calendar:reminder:body' => "The event
%s
diff --git a/models/model.php b/models/model.php
index d25c8dca3..aea6bca2f 100644
--- a/models/model.php
+++ b/models/model.php
@@ -2144,7 +2144,6 @@ function event_calendar_get_page_content_fullcalendar_events($start_date,$end_da
'id' => $event->guid,
'guid' => $event->guid,
'title' => $event->title,
- 'url' => elgg_get_site_url().'event_calendar/view_light_box/'.$event->guid,
'start' => date('c',$ed['start_time']),
'end' => date('c',$ed['end_time']),
);
@@ -2157,6 +2156,11 @@ function event_calendar_get_page_content_fullcalendar_events($start_date,$end_da
if ($polls_supported && isset($e['is_event_poll']) && $e['is_event_poll']) {
$event_item['className'] = 'event-poll-class';
$event_item['title'] .= ' '.elgg_echo('event_calendar:poll_suffix');
+ $event_item['is_event_poll'] = TRUE;
+ $event_item['url'] = elgg_get_site_url().'event_poll/vote/'.$event->guid;
+ } else {
+ $event_item['is_event_poll'] = FALSE;
+ $event_item['url'] = elgg_get_site_url().'event_calendar/view_light_box/'.$event->guid;
}
$event_array[] = $event_item;
diff --git a/views/default/event_calendar/full_calendar_view.php b/views/default/event_calendar/full_calendar_view.php
index d86a3ac27..bba3a66db 100644
--- a/views/default/event_calendar/full_calendar_view.php
+++ b/views/default/event_calendar/full_calendar_view.php
@@ -9,8 +9,12 @@ elgg_load_css('lightbox');
handleEventClick = function(event) {
if (event.url) {
- //window.location.href = event.url;
- $.fancybox({'href':event.url});
+ if (event.is_event_poll) {
+ window.location.href = event.url;
+ } else {
+ //window.location.href = event.url;
+ $.fancybox({'href':event.url});
+ }
return false;
}
};
@@ -38,8 +42,10 @@ handleDayClick = function(date,allDay,jsEvent,view) {
}
handleEventDrop = function(event,dayDelta,minuteDelta,allDay,revertFunc) {
-
- if (!confirm("")) {
+ if (event.is_event_poll) {
+ alert("");
+ revertFunc();
+ } else if (!confirm("")) {
revertFunc();
} else {
elgg.action('event_calendar/modify_full_calendar',
@@ -67,6 +73,12 @@ getISODate = function(d) {
return year +"-"+month+"-"+day;
}
+handleEventRender = function(event, element, view) {
+ if (event.is_event_poll) {
+ element.draggable = false;
+ }
+}
+
handleGetEvents = function(start, end, callback) {
var start_date = getISODate(start);
var end_date = getISODate(end);
@@ -105,6 +117,7 @@ $(document).ready(function() {
ignoreTimezone: true,
editable: true,
slotMinutes: 15,
+ eventRender: handleEventRender,
eventDrop: handleEventDrop,
eventClick: handleEventClick,
dayClick: handleDayClick,
--
cgit v1.2.3
From 0e264d23ae1b4c4a186cb855ed984bb082908fbb Mon Sep 17 00:00:00 2001
From: Kevin Jardine
Date: Tue, 26 Jun 2012 21:41:58 +0200
Subject: more changes to support event polls
---
actions/event_calendar/modify_full_calendar.php | 13 +++++-
languages/en.php | 5 ++-
models/model.php | 48 +++++++++++---------
start.php | 4 +-
.../default/event_calendar/full_calendar_view.php | 51 ++++++++++++++--------
5 files changed, 76 insertions(+), 45 deletions(-)
(limited to 'models/model.php')
diff --git a/actions/event_calendar/modify_full_calendar.php b/actions/event_calendar/modify_full_calendar.php
index 595bdbe4b..9288eb0e0 100644
--- a/actions/event_calendar/modify_full_calendar.php
+++ b/actions/event_calendar/modify_full_calendar.php
@@ -3,9 +3,18 @@ elgg_load_library('elgg:event_calendar');
$event_guid = get_input('event_guid',0);
$day_delta = get_input('dayDelta');
$minute_delta = get_input('minuteDelta','');
-
-if (event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delta)) {
+$start_time = get_input('startTime','');
+$resend = get_input('resend','');
+$minutes = get_input('minutes');
+$iso_date = get_input('iso_date');
+$result = event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delta,$start_time,$resend,$minutes,$iso_date);
+if ($result) {
$response = array('success'=>TRUE);
+ // specially handling for event polls
+ if (is_array($result)) {
+ $response['minutes'] = $result['minutes'];
+ $response['iso_date'] = $result['iso_date'];
+ }
} else {
$response = array('success'=>FALSE, 'message' =>elgg_echo('event_calendar:modify_full_calendar:error'));
}
diff --git a/languages/en.php b/languages/en.php
index 3d8c94e3f..3fd9cf7cb 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -309,8 +309,6 @@ You can manage calendar requests for this event here:
'event_calendar:settings:repeated_events:title' => "Allow repeated events (currently only works properly in full calendar mode)",
'event_calendar:settings:reminders:title' => "Allow sending reminders",
'event_calendar:reminder:subject' => "Reminder for event: %s",
- 'event_calendar:poll_suffix' => "(poll)",
- 'event_calendar:cannot_drag_polls' => "Cannot change event polls.",
'event_calendar:reminder:body' => "The event
%s
@@ -332,6 +330,9 @@ You can visit the event page here:
'event_calendar:bbb_create_error' => "Error: unable to create BBB conference, message was: %s",
'event_calendar:bbb_settings_error' => "Error: must set conference URL and salt in plugin settings",
'event_calendar:join_conf_button' => "Join conference",
+
+ 'event_calendar:poll_suffix' => "(poll)",
+ 'event_calendar:resend_poll_invitation' => "Do you want to alert poll invitees that the options have changed?",
/**
* Event calendar river
diff --git a/models/model.php b/models/model.php
index aea6bca2f..2752626bc 100644
--- a/models/model.php
+++ b/models/model.php
@@ -2091,28 +2091,34 @@ function getLastDayOfMonth($month,$year) {
return idate('d', mktime(0, 0, 0, ($month + 1), 0, $year));
}
-// TODO - this is not quite right across daylight savings time divides
-// Possible solution: convert stored date to server date, do inc and then convert back to GMT
-
-function event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delta) {
+function event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delta,$start_time,$resend,$minutes,$iso_date) {
$event = get_entity($event_guid);
if (elgg_instanceof($event,'object','event_calendar') && $event->canEdit()) {
- $event->start_date = strtotime("$day_delta days",$event->start_date)+60*$minute_delta;
- if ($event->end_date) {
- $event->end_date = strtotime("$day_delta days",$event->end_date);
- }
- $times = elgg_get_plugin_setting('times','event_calendar');
- //$inc = 24*60*60*$day_delta+60*$minute_delta;
-
- //$event->real_end_time += $inc;
- $event->real_end_time = strtotime("$day_delta days",$event->real_end_time)+60*$minute_delta;
- if ($times != 'no') {
- $event->start_time += $minute_delta;
- if ($event->end_time) {
- $event->end_time += $minute_delta;
+ if ($event->is_event_poll) {
+ if (elgg_is_active_plugin('event_poll')) {
+ elgg_load_library('elgg:event_poll');
+ return event_poll_change($event_guid,$day_delta,$minute_delta,$start_time,$resend,$minutes,$iso_date);
+ } else {
+ return FALSE;
+ }
+ } else {
+ $event->start_date = strtotime("$day_delta days",$event->start_date)+60*$minute_delta;
+ if ($event->end_date) {
+ $event->end_date = strtotime("$day_delta days",$event->end_date);
}
+ $times = elgg_get_plugin_setting('times','event_calendar');
+ //$inc = 24*60*60*$day_delta+60*$minute_delta;
+
+ //$event->real_end_time += $inc;
+ $event->real_end_time = strtotime("$day_delta days",$event->real_end_time)+60*$minute_delta;
+ if ($times != 'no') {
+ $event->start_time += $minute_delta;
+ if ($event->end_time) {
+ $event->end_time += $minute_delta;
+ }
+ }
+ return TRUE;
}
- return TRUE;
}
return FALSE;
}
@@ -2134,14 +2140,13 @@ function event_calendar_get_page_content_fullcalendar_events($start_date,$end_da
}
$event_array = array();
$times_supported = elgg_get_plugin_setting('times','event_calendar') != 'no';
- $polls_supported = elgg_plugin_exists('event_poll');
+ $polls_supported = elgg_is_active_plugin('event_poll');
foreach($events as $e) {
$event = $e['event'];
$event_data = $e['data'];
$c = count($event_data);
foreach($event_data as $ed) {
$event_item = array(
- 'id' => $event->guid,
'guid' => $event->guid,
'title' => $event->title,
'start' => date('c',$ed['start_time']),
@@ -2158,7 +2163,10 @@ function event_calendar_get_page_content_fullcalendar_events($start_date,$end_da
$event_item['title'] .= ' '.elgg_echo('event_calendar:poll_suffix');
$event_item['is_event_poll'] = TRUE;
$event_item['url'] = elgg_get_site_url().'event_poll/vote/'.$event->guid;
+ $event_item['minutes'] = $ed['minutes'];
+ $event_item['iso_date'] = $ed['iso_date'];
} else {
+ $event_item['id'] = $event->guid;
$event_item['is_event_poll'] = FALSE;
$event_item['url'] = elgg_get_site_url().'event_calendar/view_light_box/'.$event->guid;
}
diff --git a/start.php b/start.php
index ebd88d541..dd5437944 100644
--- a/start.php
+++ b/start.php
@@ -66,7 +66,7 @@ function event_calendar_init() {
elgg_extend_view('css/elgg', 'event_calendar/css');
$event_calendar_listing_format = elgg_get_plugin_setting('listing_format', 'event_calendar');
- if (elgg_plugin_exists('event_poll') || ($event_calendar_listing_format == 'full')) {
+ if (elgg_is_active_plugin('event_poll') || ($event_calendar_listing_format == 'full')) {
elgg_extend_view('css/elgg', 'fullcalendar/css');
$plugin_js = elgg_get_simplecache_url('js', 'event_calendar/fullcalendar');
elgg_register_js('elgg.full_calendar', $plugin_js);
@@ -293,7 +293,7 @@ function event_calendar_entity_menu_setup($hook, $type, $return, $params) {
if ($handler != 'event_calendar') {
return $return;
}
- if (elgg_plugin_exists('event_poll') && $entity->canEdit() && $entity->schedule_type == 'poll') {
+ if (elgg_is_active_plugin('event_poll') && $entity->canEdit() && $entity->schedule_type == 'poll') {
$options = array(
'name' => 'schedule',
'text' => elgg_echo('event_poll:schedule_button'),
diff --git a/views/default/event_calendar/full_calendar_view.php b/views/default/event_calendar/full_calendar_view.php
index 6ba8fe892..4316b5359 100644
--- a/views/default/event_calendar/full_calendar_view.php
+++ b/views/default/event_calendar/full_calendar_view.php
@@ -54,21 +54,32 @@ handleDayClick = function(date,allDay,jsEvent,view) {
}
handleEventDrop = function(event,dayDelta,minuteDelta,allDay,revertFunc) {
- if (event.is_event_poll) {
- alert("");
- revertFunc();
- } else if (!confirm("")) {
+
+ if (!event.is_event_poll && !confirm("")) {
revertFunc();
} else {
+ if (event.is_event_poll) {
+ if (confirm("")) {
+ var resend = 1;
+ } else {
+ resend = 0;
+ }
+ var data = {event_guid: event.guid, startTime: event.start.toISOString(), dayDelta: dayDelta, minuteDelta: minuteDelta, resend: resend, minutes: event.minutes, iso_date: event.iso_date};
+ } else {
+ data = {event_guid: event.guid, startTime: event.start.toISOString(), dayDelta: dayDelta, minuteDelta: minuteDelta};
+ }
elgg.action('event_calendar/modify_full_calendar',
{
- data: {event_guid: event.guid,dayDelta: dayDelta, minuteDelta: minuteDelta},
+ data: data,
success: function (res) {
var success = res.success;
var msg = res.message;
if (!success) {
elgg.register_error(msg,2000);
revertFunc()
+ } else {
+ event.minutes = res.minutes;
+ event.iso_date = res.iso_date;
}
}
}
@@ -86,9 +97,9 @@ getISODate = function(d) {
}
handleEventRender = function(event, element, view) {
- if (event.is_event_poll) {
+ /*if (event.is_event_poll) {
element.draggable = false;
- }
+ }*/
}
handleGetEvents = function(start, end, callback) {
@@ -103,19 +114,21 @@ handleGetEvents = function(start, end, callback) {
// reset date links and classes
//$('.fc-widget-content').removeClass('event-calendar-date-selected');
var link = $('.elgg-menu-item-event-calendar-0add').find('a').attr('href');
- var ss = link.split('/');
- var last_ss = ss[ss.length-1];
- var group_guid;
- if (last_ss == 'add') {
- group_guid = 0;
- } else if (last_ss.split('-').length == 3) {
- group_guid = ss[ss.length-2];
- } else {
- group_guid = last_ss;
+ if (link != undefined) {
+ var ss = link.split('/');
+ var last_ss = ss[ss.length-1];
+ var group_guid;
+ if (last_ss == 'add') {
+ group_guid = 0;
+ } else if (last_ss.split('-').length == 3) {
+ group_guid = ss[ss.length-2];
+ } else {
+ group_guid = last_ss;
+ }
+ var url = elgg.get_site_url();
+ $('.elgg-menu-item-event-calendar-0add').find('a').attr('href',url+'event_calendar/add/'+group_guid);
+ $('.elgg-menu-item-event-calendar-1schedule').find('a').attr('href',url+'event_calendar/schedule/'+group_guid);
}
- var url = elgg.get_site_url();
- $('.elgg-menu-item-event-calendar-0add').find('a').attr('href',url+'event_calendar/add/'+group_guid);
- $('.elgg-menu-item-event-calendar-1schedule').find('a').attr('href',url+'event_calendar/schedule/'+group_guid);
}
handleViewDisplay = function(view) {
--
cgit v1.2.3
From bd6840a34cd9d3b3afabf3f6c977f8cea5a32662 Mon Sep 17 00:00:00 2001
From: Matt Beckett
Date: Tue, 3 Jul 2012 12:54:06 -0600
Subject: removed old widget file Allows calendar widget to be useful in groups
context
---
models/model.php | 4 +--
views/default/widgets/event_calendar/content.php | 8 +++--
views/default/widgets/event_calendar/view.php | 39 ------------------------
3 files changed, 8 insertions(+), 43 deletions(-)
delete mode 100644 views/default/widgets/event_calendar/view.php
(limited to 'models/model.php')
diff --git a/models/model.php b/models/model.php
index 2752626bc..ba1393a8c 100644
--- a/models/model.php
+++ b/models/model.php
@@ -1150,12 +1150,12 @@ function event_calendar_security_fields() {
return "__elgg_token=$token&__elgg_ts=$ts";
}
-function event_calendar_get_events_for_group($group_guid) {
+function event_calendar_get_events_for_group($group_guid, $limit = 0) {
$options = array(
'type' => 'object',
'subtype' => 'event_calendar',
'container_guid' => $group_guid,
- 'limit' => 0,
+ 'limit' => $limit,
);
return elgg_get_entities($options);
}
diff --git a/views/default/widgets/event_calendar/content.php b/views/default/widgets/event_calendar/content.php
index 329046cb0..eaedb76bd 100644
--- a/views/default/widgets/event_calendar/content.php
+++ b/views/default/widgets/event_calendar/content.php
@@ -20,8 +20,12 @@
$num = 5;
// Get the events
-
- $events = event_calendar_get_personal_events_for_user(elgg_get_page_owner_guid(),$num);
+ $owner = elgg_get_page_owner_entity();
+ if(elgg_instanceof($owner, 'group')) {
+ $events = event_calendar_get_events_for_group(elgg_get_page_owner_guid(),$num);
+ } else {
+ $events = event_calendar_get_personal_events_for_user(elgg_get_page_owner_guid(),$num);
+ }
// If there are any events to view, view them
if (is_array($events) && sizeof($events) > 0) {
diff --git a/views/default/widgets/event_calendar/view.php b/views/default/widgets/event_calendar/view.php
deleted file mode 100644
index 329046cb0..000000000
--- a/views/default/widgets/event_calendar/view.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
- * @copyright Radagast Solutions 2008
- * @link http://radagast.biz/
- *
- */
-
- // Load event calendar model
- elgg_load_library('elgg:event_calendar');
-
- //the number of events to display
- $num = (int) $vars['entity']->num_display;
- if (!$num)
- $num = 5;
-
- // Get the events
-
- $events = event_calendar_get_personal_events_for_user(elgg_get_page_owner_guid(),$num);
-
- // If there are any events to view, view them
- if (is_array($events) && sizeof($events) > 0) {
-
- echo "";
-
- foreach($events as $event) {
- echo elgg_view("object/event_calendar",array('entity' => $event));
- }
-
- echo "
";
-
- }
-
-?>
\ No newline at end of file
--
cgit v1.2.3