Skip to content

Instantly share code, notes, and snippets.

@cmcintosh
Created February 24, 2015 08:41
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 cmcintosh/37c4eab81606941eccd3 to your computer and use it in GitHub Desktop.
Save cmcintosh/37c4eab81606941eccd3 to your computer and use it in GitHub Desktop.
/**
* Overrides parent::render_grouping().
*/
function render_grouping($records, $groupings = array(), $group_rendered = NULL) {
$sets = parent::render_grouping($records, $groupings, $group_rendered);
// Apply the offset and limit.
array_walk($sets, array($this, 'group_limit_recursive'));
return $sets;
}
/**
* Recursively limits the number of rows in nested groups.
*
* @param array $group_data
* A single level of grouped records.
*
* @param mixed $key
* The key of the array being passed in. Used for when this function is
* called from array_walk() and the like. Do not set directly.
*
* @params int $level
* The current level we are gathering results for. Used for recursive
* operations; do not set directly.
*
* @return array
* An array with a "rows" property that is recursively grouped by the
* grouping fields.
*/
function group_limit_recursive(&$group_data, $key = NULL, $level = 0) {
$settings = $this->grouping_limit_settings($level);
// Slice up the rows according to the offset and limit.
$group_data['rows'] = array_slice($group_data['rows'], $settings['grouping-offset'], $settings['grouping-limit'], TRUE);
// For each row, if it appears to be another grouping, recurse again.
foreach ($group_data['rows'] as &$data) {
if (is_array($data) && isset($data['group']) && isset($data['rows'])) {
$this->group_limit_recursive($data, NULL, $level + 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment