Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/1ac78bb3447a4d8a820ca281b4016cb3 to your computer and use it in GitHub Desktop.
Save dubrod/1ac78bb3447a4d8a820ca281b4016cb3 to your computer and use it in GitHub Desktop.
Get MODX Active Users and Create a Table based on Extended Fields
//SNIPPET
$year = date("Y");
$jerseyYS = 0;
$jerseyYM = 0;
$jerseyYL = 0;
$jerseyYXL = 0;
$jerseyAS = 0;
$jerseyAM = 0;
$jerseyAL = 0;
$jerseyAXL = 0;
$jerseyYSarr = [];
$jerseyYMarr = [];
$jerseyYLarr = [];
$jerseyYXLarr = [];
$jerseyASarr = [];
$jerseyAMarr = [];
$jerseyALarr = [];
$jerseyAXLarr = [];
$users = $modx->getIterator('modUser', array('active'=>'1'));
foreach ($users as $user) {
$profile = $user->getOne('Profile');
$extended = $profile->get('extended');
if($extended['activeYear'] == $year){
//debug - echo '<p>Username: ' . $user->get('username') . ' Jersey:' . $extended['jersey'] . '</p>';
switch($extended['jersey']){
case "YS":
$jerseyYSarr = array('jerseysYS' => ++$jerseyYS);
break;
case "YM":
$jerseyYMarr = array('jerseysYM' => ++$jerseyYM);
break;
case "YL":
$jerseyYLarr = array('jerseysYL' => ++$jerseyYL);
break;
case "YXL":
$jerseyYXLarr = array('jerseysYXL' => ++$jerseyYXL);
break;
case "AS":
$jerseyASarr = array('jerseysAS' => ++$jerseyAS);
break;
case "AM":
$jerseyAMarr = array('jerseysAM' => ++$jerseyAM);
break;
case "AL":
$jerseyALarr = array('jerseysAL' => ++$jerseyAL);
break;
case "AXL":
$jerseyAXLarr = array('jerseysAXL' => ++$jerseyAXL);
break;
}
}
}
$orderinfo = array_merge($jerseyYSarr,$jerseyYMarr,$jerseyYLarr,$jerseyYXLarr,$jerseyASarr,$jerseyAMarr,$jerseyALarr,$jerseyAXLarr);
//print_r($orderinfo);
return($modx->parseChunk('order-info-report', $orderinfo));
//CHUNK
<h2>Jerseys</h2>
<table class="border highlight" cellspacing="0" cellpadding="0">
<thead>
<tr><th>YS</th><th>YM</th><th>YL</th><th>YXL</th><th>AS</th><th>AM</th><th>AL</th><th>AXL</th></tr>
</thead>
<tbody>
<tr>
<td data-label="YS">[[+jerseysYS]]</td>
<td data-label="YM">[[+jerseysYM]]</td>
<td data-label="YL">[[+jerseysYL]]</td>
<td data-label="YXL">[[+jerseysYXL]]</td>
<td data-label="AS">[[+jerseysAS]]</td>
<td data-label="AM">[[+jerseysAM]]</td>
<td data-label="AL">[[+jerseysAL]]</td>
<td data-label="AXL">[[+jerseysAXL]]</td>
</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment