/** * Update a specified case. * * @param array( //REQUIRED: * 'case_id' => int * * //OPTIONAL * 'status_id' => int * 'start_date' => str datestamp * 'contact_id' => int // case client * * @return Updated case * * @access public * */ function civicrm_api3_case_update($params) { //check parameters civicrm_api3_verify_mandatory($params, NULL, array('id')); // return error if modifing creator id if (array_key_exists('creator_id', $params)) { return civicrm_api3_create_error(ts('You cannot update creator id')); } $mCaseId = array(); $origContactIds = array(); // get original contact id and creator id of case if (!empty($params['contact_id'])) { $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['id']); $origContactId = $origContactIds[1]; } if (count($origContactIds) > 1) { // check valid orig contact id if (!empty($params['orig_contact_id']) && !in_array($params['orig_contact_id'], $origContactIds)) { return civicrm_api3_create_error('Invalid case contact id (orig_contact_id)'); } elseif (empty($params['orig_contact_id'])) { return civicrm_api3_create_error('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced'); } $origContactId = $params['orig_contact_id']; } // check for same contact id for edit Client if (!empty($params['contact_id']) && !in_array($params['contact_id'], $origContactIds)) { $mCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'], $origContactId, NULL, TRUE); } if (!empty($mCaseId[0])) { $params['id'] = $mCaseId[0]; } $dao = new CRM_Case_BAO_Case(); $dao->id = $params['id']; $dao->copyValues($params); $dao->save(); $case = array(); _civicrm_api3_object_to_array($dao, $case); return civicrm_api3_create_success($case, $params, 'case', 'update', $dao); }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params input parameters to find object * @param array $values output values of the object * @param array $ids the array that holds all the db ids * * @return CRM_Case_BAO_Case|null the found object or null * @access public * @static */ static function &getValues(&$params, &$values, &$ids) { $case = new CRM_Case_BAO_Case(); $case->copyValues($params); if ($case->find(TRUE)) { $ids['case'] = $case->id; CRM_Core_DAO::storeValues($case, $values); return $case; } return NULL; }
/** * Update a specified case. * * @param array( //REQUIRED: * 'case_id' => int * * //OPTIONAL * 'status_id' => int * 'start_date' => str datestamp * 'contact_id' => int // case client * 'creator_id' => int // case manager * * @return Updated case * * @access public * */ function civicrm_case_update(&$params) { _civicrm_initialize(); $errors = array(); //check for various error and required conditions $errors = _civicrm_case_check_params($params, 'update'); if (!empty($errors)) { return $errors; } // return error if modifing creator id if (array_key_exists('creator_id', $params)) { return civicrm_create_error(ts('You have no provision to update creator id')); } $mCaseId = array(); $origContactIds = array(); // get original contact id and creator id of case if ($params['contact_id']) { $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['case_id']); $origContactId = $origContactIds[1]; } if (count($origContactIds) > 1) { // check valid orig contact id if ($params['orig_contact_id'] && !in_array($params['orig_contact_id'], $origContactIds)) { return civicrm_create_error(ts('Invalid case contact id (orig_contact_id)')); } else { if (!$params['orig_contact_id']) { return civicrm_create_error(ts('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced')); } } $origContactId = $params['orig_contact_id']; } // check for same contact id for edit Client if ($params['contact_id'] && !in_array($params['contact_id'], $origContactIds)) { $mCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'], $origContactId, null, true); } if (CRM_Utils_Array::value('0', $mCaseId)) { $params['case_id'] = $mCaseId[0]; } $dao = new CRM_Case_BAO_Case(); $dao->id = $params['case_id']; $dao->copyValues($params); $dao->save(); $case = array(); _civicrm_object_to_array($dao, $case); return civicrm_create_success($case); }