Blogs

Posted At : 13 May 2008 17:31 | Posted By : Alex Lloyd
Related Categories: Ning Development

Recently i've done some work for a client, with a Ning site, who requested an export of the invite tab, just like with members. They had over 30,000 invites, so this was an excellent test of the function.

It seems like this is a much sought after thing, and as ever, this is a massive hack, as I'm not a PHP or Ning developer!

I started this solution by looking at getUnusedInvitations() invitation in /widgets/index/lib/helpers/Index_InvitationHelper.php which is used to populate the 'invite' list.

Then, i copied the action_exportMemberData() in /widgets/index/controllers/BulkController.php, and modified it to action_exportInviteData(). Amongst the changes, the most significant was repointing the data-gather line

$members = User::find($filters, $start, $end, 'createdDate', 'desc', TRUE);


to use the function above:

$invitations = Index_InvitationHelper::getUnusedInvitations($filters, $start, $end, $totalNumInvites, $profiles);


So this is now pulling the list of unused invitations, then in this case, outputting displayName, emailAddress, date and inviter from the $invitations array to the csv file, using fwrite().

This doesn't return the name of the inviter, but the screenName (NingID), so i did some work to ensure that the name was also written to the csv file:

if ($invitations[$count][inviter] != ''){ $invitedBy = explode('>', xg_userlink($invitations[$count][inviter])); $invitedBy = explode('<', $invitedBy[1]); $invitedBy = $invitedBy[0]; }else{ $invitedBy = ''; };


Then copied the memberDataExportFile() function from within /widgets/index/lib/helpers/Index_MembershipHelper.php and changed it to invitationDataExportFile() within /widgets/index/lib/helpers/Index_InvitationHelper.php.

So, now, you are naming the file, and populating it with the first 50 rows of unused invitation data, next, creating and completing the file!

Towards the bottom of /widgets/index/templates/membership/listMembers.php there is a link 'builder', which puts together a link to compile and download the .csv file copy this into /widgets/index/templates/membership/listInvited.php, change the text, and make sure it points at your new exportInvitationData function in BulkController.php.

Finally, make sure you add the line:



This goes at the top of listInvited.php, this will allow the download link to be built.

So, now, when you click on the link, it should, should, create the .csv file and loop through the file writing function, 50 rows at a time, until all data is gathered, then it should offer, for download, the .csv file.

Note: with 30,000 rows the file weighs about 2.25MB and it takes about 5-7mins to cycle through and build the list!




As ever, if you have any questions, comment below, and i'll try and get back to you!

Lloyd

Comments

© 1998 - 2010 TalkWebSolutions Ltd. Registered in England No. 04521175.