From 3c7e7ab23101a869915b0d3e355274cf29a68af4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 1 Apr 2009 14:43:50 -0700 Subject: [PATCH] Checkpoint. Too many changes to enumerate. --- lib/WebGUI/Account.pm | 8 ++- lib/WebGUI/Account/FriendManager.pm | 48 +++++++++++++++++- sbin/installFriendManager.pl | 6 +-- .../root_import_account_friendmanager.wgpkg | Bin 1425 -> 1168 bytes 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/WebGUI/Account.pm b/lib/WebGUI/Account.pm index 2d62b3f1c..bae617837 100644 --- a/lib/WebGUI/Account.pm +++ b/lib/WebGUI/Account.pm @@ -34,7 +34,9 @@ readonly module => my %module; public method => my %method; public uid => my %uid; public store => my %store; #This is an all purpose hash to store stuff in: $self->store->{something} = "something" - +public bare => my %bare; #This flag indicates that neither the layout nor style template should be applied + #to the output of the method. Think JSON/XML, etc. + #------------------------------------------------------------------- =head2 appendCommonVars ( var ) @@ -139,6 +141,9 @@ sub displayContent { my $noStyle = shift; my $session = $self->session; + ##Don't do any templating if we're sending back data like JSON or XML. + return $content if $self->bare; + #Wrap content into the layout my $var = {}; $var->{content} = $content; @@ -344,6 +349,7 @@ sub new { $store { $id } = {}; $method { $id } = "view"; $uid { $id } = undef; + $bare { $id } = 0; return $self; } diff --git a/lib/WebGUI/Account/FriendManager.pm b/lib/WebGUI/Account/FriendManager.pm index 4f42a0080..16e67b587 100644 --- a/lib/WebGUI/Account/FriendManager.pm +++ b/lib/WebGUI/Account/FriendManager.pm @@ -108,6 +108,52 @@ sub editSettingsFormSave { #------------------------------------------------------------------- +=head2 www_getFriendsAsJson ( ) + +For each user in a group, count how many friends they have and return that data +as JSON. + +=cut + +sub www_getFriendsAsJson { + my $self = shift; + my $session = $self->session; + return $session->privilege->insufficient + unless $session->user->isInGroup($session->setting->get('groupIdAdminFriends')); + my $form = $session->form; + my $groupId = $form->get('groupId'); + if (! $groupId) {; + $session->log->warn("No groupId: >$groupId<"); + return '{}'; + } + my $group = WebGUI::Group->new($session, $groupId); + return '{}' if $group->getId eq 'new'; + if ($group->getId eq 'new') {; + $session->log->warn("New group created"); + return '{}'; + } + my @records = (); + USER: foreach my $userId (@{ $group->getUsers} ) { + my $user = WebGUI::User->new($session, $userId); + next USER unless $user; + my $friendsCount = scalar $user->friends->getUsers(); + push @records, { + userId => $userId, + username => $user->username, + friends => $friendsCount, + }; + } + my %results; + $results{totalRecords} = scalar @records; + $results{records} = \@records; + #$results{'sort'} = undef; + $session->http->setMimeType('application/json'); + my $json = JSON::to_json(\%results); + return $json; +} + +#------------------------------------------------------------------- + =head2 www_view ( ) The main view page for editing the user's profile. @@ -127,7 +173,7 @@ sub www_view { next GROUP unless $group->getId || $group->getId eq 'new'; push @{ $var->{group_loop} }, { groupId => $groupId, - groupName => $group->getName, + groupName => $group->name, }; } diff --git a/sbin/installFriendManager.pl b/sbin/installFriendManager.pl index 7fe2c77ac..64d12fc76 100644 --- a/sbin/installFriendManager.pl +++ b/sbin/installFriendManager.pl @@ -43,9 +43,9 @@ finish($session); sub installFriendManagerSettings { my $session = shift; print "Installing FriendManager into settings..."; - $session->setting->add('groupIdAdminFriends', '3'); - $session->setting->add('friendManagerViewTemplate', '64tqS80D53Z0JoAs2cX2VQ'); - $session->setting->add('groupsToManageFriends', '2'); + $session->setting->add('groupIdAdminFriends', '3'); + $session->setting->add('friendManagerViewTemplateId', '64tqS80D53Z0JoAs2cX2VQ'); + $session->setting->add('groupsToManageFriends', '2'); print "\tDone"; } diff --git a/sbin/packages/root_import_account_friendmanager.wgpkg b/sbin/packages/root_import_account_friendmanager.wgpkg index 3ae43b1abf21e2da27a819b7bedd4560b8efd901..207e3e061cf76b193713b83e1df0a49fa1d76a34 100644 GIT binary patch literal 1168 zcmV;B1aJEviwFP!00000|Ls;=bK*7>=6QdG#(CMDSuo}rNH#NcNgCP>lQd-03vEW& z!e}v)BgqiDlmFf$8EkXev^#;BKHvvgqjPjF-?^!f+y7TA7VGtDE~o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