Skip to content

Instantly share code, notes, and snippets.

@fczuardi
Created August 23, 2008 20:26
Show Gist options
  • Save fczuardi/6939 to your computer and use it in GitHub Desktop.
Save fczuardi/6939 to your computer and use it in GitHub Desktop.
Members Data Table for Ning.com social networks
<?php
/**
* Detailed Members Table
* Display a detailed list of members for a particular network containing
* all answers for the profile questions, you can sort by any field
*
* Author: Fabricio Campos Zuardi (fabricio@gmail.com)
**/
//parameters
$begin = $_GET['begin'] ? $_GET['begin'] : 0;
$end = $_GET['end'] ? $_GET['end'] : 10;
$sort = $_GET['sort'] ? $_GET['sort'] : 'fullName';
$order = $_GET['order'] ? $_GET['order'] : 'asc';
$pageSize = $end - $begin;
$app = XN_Application::load();
$appSubdomain = $app->relativeUrl;
$appUrl = 'http://' . XN_AtomHelper::HOST_APP($appSubdomain);
//get the questions
$configfilepath = 'xn_private/profiles-private-configuration.xml';
$xml = simplexml_load_file($configfilepath);
$questions = (unserialize(urldecode((string)$xml->config->profileQuestions)));
//query users
$query = XN_Query::create('Content')
->filter('owner')
->filter('type', '=', 'User')
->begin($begin)
->end($end)
->order('my->'.$sort, $order)
->alwaysReturnTotalCount(true);
$users = $query->execute();
$total = $query->getTotalCount();
//display results
?>
<table border="1">
<tr>
<th>Avatar</th>
<th><a href="?sort=fullName&order=<%= (($order == 'asc') && ($sort == 'fullName')) ? 'desc' : 'asc'; %>">Name</a></th>
<th><a href="?sort=gender&order=<%= (($order == 'asc') && ($sort == 'gender')) ? 'desc' : 'asc'; %>">Gender</a></th>
<th><a href="?sort=birthdate&order=<%= (($order == 'asc') && ($sort == 'birthdate')) ? 'desc' : 'asc'; %>">Birthdate</a></th>
<th><a href="?sort=location&order=<%= (($order == 'asc') && ($sort == 'location')) ? 'desc' : 'asc'; %>">Location</a></th>
<th><a href="?sort=country&order=<%= (($order == 'asc') && ($sort == 'country')) ? 'desc' : 'asc'; %>">Country</a></th>
<?php
foreach($questions as $question){
if (($question['private'] != 'on') || (XN_Profile::current()->isOwner())) {
?>
<th><a href="?sort=<%= 'xg_profiles_answer_q' . $question['questionCounter']
%>&order=<%= (($order == 'asc') && ($sort == 'xg_profiles_answer_q' . $question['questionCounter'])) ?
'desc' : 'asc'; %>"><%= $question['question_title'] %></a></th>
<?php
}
}
?>
</tr>
<?php
foreach($users as $user){
// echo $user->debugHtml();
echo " <tr>\n <td>" . '<a href="'. $appUrl .'/xn/detail/u_'.$user->title.
'"><img src="' . $user->my->thumbnailUrl . '?width=60&height=60" /></a>' . "&nbsp;</td>\n <td>" .
$user->my->fullName . "&nbsp;</td>\n <td>" .
$user->my->gender . "&nbsp;</td>\n <td>" .
$user->my->birthdate . "&nbsp;</td>\n <td>" .
$user->my->location . "&nbsp;</td>\n <td>" .
$user->my->country . "&nbsp;</td>";
foreach($questions as $question){
if (($question['private'] != 'on') || (XN_Profile::current()->isOwner())) {
echo "\n <td>" . $user->my->{'xg_profiles_answer_q' . $question['questionCounter']} . '&nbsp;</td>';
}
}
echo "\n </tr>\n";
}
?>
</table>
<p>Displaying <%= $begin . ' - ' . min($end,$total) %> of <%= $total %>.</p><?php
if ($begin > 0) {
?>
<a href="?sort=<%= $sort %>&order=<%= $order %>&begin=<%= $begin-$pageSize %>&end=<%= $begin %>">Previous</a>
<?php
}
if ($end < $total) {
?>
<a href="?sort=<%= $sort %>&order=<%= $order %>&begin=<%= $end %>&end=<%= $end+$pageSize %>">Next</a>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment