/** * Function to build the form * * @param * @return void * @access public */ function buildQuickForm() { $id = $this->get('id'); $url = CRM_Utils_System::url('civicrm/contact/view/activity', 'show=1&action=browse&history=1'); if (CRM_Utils_Request::retrieve('confirmed', $form, '', '', 'GET')) { CRM_Core_BAO_History::del($id); CRM_Core_Session::setStatus("Selected Activity History record has been deleted."); CRM_Utils_System::redirect($url); } // only used for delete confirmation $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); // get values for activity date, summary and type from db // and set them up for smarty variables $params = array('id' => $id); $row = CRM_Core_BAO_History::getHistory($params); $fields = array('activity_type', 'activity_summary', 'activity_date'); foreach ($fields as $field) { if ($row[$id][$field]) { $this->assign($field, $row[$id][$field]); } } }
/** * 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; }
/** * Get an existing History * * Returns an array containing existing Histories which matches ALL property * values passed in $params. * * @param array $params Associative array of property name/value * pairs to attempt to match on. * * @param int $offset which row to start from? * @param int $rowCount how many rows to fetch * @param object|array $sort object or array describing sort order for sql query. * * * @param array $returnProperties Which properties should be included in the * returned array. If NULL, the default * set of properties will be included. * * @return array $values Return the array containing the matched Activity Histories * * @access public * */ function &crm_get_activity_history(&$params, $offset = null, $numRow = null, $sort = null) { _crm_initialize(); $values =& CRM_Core_BAO_History::getHistory($params, $offset, $numRow, $sort, 'Activity'); return $values; }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { $params = array('entity_table' => 'civicrm_contact', 'entity_id' => $this->_entityId); $rows =& CRM_Core_BAO_History::getHistory($params, $offset, $rowCount, $sort, 'Activity'); $links =& CRM_History_Selector_Activity::actionLinks(); $mask = array_sum(array_keys($links)) & CRM_Core_Action::mask($this->_permission); foreach ($rows as $k => $row) { $row =& $rows[$k]; if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT && $output != CRM_CORE_SELECTOR_CONTROLLER_SCREEN) { // check if callback exists if ($row['callback']) { $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $k, 'activity_id' => $row['activity_id'], 'cid' => $this->_entityId)); } else { $actionLinks = $links; unset($actionLinks[CRM_CORE_ACTION_VIEW]); //$row['action'] = CRM_Core_Action::formLink($actionLinks, $mask, array('id'=>$k)); $row['action'] = CRM_Core_Action::formLink($actionLinks, $mask, array('id' => $k, 'cid' => $this->_entityId)); } } unset($row); } return $rows; }
/** * 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 * * @return array (reference) the values that could be potentially assigned to smarty * @access public * @static */ function &getValues(&$params, &$values, $type = 'Activity') { // get top 3 histories $values['activity']['data'] =& CRM_Core_BAO_History::getHistory($params, 0, 3, null, $type); // get the total number of histories $values['activity']['totalCount'] =& CRM_Core_BAO_History::getNumHistory($params['entity_id'], $type); return $values; }