X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroup.php;h=d63caf2650e435a4039446257731094dc970dd0c;hb=2717c8a52601804ca65b8a58ca439feb7b85b62e;hp=b0cea18aa89201e1df4a0b3d5a27b268d5818a04;hpb=87878ac8e6101fc5bed04f356c677b5f9ec54bc7;p=civicrm-core.git
diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php
index b0cea18aa8..d63caf2650 100644
--- a/CRM/Contact/BAO/Group.php
+++ b/CRM/Contact/BAO/Group.php
@@ -3,7 +3,7 @@
+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
@@ -23,12 +23,12 @@
| 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$
*
*/
@@ -42,11 +42,9 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * 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.
@@ -72,8 +70,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
*
* @param int $id
* Group id.
- *
- * @return NULL
*/
public static function discard($id) {
CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray);
@@ -150,7 +146,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * 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.
@@ -198,7 +194,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * Get the list of member for a group id
+ * Get the list of member for a group id.
*
* @param int $groupID
* @param bool $useCache
@@ -238,7 +234,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
* @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,
@@ -302,7 +298,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * 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.
@@ -341,7 +337,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * Create a new group
+ * Create a new group.
*
* @param array $params
*
@@ -517,12 +513,10 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
$this->where_tables = serialize($whereTables);
}
}
-
- return;
}
/**
- * Defines a new smart group
+ * Defines a new smart group.
*
* @param array $params
* Associative array of parameters.
@@ -550,7 +544,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * Update the is_active flag in the db
+ * Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
@@ -604,7 +598,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * Get permission relevant clauses
+ * Get permission relevant clauses.
* CRM-12209
*
* @param bool $force
@@ -708,7 +702,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * wrapper for ajax group selector
+ * wrapper for ajax group selector.
*
* @param array $params
* Associated array for params record id.
@@ -778,7 +772,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
- * This function to get list of groups
+ * This function to get list of groups.
*
* @param array $params
* Associated array for params.
@@ -801,6 +795,11 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
$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 = "";
@@ -867,6 +866,9 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
'count' => '0',
);
CRM_Core_DAO::storeValues($object, $values[$object->id]);
+ // Wrap with crm-editable. Not an ideal solution.
+ $values[$object->id]['title'] = '' . $values[$object->id]['title'] . '';
+
if ($object->saved_search_id) {
$values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
// check if custom search, if so fix view link
@@ -979,6 +981,17 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
}
+ // 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;
}
@@ -994,7 +1007,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
*
* @return array
*/
- static function getGroupsHierarchy(
+ public static function getGroupsHierarchy(
$groupIDs,
$parents = NULL,
$spacer = '',
@@ -1137,7 +1150,7 @@ WHERE {$whereClause}";
}
/**
- * Generate permissioned where clause for group search
+ * Generate permissioned where clause for group search.
* @param array $params
* @param bool $sortBy
* @param bool $excludeHidden
@@ -1224,12 +1237,11 @@ WHERE {$whereClause}";
$clauses[] = self::getPermissionClause();
-
return implode(' AND ', $clauses);
}
/**
- * Define action links
+ * Define action links.
*
* @return array
* array of action links
@@ -1286,4 +1298,5 @@ WHERE {$whereClause}";
return CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE);
}
+
}