+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
}
/**
- * Takes a bunch of params that are needed to match certain criteria and
- * retrieves the relevant objects. Typically the valid params are only
- * group_id. We'll tweak this function to be more full featured over a period
- * of time. This is the inverse function of create. It also stores all the retrieved
- * values in the default array
+ * Retrieve DB object based on input parameters.
+ *
+ * It also stores all the retrieved values in the default array.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @param int $id
* Group id.
- *
- * @return NULL
*/
public static function discard($id) {
CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray);
}
/**
- * Get the count of a members in a group with the specific status
+ * Get the count of a members in a group with the specific status.
*
* @param int $id
* Group id.
}
/**
- * Get the list of member for a group id
+ * Get the list of member for a group id.
*
* @param int $groupID
* @param bool $useCache
* @todo other BAO functions that use returnProperties (e.g. Query Objects) receive the array flipped & filled with 1s and
* add in essential fields (e.g. id). This should follow a regular pattern like the others
*/
- static function getGroups(
+ public static function getGroups(
$params = NULL,
$returnProperties = NULL,
$sort = NULL,
}
/**
- * Make sure that the user has permission to access this group
+ * Make sure that the user has permission to access this group.
*
* @param int $id
* The id of the object.
}
/**
- * Create a new group
+ * Create a new group.
*
* @param array $params
*
$this->where_tables = serialize($whereTables);
}
}
-
- return;
}
/**
- * Defines a new smart group
+ * Defines a new smart group.
*
* @param array $params
* Associative array of parameters.
}
/**
- * Update the is_active flag in the db
+ * Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
}
/**
- * Get permission relevant clauses
+ * Get permission relevant clauses.
* CRM-12209
*
* @param bool $force
}
/**
- * wrapper for ajax group selector
+ * wrapper for ajax group selector.
*
* @param array $params
* Associated array for params record id.
}
/**
- * This function to get list of groups
+ * This function to get list of groups.
*
* @param array $params
* Associated array for params.
$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 = "";
'count' => '0',
);
CRM_Core_DAO::storeValues($object, $values[$object->id]);
+ // Wrap with crm-editable. Not an ideal solution.
+ $values[$object->id]['title'] = '<span class="crm-editable crmf-title">' . $values[$object->id]['title'] . '</span>';
+
if ($object->saved_search_id) {
$values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
// check if custom search, if so fix view link
}
}
+ // 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;
}
*
* @return array
*/
- static function getGroupsHierarchy(
+ public static function getGroupsHierarchy(
$groupIDs,
$parents = NULL,
$spacer = '<span class="child-indent"></span>',
}
/**
- * Generate permissioned where clause for group search
+ * Generate permissioned where clause for group search.
* @param array $params
* @param bool $sortBy
* @param bool $excludeHidden
$clauses[] = self::getPermissionClause();
-
return implode(' AND ', $clauses);
}
/**
- * Define action links
+ * Define action links.
*
* @return array
* array of action links
return CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE);
}
+
}