/**
  * the initializer code, called before the processing
  *
  * @return void
  * @access public
  */
 function init()
 {
     require_once 'CRM/Contribute/BAO/Contribution.php';
     $fields =& CRM_Core_BAO_History::importableFields();
     foreach ($fields as $name => $field) {
         $this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
     }
     $this->_newHistory = array();
     $this->setActiveFields($this->_mapperKeys);
     //$this->setActiveFieldLocationTypes( $this->_mapperLocType );
     //$this->setActiveFieldPhoneTypes( $this->_mapperPhoneType );
     // FIXME: we should do this in one place together with Form/MapField.php
     $this->_contactIdIndex = -1;
     $this->_activityTypeIndex = -1;
     $this->_activityDateIndex = -1;
     $index = 0;
     foreach ($this->_mapperKeys as $key) {
         switch ($key) {
             case 'entity_id':
                 $this->_contactIdIndex = $index;
                 break;
             case 'activity_type':
                 $this->_activityTypeIndex = $index;
                 break;
             case 'activity_date':
                 $this->_activityDateIndex = $index;
                 break;
         }
         $index++;
     }
 }
Example #2
0
 /**
  * Browse all activities for a particular contact
  *
  * @param boolean $history - true if we want to browse activity history, false otherwise.
  * @return none
  *
  * @access public
  */
 function browse($history)
 {
     $this->assign('totalCountOpenActivity', CRM_Contact_BAO_Contact::getNumOpenActivity($this->_contactId));
     $this->assign('totalCountActivity', CRM_Core_BAO_History::getNumHistory($this->_contactId, 'Activity'));
     require_once 'CRM/Core/Selector/Controller.php';
     if ($history) {
         $this->assign('history', true);
         // create the selector, controller and run - store results in session
         $output = CRM_CORE_SELECTOR_CONTROLLER_SESSION;
         require_once 'CRM/History/Selector/Activity.php';
         $selector =& new CRM_History_Selector_Activity($this->_contactId, $this->_permission);
         $sortID = null;
         if ($this->get(CRM_UTILS_SORT_SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_UTILS_SORT_SORT_ID), $this->get(CRM_UTILS_SORT_SORT_DIRECTION));
         }
         $controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_UTILS_PAGER_PAGE_ID), $sortID, CRM_CORE_ACTION_VIEW, $this, $output);
         $controller->setEmbedded(true);
         $controller->run();
         $controller->moveFromSessionToTemplate();
     } else {
         $this->assign('history', false);
         // create the selector, controller and run - store results in session
         $output = CRM_CORE_SELECTOR_CONTROLLER_SESSION;
         require_once 'CRM/Contact/Selector/Activity.php';
         $selector =& new CRM_Contact_Selector_Activity($this->_contactId, $this->_permission);
         $sortID = null;
         if ($this->get(CRM_UTILS_SORT_SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_UTILS_SORT_SORT_ID), $this->get(CRM_UTILS_SORT_SORT_DIRECTION));
         }
         $controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_UTILS_PAGER_PAGE_ID), $sortID, CRM_CORE_ACTION_VIEW, $this, $output);
         $controller->setEmbedded(true);
         $controller->run();
         $controller->moveFromSessionToTemplate();
     }
 }
 /** 
  * compose the url to show details of this specific contribution 
  * 
  * @param int $id 
  * @param int $activityHistoryId 
  * 
  * @static 
  * @access public 
  */
 function details($id, $activityHistoryId)
 {
     $params = array();
     $defaults = array();
     $params['id'] = $activityHistoryId;
     $params['entity_table'] = 'civicrm_contact';
     require_once 'CRM/Core/BAO/History.php';
     $history = CRM_Core_BAO_History::retrieve($params, $defaults);
     $contributionId = CRM_Utils_Array::value('activity_id', $defaults);
     if ($contributionId) {
         $cid = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'contact_id');
         return CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=view&id={$contributionId}&cid={$cid}&context=basic");
     } else {
         return CRM_Utils_System::url('civicrm');
     }
 }
