// CRM-16905 - Sort by count cannot be done with sql
if (!empty($params['sort']) && strpos($params['sort'], 'count') === 0) {
usort($values, function($a, $b) {
+ if ($a['count'] === 'unknown') {
+ return -1;
+ }
+ if ($b['count'] === 'unknown') {
+ return 1;
+ }
return $a['count'] - $b['count'];
});
if (strpos($params['sort'], 'desc')) {
$this->assertEquals('pick-me-active', $groups['data'][0]['title']);
}
+ /**
+ * Test sorting, including with smart group.
+ */
+ public function testSmartGroupSort(): void {
+ $this->smartGroupCreate();
+ $this->_params['sort'] = 'count asc';
+ CRM_Contact_BAO_Group::getGroupList($this->_params);
+ }
+
/**
* Don't populate smart group cache when building Group list.
*