Merge pull request #5901 from colemanw/CRM-16557
[civicrm-core.git] / api / v3 / Case.php
index 4be69dba1c02a2c996d53589aa5a4d38313f1ae5..afa5f48a92f4a32a07aa98bda47b16d664bc814e 100644 (file)
@@ -1,10 +1,9 @@
 <?php
-
 /*
   +--------------------------------------------------------------------+
   | 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        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
- * File for the CiviCRM APIv3 Case functions
+ * This api exposes CiviCRM Case objects.
  * Developed by woolman.org
  *
  * @package CiviCRM_APIv3
- * @subpackage API_Case
- * @copyright CiviCRM LLC (c) 2004-2014
- *
  */
 
 
 /**
- * Open a new case, add client and manager roles, and add standard timeline
+ * Open a new case, add client and manager roles, and standard timeline.
  *
- * @param array (
+ * @param array $params
+ *
+ * @code
  * //REQUIRED:
  * 'case_type_id' => int OR
  * 'case_type' => str (provide one or the other)
  * 'start_date' => str datestamp // defaults to: date('YmdHis')
  * 'duration' => int // in minutes
  * 'details' => str // html format
+ * @endcode
  *
  * @throws API_Exception
  * @return array
  *   api result array
- *
- * @access public
- * {@getfields case_create}
  */
 function civicrm_api3_case_create($params) {
 
@@ -69,7 +65,11 @@ function civicrm_api3_case_create($params) {
     return civicrm_api3_case_update($params);
   }
 
-  civicrm_api3_verify_mandatory($params, NULL, array('contact_id', 'subject', array('case_type', 'case_type_id')));
+  civicrm_api3_verify_mandatory($params, NULL, array(
+    'contact_id',
+    'subject',
+    array('case_type', 'case_type_id'))
+  );
   _civicrm_api3_case_format_params($params);
 
   // If format_params didn't find what it was looking for, return error
@@ -125,30 +125,36 @@ function civicrm_api3_case_create($params) {
   $values = array();
   _civicrm_api3_object_to_array($caseBAO, $values[$caseBAO->id]);
 
-  return civicrm_api3_create_success($values, $params, 'case', 'create', $caseBAO);
+  return civicrm_api3_create_success($values, $params, 'Case', 'create', $caseBAO);
 }
 
 /**
- * Adjust Metadata for Get Action
+ * Adjust Metadata for Get Action.
  *
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Parameters determined by getfields.
  */
 function _civicrm_api3_case_get_spec(&$params) {
-  $params['contact_id']['api.aliases'] = array('client_id');
-  $params['contact_id']['title'] = 'Case Client';
+  $params['contact_id'] = array(
+    'api.aliases' => array('client_id'),
+    'title' => 'Case Client',
+    'type' => CRM_Utils_Type::T_INT,
+  );
 }
 
 /**
- * Adjust Metadata for Create Action
+ * Adjust Metadata for Create Action.
  *
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_case_create_spec(&$params) {
-  $params['contact_id']['api.aliases'] = array('client_id');
-  $params['contact_id']['title'] = 'Case Client';
-  $params['contact_id']['api.required'] = 1;
+  $params['contact_id'] = array(
+    'api.aliases' => array('client_id'),
+    'title' => 'Case Client',
+    'api.required' => 1,
+    'type' => CRM_Utils_Type::T_INT,
+  );
   $params['status_id']['api.default'] = 1;
   $params['status_id']['api.aliases'] = array('case_status');
   $params['creator_id']['api.default'] = 'user_contact_id';
@@ -158,49 +164,46 @@ function _civicrm_api3_case_create_spec(&$params) {
   $params['medium_id'] = array(
     'name' => 'medium_id',
     'title' => 'Activity Medium',
+    'type' => CRM_Utils_Type::T_INT,
   );
 }
 
 /**
- * Adjust Metadata for Update action
+ * Adjust Metadata for Update action.
  *
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_case_update_spec(&$params) {
   $params['id']['api.required'] = 1;
 }
 
 /**
- * Adjust Metadata for Delete action
+ * Adjust Metadata for Delete action.
  *
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_case_delete_spec(&$params) {
   $params['id']['api.required'] = 1;
 }
 
 /**
- * Get details of a particular case, or search for cases, depending on params
+ * Get details of a particular case, or search for cases, depending on params.
  *
  * Please provide one (and only one) of the four get/search parameters:
  *
- * @param array (
- * 'id' => if set, will get all available info about a case, including contacts and activities
- *
- * // if no case_id provided, this function will use one of the following search parameters:
- * 'client_id' => finds all cases with a specific client
- * 'activity_id' => returns the case containing a specific activity
- * 'contact_id' => finds all cases associated with a contact (in any role, not just client)
+ * @param array $params
+ *   'id' => if set, will get all available info about a case, including contacts and activities
  *
- * {@getfields case_get}
+ *   // if no case_id provided, this function will use one of the following search parameters:
+ *   'client_id' => finds all cases with a specific client
+ *   'activity_id' => returns the case containing a specific activity
+ *   'contact_id' => finds all cases associated with a contact (in any role, not just client)
  *
  * @throws API_Exception
  * @return array
  *   (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found
- * @access public
- * @todo Erik Hommel 16 dec 2010 check if all DB fields are returned
  */
 function civicrm_api3_case_get($params) {
   $options = _civicrm_api3_get_options_from_params($params);
@@ -218,7 +221,7 @@ function civicrm_api3_case_get($params) {
         $cases[$id] = $case;
       }
     }
-    return civicrm_api3_create_success($cases, $params, 'case', 'get');
+    return civicrm_api3_create_success($cases, $params, 'Case', 'get');
   }
 
   //search by activity
