Merge pull request #6553 from sudhabisht/C12658
[civicrm-core.git] / api / v3 / Case.php
index fa1fee74bef973f2f8ed556dcbd6fbf5d2fdfc95..cd27ced8a517b8268fc9ccc68255e880f272687b 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.                                    |
   |                                                                    |
  */
 
 /**
- * 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 $params
+ *
+ * @code
  * //REQUIRED:
  * 'case_type_id' => int OR
  * 'case_type' => str (provide one or the other)
@@ -53,6 +53,7 @@
  * 'start_date' => str datestamp // defaults to: date('YmdHis')
  * 'duration' => int // in minutes
  * 'details' => str // html format
+ * @endcode
  *
  * @throws API_Exception
  * @return array
@@ -124,7 +125,7 @@ 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);
 }
 
 /**
@@ -134,20 +135,26 @@ function civicrm_api3_case_create($params) {
  *   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.
  *
  * @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';
@@ -157,6 +164,7 @@ function _civicrm_api3_case_create_spec(&$params) {
   $params['medium_id'] = array(
     'name' => 'medium_id',
     'title' => 'Activity Medium',
+    'type' => CRM_Utils_Type::T_INT,
   );
 }
 
@@ -164,7 +172,7 @@ function _civicrm_api3_case_create_spec(&$params) {
  * 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;
@@ -174,7 +182,7 @@ function _civicrm_api3_case_update_spec(&$params) {
  * 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;
@@ -213,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
@@ -223,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
@@ -247,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
@@ -264,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
  *
@@ -283,6 +293,8 @@ function civicrm_api3_case_activity_create($params) {
 }
 
 /**
+ * Declare deprecated api functions.
+ *
  * @deprecated api notice
  * @return array
  *   Array of deprecated actions
@@ -355,18 +367,21 @@ 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 $params
+ *
+ * @code
  *   //REQUIRED:
  *   'id' => int
  *
  *   //OPTIONAL
  *   'move_to_trash' => bool (defaults to false)
+ * @endcode
  *
  * @throws API_Exception
  * @return bool
@@ -377,19 +392,13 @@ function civicrm_api3_case_delete($params) {
   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.
  *
@@ -430,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
  */
@@ -444,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'])) {