Merge pull request #7150 from colemanw/CRM-13823
[civicrm-core.git] / api / v3 / Group.php
index 59ab73fcf4f097135fcfe28a8fa65bba5c1200f5..a752c672b1fed246493e1fbd4b873b3701541fec 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  */
 
 /**
- * This api exposes CiviCRM groups.
+ * This api exposes CiviCRM Groups.
  *
  * This api is for creating/deleting groups or fetching a list of existing groups.
- * To add/remove contacts to a group, use the groupContact api instead.
+ * To add/remove contacts to a group, use the GroupContact api instead.
  *
  * @package CiviCRM_APIv3
  */
@@ -38,7 +38,7 @@
  * Create/update group.
  *
  * @param array $params
- *   name/value pairs to insert in new 'group'
+ *   name/value pairs to insert in new 'Group'
  *
  * @return array
  *   API result array
@@ -61,7 +61,7 @@ function _civicrm_api3_group_create_spec(&$params) {
 }
 
 /**
- * Returns array of groups matching a set of one or more group properties.
+ * Returns array of groups matching a set of one or more Group properties.
  *
  * @param array $params
  *   Array of properties. If empty, all records will be returned.
@@ -70,20 +70,25 @@ function _civicrm_api3_group_create_spec(&$params) {
  *   Array of matching groups
  */
 function civicrm_api3_group_get($params) {
-  $options = _civicrm_api3_get_options_from_params($params, TRUE, 'group', 'get');
-  if (empty($options['return']) || !in_array('member_count', $options['return'])) {
+  $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get');
+  if ((empty($options['return']) || !in_array('member_count', $options['return'])) && empty($params['check_permissions'])) {
     return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group');
   }
 
   $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group');
   foreach ($groups as $id => $group) {
-    $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
+    if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Group::checkPermission($group['id'])) {
+      unset($groups[$id]);
+    }
+    elseif (!empty($options['return']) && in_array('member_count', $options['return'])) {
+      $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
+    }
   }
-  return civicrm_api3_create_success($groups, $params, 'group', 'get');
+  return civicrm_api3_create_success($groups, $params, 'Group', 'get');
 }
 
 /**
- * Delete an existing group.
+ * Delete an existing Group.
  *
  * @param array $params
  *   [id]