@@ -228,10 +231,10 @@ function civicrm_api3_case_get($params) {
     }
     $caseId = CRM_Case_BAO_Case::getCaseIdByActivityId($params['activity_id']);
     if (!$caseId) {
-      return civicrm_api3_create_success(array(), $params, 'case', 'get');
+      return civicrm_api3_create_success(array(), $params, 'Case', 'get');
     }
     $case = array($caseId => _civicrm_api3_case_read($caseId, $options));
-    return civicrm_api3_create_success($case, $params, 'case', 'get');
+    return civicrm_api3_create_success($case, $params, 'Case', 'get');
   }
 
   //search by contacts
@@ -252,7 +255,7 @@ SELECT DISTINCT case_id
     while ($dao->fetch()) {
       $cases[$dao->case_id] = _civicrm_api3_case_read($dao->case_id, $options);
     }
-    return civicrm_api3_create_success($cases, $params, 'case', 'get');
+    return civicrm_api3_create_success($cases, $params, 'Case', 'get');
   }
 
   // For historic reasons we always return these when an id is provided
@@ -269,11 +272,13 @@ SELECT DISTINCT case_id
     }
   }
 
-  return civicrm_api3_create_success($cases, $params, 'case', 'get');
+  return civicrm_api3_create_success($cases, $params, 'Case', 'get');
 }
 
 /**
- * Deprecated. Use activity API instead
+ * Deprecated API.
+ *
+ * Use activity API instead.
  *
  * @param array $params
  *
@@ -288,6 +293,8 @@ function civicrm_api3_case_activity_create($params) {
 }
 
 /**
+ * Declare deprecated api functions.
+ *
  * @deprecated api notice
  * @return array
  *   Array of deprecated actions
@@ -299,20 +306,18 @@ function _civicrm_api3_case_deprecation() {
 /**
  * Update a specified case.
  *
- * @param array (
- * //REQUIRED:
- * 'case_id' => int
+ * @param array $params
+ *   //REQUIRED:
+ *   'case_id' => int
  *
- * //OPTIONAL
- * 'status_id' => int
- * 'start_date' => str datestamp
- * 'contact_id' => int // case client
+ *   //OPTIONAL
+ *   'status_id' => int
+ *   'start_date' => str datestamp
+ *   'contact_id' => int // case client
  *
  * @throws API_Exception
  * @return array
  *   api result array
- *
- * @access public
  */
 function civicrm_api3_case_update($params) {
   //check parameters
@@ -362,43 +367,38 @@ function civicrm_api3_case_update($params) {
   _civicrm_api3_object_to_array($dao, $case);
   $values[$dao->id] = $case;
 
-  return civicrm_api3_create_success($values, $params, 'case', 'update', $dao);
+  return civicrm_api3_create_success($values, $params, 'Case', 'update', $dao);
 }
 
 /**
  * Delete a specified case.
  *
- * @param array (
- * //REQUIRED:
- * 'id' => int
+ * @param array $params
  *
- * //OPTIONAL
- * 'move_to_trash' => bool (defaults to false)
+ * @code
+ *   //REQUIRED:
+ *   'id' => int
+ *
+ *   //OPTIONAL
+ *   'move_to_trash' => bool (defaults to false)
+ * @endcode
  *
  * @throws API_Exception
- * @return boolean
+ * @return bool
  *   true if success, else false
- * {@getfields case_delete}
- * @access public
  */
 function civicrm_api3_case_delete($params) {
   //check parameters
   civicrm_api3_verify_mandatory($params, NULL, array('id'));
 
   if (CRM_Case_BAO_Case::deleteCase($params['id'], CRM_Utils_Array::value('move_to_trash', $params, FALSE))) {
-    return civicrm_api3_create_success($params, $params, 'case', 'delete');
+    return civicrm_api3_create_success($params, $params, 'Case', 'delete');
   }
   else {
     throw new API_Exception('Could not delete case.');
   }
 }
 
-/***********************************/
-/*                                 */
-/*     INTERNAL FUNCTIONS          */
-/*                                 */
-/***********************************/
-
 /**
  * Internal function to retrieve a case.
  *
@@ -439,7 +439,7 @@ function _civicrm_api3_case_read($caseId, $options) {
 }
 
 /**
- * Internal function to format create params for processing
+ * Internal function to format create params for processing.
  *
  * @param array $params
  */
@@ -453,7 +453,7 @@ function _civicrm_api3_case_format_params(&$params) {
     if (!$params['case_type_id']) {
       $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE);
       $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels);
-      $params['case_type'] = $caseTypes[$params['case_type_id']]; // label => name
+      $params['case_type'] = $caseTypes[$params['case_type_id']];
     }
   }
   elseif (empty($params['case_type'])) {