Example #4
0
 /**
  * compose the url to show details of this specific Meeting
  *
  * @param int $id
  * @param int $activityHistoryId
  *
  * @static
  * @access public
  *
  */
 function showMeetingDetails($id, $activityHistoryId)
 {
     // require_once 'CRM/Core/DAO/Meeting.php';
     //$dao =& new CRM_Core_DAO_Meeting( );
     //$dao->id = $id;
     $params = array();
     $defaults = array();
     $params['id'] = $activityHistoryId;
     $params['entity_table'] = 'civicrm_contact';
     require_once 'CRM/Core/BAO/History.php';
     $history = CRM_Core_BAO_History::retrieve($params, $defaults);
     $contactId = CRM_Utils_Array::value('entity_id', $defaults);
     //if ( $dao->find( true ) ) {
     if ($contactId) {
         //return CRM_Utils_System::url('civicrm/contact/view/activity', "activity_id=1&cid={$dao->source_contact_id}&action=view&id=$id&status=true&history=1");
         return CRM_Utils_System::url('civicrm/contact/view/activity', "activity_id=1&cid={$contactId}&action=view&id={$id}&status=true&history=1");
     } else {
         return CRM_Utils_System::url('civicrm');
     }
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * Function to process the form
  *
  * @param
  * @access public
  * @return void
  */
 function postProcess()
 {
     CRM_Core_BAO_History::del($this->get('id'));
     CRM_Core_Session::setStatus("Selected Activity History record has been deleted.");
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
/**
 * Get an existing History object
 *
 * Returns a single existing History object which matches ALL property
 * values passed in $params. An error object is returned if there is
 * no match, or more than one match. 
 *
 * @param array   $params    Associative array of property name/value
 *                           pairs to attempt to match on.
 * @param array   $deaults   An assoc array to hold the flattened values.   
 *
 * @return CRM_Core_DAO_$typeHistory|CRM_Core_Error  Return the Contact Object if found, else Error Object
 *
 * @access public
 *
 */
function &crm_get_activity_history_object(&$params, &$defaults)
{
    _crm_initialize();
    $historyObject =& CRM_Core_BAO_History::retrieve($params, $defaults);
    return $historyObject;
}
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects. Typically the valid params are only
  * contact_id. We'll tweak this function to be more full featured over a period
  * of time. This is the inverse function of create. It also stores all the retrieved
  * values in the default array
  *
  * @param array $params   (reference ) an assoc array of name/value pairs
  * @param array $defaults (reference ) an assoc array to hold the name / value pairs
  *                        in a hierarchical manner
  * @param array $ids      (reference) the array that holds all the db ids
  *
  * @return object CRM_Contact_BAO_Contact object
  * @access public
  * @static
  */
 function retrieve(&$params, &$defaults, &$ids)
 {
     $contact = CRM_Contact_BAO_Contact::getValues($params, $defaults, $ids);
     unset($params['id']);
     require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $contact->contact_type) . ".php";
     eval('$contact->contact_type_object =& CRM_Contact_BAO_' . $contact->contact_type . '::getValues( $params, $defaults, $ids );');
     $locParams = $params + array('entity_id' => $params['contact_id'], 'entity_table' => CRM_Contact_BAO_Contact::getTableName());
     $contact->location =& CRM_Core_BAO_Location::getValues($locParams, $defaults, $ids, 3);
     $contact->notes =& CRM_Core_BAO_Note::getValues($params, $defaults, $ids);
     $contact->relationship =& CRM_Contact_BAO_Relationship::getValues($params, $defaults, $ids);
     $contact->groupContact =& CRM_Contact_BAO_GroupContact::getValues($params, $defaults, $ids);
     $activityParam = array('entity_id' => $params['contact_id']);
     $contact->activity =& CRM_Core_BAO_History::getValues($activityParam, $defaults, 'Activity');
     $activityParam = array('contact_id' => $params['contact_id']);
     $defaults['openActivity'] = array('data' => CRM_Contact_BAO_Contact::getOpenActivities($activityParam, 0, 3), 'totalCount' => CRM_Contact_BAO_Contact::getNumOpenActivity($params['contact_id']));
     return $contact;
 }