From aa04adce03438348c52477eacbd611c83d3caf68 Mon Sep 17 00:00:00 2001 From: Kevin Jardine Date: Mon, 2 Jan 2012 15:09:06 +0100 Subject: added new userpicker for site-wide event user management --- actions/event_calendar/manage_subscribers.php | 17 ++++++++++++ languages/en.php | 5 +++- models/model.php | 30 +++++++++++----------- start.php | 1 + .../forms/event_calendar/manage_subscribers.php | 14 ++++++++++ 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 actions/event_calendar/manage_subscribers.php create mode 100644 views/default/forms/event_calendar/manage_subscribers.php diff --git a/actions/event_calendar/manage_subscribers.php b/actions/event_calendar/manage_subscribers.php new file mode 100644 index 000000000..212150082 --- /dev/null +++ b/actions/event_calendar/manage_subscribers.php @@ -0,0 +1,17 @@ +canEdit()) { + $members = get_input('members'); + // clear the event from all personal calendars + remove_entity_relationships($event_guid, 'personal_event', TRUE); + // add event to personal calendars + foreach ($members as $user_guid) { + add_entity_relationship($user_guid,'personal_event',$event_guid); + } + system_message(elgg_echo('event_calendar:manage_subscribers:success')); + forward($event->getURL()); +} else { + register_error(elgg_echo('event_calendar:manage_subscribers:error')); + forward(); +} diff --git a/languages/en.php b/languages/en.php index 285392e62..d16085994 100644 --- a/languages/en.php +++ b/languages/en.php @@ -230,7 +230,7 @@ You can manage calendar requests for this event here: 'event_calendar:listing_title:friends' => "Friends' calendars", 'event_calendar:manage_users:title' => "Manage subscribers for \"%s\"", 'event_calendar:manage_users:breadcrumb' => "Manage subscribers", - 'event_calendar:manage_users:description' => "You can add or remove events from personal calendars using the buttons below.", + 'event_calendar:manage_users:description' => "Add or remove events from personal calendars.", 'event_calendar:manage_users:unauthorized' => "Error: you are not authorised to manage personal calendars for this event.", 'event_calendar:add_to_group_members:success' => "This event has been added to the personal calendars of all group members.", 'event_calendar:add_to_group_members:error' => "Error: could not add this event to the personal calendars of group members.", @@ -239,6 +239,9 @@ You can manage calendar requests for this event here: 'event_calendar:add_to_group_members:button' => "Add to all", 'event_calendar:remove_from_group_members:button' => "Remove from all", + 'event_calendar:manage_subscribers:success' => "Personal calendars updated.", + 'event_calendar:manage_subscribers:error' => "Error: could not update personal calendars.", + /** * Event calendar river **/ diff --git a/models/model.php b/models/model.php index db2bdf95d..65a9215af 100644 --- a/models/model.php +++ b/models/model.php @@ -1561,8 +1561,6 @@ function event_calendar_get_page_content_manage_users($event_guid) { elgg_push_context('groups'); elgg_set_page_owner_guid($event->container_guid); elgg_push_breadcrumb(elgg_echo('event_calendar:group_breadcrumb'), 'event_calendar/group/'.$event->container_guid); - $users = $event_container->getMembers($limit,$offset); - $count = $event_container->getMembers($limit,$offset,TRUE); elgg_register_menu_item('title', array( 'name' => 'remove_from_group_members', 'href' => elgg_add_action_tokens_to_url('action/event_calendar/remove_from_group_members?event_guid='.$event_guid), @@ -1575,24 +1573,26 @@ function event_calendar_get_page_content_manage_users($event_guid) { 'text' => elgg_echo('event_calendar:add_to_group_members:button'), 'class' => 'elgg-button elgg-button-action', )); + $users = $event_container->getMembers($limit,$offset); + $count = $event_container->getMembers($limit,$offset,TRUE); + elgg_extend_view('user/default','event_calendar/calendar_toggle'); + $options = array( + 'full_view' => FALSE, + 'list_type_toggle' => FALSE, + 'limit'=>$limit, + 'event_calendar_event'=>$event, + 'pagination' => TRUE, + 'count'=>$count, + ); + $content .= elgg_view_entity_list($users,$options,$offset,$limit); } else { elgg_push_breadcrumb(elgg_echo('event_calendar:show_events_title'),'event_calendar/list'); - $users = elgg_get_entities(array('type'=>'user','limit'=>$limit,'offset'=>$offset)); - $count = elgg_get_entities(array('type'=>'user','count'=>TRUE)); + $content = '

'.elgg_echo('event_calendar:manage_users:description').'

'; + $content .= elgg_view_form('event_calendar/manage_subscribers',array(),array('event'=>$event)); } elgg_push_breadcrumb($event->title,$event->getURL()); elgg_push_breadcrumb(elgg_echo('event_calendar:manage_users:breadcrumb')); - $options = array( - 'full_view' => FALSE, - 'list_type_toggle' => FALSE, - 'limit'=>$limit, - 'event_calendar_event'=>$event, - 'pagination' => TRUE, - 'count'=>$count, - ); - elgg_extend_view('user/default','event_calendar/calendar_toggle'); - $content = '

'.elgg_echo('event_calendar:manage_users:description').'

'; - $content .= elgg_view_entity_list($users,$options,$offset,$limit); + } else { $content = elgg_echo('event_calendar:manage_users:unauthorized'); } diff --git a/start.php b/start.php index b8c79ca37..5cfc9fd3a 100644 --- a/start.php +++ b/start.php @@ -99,6 +99,7 @@ function event_calendar_init() { elgg_register_action("event_calendar/remove_from_group","$action_path/remove_from_group.php"); elgg_register_action("event_calendar/add_to_group_members","$action_path/add_to_group_members.php"); elgg_register_action("event_calendar/remove_from_group_members","$action_path/remove_from_group_members.php"); + elgg_register_action("event_calendar/manage_subscribers","$action_path/manage_subscribers.php"); } diff --git a/views/default/forms/event_calendar/manage_subscribers.php b/views/default/forms/event_calendar/manage_subscribers.php new file mode 100644 index 000000000..8039c5015 --- /dev/null +++ b/views/default/forms/event_calendar/manage_subscribers.php @@ -0,0 +1,14 @@ +guid,0); +$guids = array(); +foreach($users as $user) { + $guids[] = $user->guid; +} +// TODO: if the event container is a group need to restrict user picker to the members of the group? +$content = elgg_view('input/userpicker_plus',array('value'=> $guids)); +$content .= '

'; +$content .= elgg_view('input/hidden',array('name'=>'event_guid','value'=>$event->guid)); +$content .= elgg_view('input/submit',array('value'=>elgg_echo('submit'),'name'=>'submit_manage_subscribers','id'=>'submit-manage-subscribers')); + +echo $content; -- cgit v1.2.3