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 3ae43b1ab..207e3e061 100644 Binary files a/sbin/packages/root_import_account_friendmanager.wgpkg and b/sbin/packages/root_import_account_friendmanager.wgpkg differ