Skip to content

Instantly share code, notes, and snippets.

@dubrod
Last active July 6, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/0ec771608858265bee332f3677b0661c to your computer and use it in GitHub Desktop.
Save dubrod/0ec771608858265bee332f3677b0661c to your computer and use it in GitHub Desktop.
Display a Table Count of Users by DOB
//SNIPPET
$datearr = [];
$users = $modx->getIterator('modUser', array('active'=>'1'));
foreach ($users as $user) {
$profile = $user->getOne('Profile');
$dob = date("Y", $profile->get('dob'));
if(array_key_exists($dob,$datearr)){
$datearr[$dob]++;
} else {
$datearr[$dob] = 1;
}
}
ksort($datearr);
foreach($datearr as $key => $value){
$output .= $modx->parseChunk('dob-row-loop',array('year' => $key,'count' => $value));
}
$table = $modx->parseChunk('dob-row-table', array('rows' => $output));
return $table;
//chunk dob-row-loop
<tr><td>[[+year]]</td><td>[[+count]]</td></tr>
//chunk dob-row-table
<table class="border" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>D.O.B.</th>
<th>Count</th>
</tr>
</thead>
<tbody>
[[+rows]]
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment