version fixes
[civicrm-core.git] / api / v3 / UFGroup.php
index 209fcada12c88d7ca3bfa19eca4e62967ce85146..89fb6c284ba49af4ead81e3bbe3bd941f4b315fb 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.                                    |
  |                                                                    |
@@ -85,3 +85,76 @@ function civicrm_api3_uf_group_get($params) {
 function civicrm_api3_uf_group_delete($params) {
   return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
+
+/**
+ * Set default getlist parameters.
+ *
+ * @see _civicrm_api3_generic_getlist_defaults
+ *
+ * @param array $request
+ *
+ * @return array
+ */
+function _civicrm_api3_uf_group_getlist_defaults(&$request) {
+  return array(
+    'description_field' => array(
+      'description',
+      'group_type',
+    ),
+    'params' => array(
+      'is_active' => 1,
+    ),
+  );
+}
+
+/**
+ * Format getlist output
+ *
+ * @see _civicrm_api3_generic_getlist_output
+ *
+ * @param array $result
+ * @param array $request
+ * @param string $entity
+ * @param array $fields
+ *
+ * @return array
+ */
+function _civicrm_api3_uf_group_getlist_output($result, $request, $entity, $fields) {
+  $output = array();
+  if (!empty($result['values'])) {
+    foreach ($result['values'] as $row) {
+      $data = array(
+        'id' => $row[$request['id_field']],
+        'label' => $row[$request['label_field']],
+      );
+      if (!empty($request['description_field'])) {
+        $data['description'] = array();
+        foreach ((array) $request['description_field'] as $field) {
+          if (!empty($row[$field])) {
+            // Special formatting for group_type field
+            if ($field == 'group_type') {
+              $groupTypes = CRM_UF_Page_Group::extractGroupTypes($row[$field]);
+              $data['description'][] = CRM_UF_Page_Group::formatGroupTypes($groupTypes);
+              continue;
+            }
+            if (!isset($fields[$field]['pseudoconstant'])) {
+              $data['description'][] = $row[$field];
+            }
+            else {
+              $data['description'][] = CRM_Core_PseudoConstant::getLabel(
+                _civicrm_api3_get_BAO($entity),
+                $field,
+                $row[$field]
+              );
+            }
+          }
+        }
+      };
+      if (!empty($request['image_field'])) {
+        $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
+      }
+      $output[] = $data;
+    }
+  }
+  return $output;
+}