$orderBy = ' ORDER BY groups.title asc';
if (!empty($params['sort'])) {
$orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
+
+ // CRM-16905 - Sort by count cannot be done with sql
+ if (strpos($params['sort'], 'count') === 0) {
+ $orderBy = $limit = '';
+ }
}
$select = $from = $where = "";
}
}
+ // CRM-16905 - Sort by count cannot be done with sql
+ if (!empty($params['sort']) && strpos($params['sort'], 'count') === 0) {
+ usort($values, function($a, $b) {
+ return $a['count'] - $b['count'];
+ });
+ if (strpos($params['sort'], 'desc')) {
+ $values = array_reverse($values, TRUE);
+ }
+ return array_slice($values, $params['offset'], $params['rowCount']);
+ }
+
return $values;
}