From ab7d70b9d870d69a5b79c3fbb005565302112efc Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 31 Jul 2008 15:22:48 +0000 Subject: Picker saves correctly! git-svn-id: https://code.elgg.org/elgg/trunk@1635 36083f99-b078-4883-b0ff-0f9b5a30f544 --- actions/friends/editcollection.php | 37 ++----------- engine/lib/access.php | 31 ++++++++++- friends/pickercallback.php | 9 +++- languages/en.php | 1 + views/default/friends/collection.php | 6 +-- views/default/friends/collectiontabs.php | 19 ++----- views/default/friends/forms/collectionfields.php | 23 ++++++++ views/default/friends/forms/edit.php | 7 +-- views/default/friends/picker.php | 69 +++++++++++++++++++++--- 9 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 views/default/friends/forms/collectionfields.php diff --git a/actions/friends/editcollection.php b/actions/friends/editcollection.php index f8458da46..fd1944c51 100644 --- a/actions/friends/editcollection.php +++ b/actions/friends/editcollection.php @@ -11,42 +11,11 @@ * @link http://elgg.org/ */ - //must be logged in - gatekeeper(); - $collection_id = get_input('collection_id'); $collection_name = get_input('collection_name'); + $friends = get_input('friend'); - //$friends = get_input('friends_collection'); - - //chech the colelction exists and the current user owners it - if($full_collection = get_access_collection($collection_id)){ - - //first check to make sure that a collection name has been set and create the new colection - if($collection_name){ - - //create the collection - $create_collection = create_access_collection($collection_name, $_SESSION['user']->getGUID()); - - - // Success message - system_message(elgg_echo("friends:collectionadded")); - // Forward to the collections page - forward("pg/collections/" . $_SESSION['user']->username); - - } else { - - register_error(elgg_echo("friends:nocollectionname")); - - } - - } else { - - register_error(elgg_echo("friends:nocollectionname")); - - } - - // Forward to the add collection page - forward("pg/collections/add"); + //chech the collection exists and the current user owners it + update_access_collection($collection_id, $friends); ?> \ No newline at end of file diff --git a/engine/lib/access.php b/engine/lib/access.php index 2c9a886e6..a1741f8bf 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -201,6 +201,33 @@ } + /** + * Updates the membership in an access collection. + * + * @param int $collection_id The ID of the collection. + * @param array $members Array of member GUIDs + * @return true|false Depending on success + */ + function update_access_collection($collection_id, $members) { + + global $CONFIG; + $collection_id = (int) $collection_id; + + if ($collection = get_access_collection($collection_id)) { + delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}"); + } + + if (is_array($members) && sizeof($members) > 0) { + foreach($members as $member) { + $member = (int) $member; + add_user_to_access_collection($member, $collection_id); + } + return true; + } + + return false; + } + /** * Deletes a specified access collection * @@ -232,7 +259,7 @@ $collection_id = (int) $collection_id; global $CONFIG; - $get_collection = get_data("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}"); + $get_collection = get_data_row("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}"); return $get_collection; @@ -252,7 +279,7 @@ $collections = get_write_access_array(); if (array_key_exists($collection_id, $collections) && $user = get_user($user_guid)) { - + global $CONFIG; insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$user_guid}"); return true; diff --git a/friends/pickercallback.php b/friends/pickercallback.php index 2a6a55439..478549d3d 100644 --- a/friends/pickercallback.php +++ b/friends/pickercallback.php @@ -13,17 +13,20 @@ // Load Elgg engine require_once(dirname(dirname(__FILE__)) . "/engine/start.php"); + global $CONFIG; // Get callback type (list or picker) $type = get_input('type','picker'); // Get list of members if applicable - $members = get_input('members',''); + /*$members = get_input('members',''); if (!empty($members)) { $members = explode(',',$members); } else { $members = array(); - } + }*/ + $collection = (int) get_input('collection',0); + $members = get_members_of_access_collection($collection, true); $friendspicker = (int) get_input('friendspicker',0); @@ -43,6 +46,8 @@ 'value' => $members, 'callback' => true, 'friendspicker' => $friendspicker, + 'formcontents' => elgg_view('friends/forms/collectionfields',array('collection' => get_access_collection($collection))), + 'formtarget' => $CONFIG->wwwroot . 'action/friends/editcollection', )); break; diff --git a/languages/en.php b/languages/en.php index b323b6a89..8d6e80fd5 100644 --- a/languages/en.php +++ b/languages/en.php @@ -397,6 +397,7 @@ */ 'save' => "Save", + 'cancel' => "Cancel", 'saving' => "Saving ...", 'update' => "Update", 'edit' => "Edit", diff --git a/views/default/friends/collection.php b/views/default/friends/collection.php index 8d8afd7d1..438d82e8c 100644 --- a/views/default/friends/collection.php +++ b/views/default/friends/collection.php @@ -36,16 +36,14 @@ // individual collection panels if($friends = $vars['collection']->entities){ - $members = $vars['collection']->members; - $implodedmemberslist = implode(',',$members); - $content = elgg_view('friends/collectiontabs', array('members' => $members, 'friends' => $friends, 'collection' => $vars['collection'], 'friendspicker' => $vars['friendspicker'])); + $content = elgg_view('friends/collectiontabs', array('owner' => $_SESSION['user'], 'collection' => $vars['collection'], 'friendspicker' => $vars['friendspicker'])); echo elgg_view('friends/picker',array('entities' => $friends, 'value' => $members, 'content' => $content, 'replacement' => '', 'friendspicker' => $vars['friendspicker'])); ?> diff --git a/views/default/friends/collectiontabs.php b/views/default/friends/collectiontabs.php index 1e40dd584..cdeb6b798 100644 --- a/views/default/friends/collectiontabs.php +++ b/views/default/friends/collectiontabs.php @@ -2,19 +2,8 @@ $friendspicker = $vars['friendspicker']; - if (isset($vars['members'])) { - $members = implode(',',$vars['members']); - } else { - $members = ""; - } - - $friends = ""; - if (isset($vars['friends'])) { - foreach($vars['friends'] as $friend) { - if (!empty($friends)) $friends .= ","; - $friends .= $friend->getGUID(); - } - } + $collectionid = $vars['collection']->id; + $ownerid = $vars['owner']->getGUID(); ?> @@ -32,7 +21,7 @@ $(document).ready(function () { $('a.collectionmembers').click(function () { // load collection members pane - $('#friends_picker_placeholder').load('friends/pickercallback.php?username=username; ?>&type=list&members='); + $('#friends_picker_placeholder').load('friends/pickercallback.php?username=username; ?>&type=list&collection='); // remove selected state from previous tab $(this).parent().parent().find("li.selected").removeClass("selected"); @@ -44,7 +33,7 @@ $(document).ready(function () { $('a.editmembers').click(function () { // load friends picker pane - $('#friends_picker_placeholder').load('friends/pickercallback.php?username=username; ?>&type=picker&members=&friends=&friendspicker='); + $('#friends_picker_placeholder').load('friends/pickercallback.php?username=username; ?>&type=picker&collection=&friendspicker='); // remove selected state from previous tab $(this).parent().parent().find("li.selected").removeClass("selected"); diff --git a/views/default/friends/forms/collectionfields.php b/views/default/friends/forms/collectionfields.php new file mode 100644 index 000000000..ef3c367e3 --- /dev/null +++ b/views/default/friends/forms/collectionfields.php @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/views/default/friends/forms/edit.php b/views/default/friends/forms/edit.php index 6ed58d5bf..7c8a3f455 100644 --- a/views/default/friends/forms/edit.php +++ b/views/default/friends/forms/edit.php @@ -3,11 +3,12 @@ /** * Elgg friend collections add/edit * - * @package ElggFriends + * @package Elgg + * @subpackage Core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 - * @author Dave Tosh + * @author Curverider Ltd * @copyright Curverider Ltd 2008 - * @link http://elgg.com/ + * @link http://elgg.org/ * * @uses $vars['object'] Optionally, the collection edit */ diff --git a/views/default/friends/picker.php b/views/default/friends/picker.php index 94211f49b..d813e6fe7 100644 --- a/views/default/friends/picker.php +++ b/views/default/friends/picker.php @@ -49,6 +49,14 @@ $users = array(); $activeletters = array(); + + // Are we displaying form tags and submit buttons? + // (If we've been given a target, then yes! Otherwise, no.) + if (isset($vars['formtarget'])) { + $formtarget = $vars['formtarget']; + } else { + $formtarget = false; + } // Sort users by letter if (is_array($vars['entities']) && sizeof($vars['entities'])) @@ -85,10 +93,40 @@ } if (!isset($vars['replacement'])) { - + + if ($formtarget) { ?> + + - + +
+ +
@@ -171,12 +209,27 @@ } ?> -
- - - - - +
+ + + + + + + + + -- cgit v1.2.3