Вывела пользователей по группам с помощью сниппета ShowMembers
http://modxcms.com/extras/package/399
<?php
// ShowMembers v1.1c
// Written by Michel van de Wetering
// Feel free to use this snippet for anything you want, just give proper credit.
//
// Changed by Wim Beerens, March 20, 2008:
// v1.1: extracted language strings to language file
// added extra parameters
// added date formatting
// Updated by Wim Beerens, July 29, 2008:
// v1.1a: added value 'all' to parameter &webGroup
// Updated by Wim Beerens, October 17, 2008:
// v1.1b: changed inclusion of language file
// to allow multiple calls on same page
// Updated by Wim Beerens, December 12, 2008:
// v1.1c: added parameter &total for counting and displaying members in webgroup
//
// This snippet will list all members in a given webgroup. There are several options
// that allow you to customize the output. Note that you can use the [+ShowMembers.Count+]
// placeholder to display the number of users in the webgroup. Note that you probably want
// to call this snippet uncached, so within [! !] tags.
//
// Thanks go to OpenGeek that provided me with the query that is the heart of this snippet
//
// Parameters:
//
// &webGroup (mandatory)
// This is the webusergroup that should be listed
// `all` lists all webusergroups
//
// &tpl (optional)
// Name of a chunk with template that defines the output of the snippet.
// The template defaults to "[+fullname+]". An example template could
// look like this: "[+fullname+] is from [+country+]<br />"
// Note that only the following fields can be used (extra formatting can be required):
// id
// internalKey
// fullname
// role
// email
// phone
// mobilephone
// blocked
// blockeduntil
// blockedafter
// logincount
// lastlogin
// thislogin
// failedlogincount
// dob (this means "date of birth")
// gender
// country
// state
// zip
// fax
// photo
// comment
//
// &seperator (optional)
// The string that will be displayed between fullnames. Defaults to ", "
//
// &wrapdiv (optional):
// Wraps the output of the snippet in a div with the class="wrapdiv"
//
// Added paramaters in v1.1:
//
// &lang (optional) - default: english
// Set the desired language.
// You can make your own language file by changing the english.inc.php file
// in the directory assets/snippets/ShowMembers/lang and save it as yourlanguage.inc.php
// In the snippet call you then use &lang=`yourlanguage`
//
// &dateFormat (optional) - default: %m/%d/%Y
// Date formatting string. As explained on http://www.php.net/manual/nl/function.strftime.php
// This string is only applicable on the fields:
// blockeduntil
// blockedafter
// lastlogin
// thislogin
// dob (this means "date of birth")
//
// Added parameter in v1.1c:
//
// &total (optional) [ 0 | 1 ] - default: 0
// Count and display total members in webgroup
// 0 = No
// 1 = Yes
// Check parameters
// -------------------------------
// Language
$lang = isset($lang)?$lang:"english";
// Include language strings
include($modx->config['base_path']."assets/snippets/ShowMembers/lang/".$lang.".inc.php");
setlocale (LC_TIME, $sm_lang['setlocale']);
// Date formatting
$dateFormat = isset($dateFormat)?$dateFormat:"%m/%d/%Y";
// Count and display members in webgroup
$total = isset($total)?$total:"0";
// Webgroup
if (!isset($webGroup)) return $sm_lang['no_group'];
// Template/chunk
if (isset($tpl))
{
if (($tpl = $modx->getChunk($tpl)) == '')
return $sm_lang['invalid_tpl'];
}
else
{
$tpl = "[+fullname+]";
}
// Separator
$seperator = isset($seperator)?$seperator:", ";
// No usersettings below this line
// -------------------------------
// Initialize
$output = '';
$counter = '0'; // added in v1.1c to count members
// Handle wrapdiv
if (isset($wrapdiv))
{
$output .= "<div class='$wrapdiv'>";
}
// Parse the template to find out what fields to retrieve from the DB
preg_match_all("|\[\+(.*[^\+])\+\]|U",
$tpl,
$matches,
PREG_PATTERN_ORDER);
if (count($matches[1]) == 0)
{
$output .= $sm_lang['no_fields_in_tpl'];
}
// Build the list of fields to retrieve with the query
$fields = "wua.{$matches[1][0]}";
for ($i=1; $i<count($matches[1]); $i++)
{
$fields .= ",wua.{$matches[1][$i]}";
}
// Get a list of users from the DB. No API call for this :-(
// Thanks to OpenGeek for making the query
$wua= $modx->getFullTableName('web_user_attributes');
$wgn= $modx->getFullTableName('webgroup_names');
$wg= $modx->getFullTableName('web_groups');
// Updated to select all webgroups
if($webGroup == "all") {
$sql= "SELECT {$fields} FROM {$wua} wua ORDER BY wua.fullname ASC";
} else {
$sql= "SELECT {$fields} FROM {$wua} wua JOIN {$wg} wg ON wg.webuser = wua.internalKey JOIN {$wgn} wgn ON wgn.name
= '{$webGroup}' AND wgn.id = wg.webgroup ORDER BY wua.fullname ASC";
}
/*
$sql= "SELECT {$fields}
FROM {$wua} wua
JOIN {$wg} wg ON wg.webuser = wua.internalKey
JOIN {$wgn} wgn ON wgn.name = '{$webGroup}'
AND wgn.id = wg.webgroup
ORDER BY wua.fullname ASC";
*/
$webusers = $modx->db->query($sql);
$count = $modx->db->getRecordCount($webusers);
$modx->setPlaceholder('ShowMembers.Count', $count);
if ($count > 0)
{
$user = $modx->db->getRow($webusers);
// Fill out the placeholders in the template
$outtpl = $tpl;
for ($i=0; $i<count($matches[1]); $i++)
{
if (($matches[1][$i]=='blockeduntil') or ($matches[1][$i]=='blockedafter') or ($matches[1][$i]=='lastlogin') or
($matches[1][$i]=='thislogin') or ($matches[1][$i]=='dob'))
{
$user[$matches[1][$i]] = strftime($dateFormat, $user[$matches[1][$i]]);
}
$outtpl = str_replace("[+{$matches[1][$i]}+]", $user[$matches[1][$i]], $outtpl);
}
$output .= $outtpl;
if ($total == '1') {
$counter++; // count users
}
while ($user = $modx->db->getRow($webusers))
{
$output .= $seperator;
// Fill out the placeholders in the template
$outtpl = $tpl;
for ($i=0; $i<count($matches[1]); $i++)
{
if (($matches[1][$i]=='blockeduntil') or ($matches[1][$i]=='blockedafter') or ($matches[1][$i]=='lastlogin') or
($matches[1][$i]=='thislogin') or ($matches[1][$i]=='dob'))
{
$user[$matches[1][$i]] = strftime($dateFormat, $user[$matches[1][$i]]);
}
$outtpl = str_replace("[+{$matches[1][$i]}+]", $user[$matches[1][$i]], $outtpl);
}
$output .= $outtpl;
if ($total == '1') {
$counter++; // count users
}
}
}
else
{
$output .= $sm_lang['no_members_found'];
}
if (isset($wrapdiv))
{
$output .= "</div>";
}
if ($total == '1') {
$output .= "</p><p>" .$sm_lang['total'] . $counter . $sm_lang['members'];
}
return $output;
?>
Но он малость недоработанный, выводит только статику, а мне надо, чтобы имя пользователя было ссылкой на его профиль.
Спасибо, конечно, за моральную поддержку
, но кто бы кодом помог, а?