/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*/
function civicrm_api3_activity_create($params) {
- if (!CRM_Utils_Array::value('id', $params)) {
+ if (empty($params['id'])) {
// an update does not require any mandatory parameters
civicrm_api3_verify_one_mandatory($params,
NULL,
$case_id = '';
$createRevision = FALSE;
$oldActivityValues = array();
- if (CRM_Utils_Array::value('case_id', $params)) {
+ if (!empty($params['case_id'])) {
$case_id = $params['case_id'];
- if (CRM_Utils_Array::value('id', $params)) {
+ if (!empty($params['id'])) {
$oldActivityParams = array('id' => $params['id']);
if (!$oldActivityValues) {
CRM_Activity_BAO_Activity::retrieve($oldActivityParams, $oldActivityValues);
//default for source_contact_id = currently logged in user
$params['source_contact_id']['api.default'] = 'user_contact_id';
+ $params['status_id']['api.aliases'] = array('activity_status');
+
$params['assignee_contact_id'] = array(
'name' => 'assignee_id',
'title' => 'assigned to',
'type' => 1,
- 'FKClassName' => 'CRM_Activity_DAO_ActivityAssignment',
+ 'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
);
$params['target_contact_id'] = array(
'name' => 'target_id',
'title' => 'Activity Target',
'type' => 1,
- 'FKClassName' => 'CRM_Activity_DAO_ActivityTarget',
+ 'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
);
- $params['activity_status_id'] = array(
- 'name' => 'status_id',
- 'title' => 'Status Id',
- 'type' => 1,
+
+ $params['source_contact_id'] = array(
+ 'name' => 'source_contact_id',
+ 'title' => 'Activity Source Contact',
+ 'type' => 1,
+ 'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
+ 'api.default' => 'user_contact_id',
);
+
}
/**
$returns[$returnkey] = $v;
}
}
-
+ $returns['source_contact_id'] = 1;
foreach ($returns as $n => $v) {
switch ($n) {
case 'assignee_contact_id':
$activities[$key]['target_contact_id'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityArray['id']);
}
break;
+ case 'source_contact_id':
+ foreach ($activities as $key => $activityArray) {
+ $activities[$key]['source_contact_id'] = CRM_Activity_BAO_Activity::getSourceContactID($activityArray['id']);
+ }
+ break;
default:
if (substr($n, 0, 6) == 'custom') {
$returnProperties[$n] = $v;
}
if (!empty($activities) && (!empty($returnProperties) || !empty($params['contact_id']))) {
foreach ($activities as $activityId => $values) {
-
_civicrm_api3_custom_data_get($activities[$activityId], 'Activity', $activityId, NULL, $values['activity_type_id']);
}
}
return civicrm_api3_create_success($activities, $params, 'activity', 'get');
}
+
+
/**
* Delete a specified Activity.
*
function _civicrm_api3_activity_check_params(&$params) {
$contactIDFields = array_intersect_key($params,
- array(
- 'source_contact_id' => 1,
- 'assignee_contact_id' => 1,
- 'target_contact_id' => 1,
- )
+ array(
+ 'source_contact_id' => 1,
+ 'assignee_contact_id' => 1,
+ 'target_contact_id' => 1,
+ )
);
- // this should be handled by wrapper layer & probably the api would already manage it
- //correctly by doing post validation - ie. a failure should result in a roll-back = an error
- // needs testing
+
+ // this should be handled by wrapper layer & probably the api would already manage it
+ //correctly by doing post validation - ie. a failure should result in a roll-back = an error
+ // needs testing
if (!empty($contactIDFields)) {
$contactIds = array();
foreach ($contactIDFields as $fieldname => $contactfield) {
$activityIds = array('activity' => CRM_Utils_Array::value('id', $params),
- 'parent' => CRM_Utils_Array::value('parent_id', $params),
- 'original' => CRM_Utils_Array::value('original_id', $params),
+ 'parent' => CRM_Utils_Array::value('parent_id', $params),
+ 'original' => CRM_Utils_Array::value('original_id', $params),
);
foreach ($activityIds as $id => $value) {
// this should be handled by wrapper layer & probably the api would already manage it
//correctly by doing pseudoconstant validation
// needs testing
- $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
+ $activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate');
$activityName = CRM_Utils_Array::value('activity_name', $params);
$activityName = ucfirst($activityName);
$activityLabel = CRM_Utils_Array::value('activity_label', $params);
if ($activityLabel) {
- $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
+ $activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'create');
}
$activityTypeId = CRM_Utils_Array::value('activity_type_id', $params);
return civicrm_api3_create_error('Invalid Activity Type ID');
}
- // check for activity status is passed in
- // note this should all be removed in favour of wrapper layer validation
- // needs testing
- if (isset($params['activity_status_id'])) {
- $activityStatus = CRM_Core_PseudoConstant::activityStatus();
-
- if (is_numeric($params['activity_status_id']) && !array_key_exists($params['activity_status_id'], $activityStatus)) {
- return civicrm_api3_create_error('Invalid Activity Status');
- }
- elseif (!is_numeric($params['activity_status_id'])) {
- $statusId = array_search($params['activity_status_id'], $activityStatus);
-
- if (!is_numeric($statusId)) {
- return civicrm_api3_create_error('Invalid Activity Status');
- }
- }
- }
-
-
-
// check for activity duration minutes
// this should be validated @ the wrapper layer not here
// needs testing
//if adding a new activity & date_time not set make it now
// this should be managed by the wrapper layer & setting ['api.default'] in speces
// needs testing
- if (!CRM_Utils_Array::value('id', $params) &&
- !CRM_Utils_Array::value('activity_date_time', $params)
- ) {
+ if (empty($params['id']) && empty($params['activity_date_time'])) {
$params['activity_date_time'] = CRM_Utils_Date::processDate(date('Y-m-d H:i:s'));
}