/** * Create a new Activity History. * * Creates a new history record and returns the newly created * History object. Minimum required data values are entity_id, * and activity_id * * @param array $params Associative array of property name/value * pairs to insert in new history. * * @return CRM_Core_DAO_History|CRM_Error Newly created History object * * @access public */ function &crm_create_activity_history(&$params) { _crm_initialize(); // return error if we do not get any params if (empty($params)) { return _crm_error(ts('Input Parameters empty')); } $error = _crm_check_history_params($params, 'Activity'); if (is_a($error, 'CRM_Core_Error')) { return $error; } $ids = array(); $history = CRM_Core_BAO_History::create($params, $ids, 'Activity'); return $history; }
/** * takes an associative array and creates a contribution object * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ function &create(&$params, &$ids) { require_once 'CRM/Utils/Money.php'; require_once 'CRM/Utils/Date.php'; // FIXME: a cludgy hack to fix the dates to MySQL format $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date'); foreach ($dateFields as $df) { if (isset($params[$df])) { $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]); } } CRM_Core_DAO::transaction('BEGIN'); $contribution = CRM_Contribute_BAO_Contribution::add($params, $ids); if (is_a($contribution, 'CRM_Core_Error')) { CRM_Core_DAO::transaction('ROLLBACK'); return $contribution; } $params['contribution_id'] = $contribution->id; // add custom field values if (CRM_Utils_Array::value('custom', $params)) { foreach ($params['custom'] as $customValue) { $cvParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']); if ($customValue['id']) { $cvParams['id'] = $customValue['id']; } CRM_Core_BAO_CustomValue::create($cvParams); } } // let's create an (or update the relevant) Acitivity History record $contributionType = CRM_Contribute_PseudoConstant::contributionType($contribution->contribution_type_id); if (!$contributionType) { $contributionType = ts('Contribution'); } if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']) { $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'] = CRM_Utils_Date::customFormat(date('Y-m-d H:i')); } $activitySummary = ts('%1 - %2 (updated on %3)', array(1 => CRM_Utils_Money::format($contribution->total_amount, $contribution->currency), 2 => $contributionType, 3 => $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'])); $historyParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contribution->contact_id, 'activity_type' => $contributionType, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => $activitySummary, 'activity_date' => $contribution->receive_date); if (CRM_Utils_Array::value('contribution', $ids)) { // this contribution should have an Activity History record already $getHistoryParams = array('module' => 'CiviContribute', 'activity_id' => $contribution->id); $getHistoryValues =& CRM_Core_BAO_History::getHistory($getHistoryParams, 0, 1, null, 'Activity'); if (!empty($getHistoryValues)) { $tmp = array_keys($getHistoryValues); $ids['activity_history'] = $tmp[0]; } } $historyDAO =& CRM_Core_BAO_History::create($historyParams, $ids, 'Activity'); if (is_a($historyDAO, 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity History for contribution of id {$contribution->id}"); } CRM_Core_DAO::transaction('COMMIT'); return $contribution; }