本文整理匯總了PHP中CRM_Activity_DAO_Activity::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Activity_DAO_Activity::find方法的具體用法?PHP CRM_Activity_DAO_Activity::find怎麽用?PHP CRM_Activity_DAO_Activity::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Activity_DAO_Activity
的用法示例。
在下文中一共展示了CRM_Activity_DAO_Activity::find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testActivityGeneration
/**
* Testing Activity Generation through Entity Recursion.
*/
public function testActivityGeneration()
{
//Activity set initial params
$daoActivity = new CRM_Activity_DAO_Activity();
$daoActivity->activity_type_id = 1;
$daoActivity->subject = "Initial Activity";
$daoActivity->activity_date_time = '20141002103000';
$daoActivity->save();
$recursion = new CRM_Core_BAO_RecurringEntity();
$recursion->entity_id = $daoActivity->id;
$recursion->entity_table = 'civicrm_activity';
$recursion->dateColumns = array('activity_date_time');
$recursion->schedule = array('entity_value' => $daoActivity->id, 'start_action_date' => $daoActivity->activity_date_time, 'entity_status' => 'fourth saturday', 'repetition_frequency_unit' => 'month', 'repetition_frequency_interval' => 3, 'start_action_offset' => 5, 'used_for' => 'activity');
$generatedEntities = $recursion->generate();
$this->assertEquals(5, count($generatedEntities['civicrm_activity']), "Cehck if number of iterations are 5");
$expectedDates = array('20141025103000', '20141227103000', '20150328103000', '20150627103000', '20150926103000');
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id', 'id', 'Check DB if repeating activities were created');
}
// set mode to ALL, i.e any change to changing activity affects all related recurring activities
$recursion->mode(3);
// lets change subject of initial activity that we created in beginning
$daoActivity->find(TRUE);
$daoActivity->subject = 'Changed Activity';
$daoActivity->save();
// check if other activities were affected
$actualDates = array();
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated');
$actualDates[] = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $entityID, 'activity_date_time', 'id')));
}
$resultDates = array_diff($actualDates, $expectedDates);
$this->assertEquals(0, count($resultDates), "Check if all the value in expected array matches actual array");
}
示例2: _convertToCaseActivity
/**
* @param array $params
*
* @return array
*/
public static function _convertToCaseActivity($params)
{
if (!$params['activityID'] || !$params['caseID']) {
return array('error_msg' => 'required params missing.');
}
$otherActivity = new CRM_Activity_DAO_Activity();
$otherActivity->id = $params['activityID'];
if (!$otherActivity->find(TRUE)) {
return array('error_msg' => 'activity record is missing.');
}
$actDateTime = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
// Create new activity record.
$mainActivity = new CRM_Activity_DAO_Activity();
$mainActVals = array();
CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
// Get new activity subject.
if (!empty($params['newSubject'])) {
$mainActVals['subject'] = $params['newSubject'];
}
$mainActivity->copyValues($mainActVals);
$mainActivity->id = NULL;
$mainActivity->activity_date_time = $actDateTime;
// Make sure this is current revision.
$mainActivity->is_current_revision = TRUE;
// Drop all relations.
$mainActivity->parent_id = $mainActivity->original_id = NULL;
$mainActivity->save();
$mainActivityId = $mainActivity->id;
CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
$mainActivity->free();
// Mark previous activity as deleted. If it was a non-case activity
// then just change the subject.
if (in_array($params['mode'], array('move', 'file'))) {
$caseActivity = new CRM_Case_DAO_CaseActivity();
$caseActivity->case_id = $params['caseID'];
$caseActivity->activity_id = $otherActivity->id;
if ($params['mode'] == 'move' || $caseActivity->find(TRUE)) {
$otherActivity->is_deleted = 1;
} else {
$otherActivity->subject = ts('(Filed on case %1)', array(1 => $params['caseID'])) . ' ' . $otherActivity->subject;
}
$otherActivity->activity_date_time = $actDateTime;
$otherActivity->save();
$caseActivity->free();
}
$otherActivity->free();
$targetContacts = array();
if (!empty($params['targetContactIds'])) {
$targetContacts = array_unique(explode(',', $params['targetContactIds']));
}
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']);
$src_params = array('activity_id' => $mainActivityId, 'contact_id' => $sourceContactID, 'record_type_id' => $sourceID);
CRM_Activity_BAO_ActivityContact::create($src_params);
foreach ($targetContacts as $key => $value) {
$targ_params = array('activity_id' => $mainActivityId, 'contact_id' => $value, 'record_type_id' => $targetID);
CRM_Activity_BAO_ActivityContact::create($targ_params);
}
// typically this will be empty, since assignees on another case may be completely different
$assigneeContacts = array();
if (!empty($params['assigneeContactIds'])) {
$assigneeContacts = array_unique(explode(',', $params['assigneeContactIds']));
}
foreach ($assigneeContacts as $key => $value) {
$assigneeParams = array('activity_id' => $mainActivityId, 'contact_id' => $value, 'record_type_id' => $assigneeID);
CRM_Activity_BAO_ActivityContact::create($assigneeParams);
}
// Attach newly created activity to case.
$caseActivity = new CRM_Case_DAO_CaseActivity();
$caseActivity->case_id = $params['caseID'];
$caseActivity->activity_id = $mainActivityId;
$caseActivity->save();
$error_msg = $caseActivity->_lastError;
$caseActivity->free();
$params['mainActivityId'] = $mainActivityId;
CRM_Activity_BAO_Activity::copyExtendedActivityData($params);
return array('error_msg' => $error_msg, 'newId' => $mainActivity->id);
}
示例3: isSurveyActivity
/**
* check survey activity.
*
* @param int $activityId
* Activity id.
* @return bool
*/
public static function isSurveyActivity($activityId)
{
$isSurveyActivity = FALSE;
if (!$activityId) {
return $isSurveyActivity;
}
$activity = new CRM_Activity_DAO_Activity();
$activity->id = $activityId;
$activity->selectAdd('source_record_id, activity_type_id');
if ($activity->find(TRUE) && $activity->source_record_id) {
$surveyActTypes = self::getSurveyActivityType();
if (array_key_exists($activity->activity_type_id, $surveyActTypes)) {
$isSurveyActivity = TRUE;
}
}
return $isSurveyActivity;
}
示例4: create
/**
* 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 CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = array())
{
$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]);
}
}
//if contribution is created with cancelled or refunded status, add credit note id
if (!empty($params['contribution_status_id'])) {
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if ($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) {
if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") {
$params['creditnote_id'] = self::createCreditNoteId();
}
}
}
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (!empty($params['note'])) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams);
}
// make entry in batch entity batch table
if (!empty($params['batch_id'])) {
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
}
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
// check if activity record exist for this contribution, if
// not add activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find(TRUE)) {
if (empty($contribution->contact_id)) {
$contribution->find(TRUE);
}
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
} else {
// CRM-13237 : if activity record found, update it with campaign id of contribution
CRM_Core_DAO::setFieldValue('CRM_Activity_BAO_Activity', $activity->id, 'campaign_id', $contribution->campaign_id);
}
// do not add to recent items for import, CRM-4399
if (empty($params['skipRecentView'])) {
$url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->financial_type_id] . ')';
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
//.........這裏部分代碼省略.........
示例5: array
/**
* 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
*/
static function &create(&$params, &$ids)
{
require_once 'CRM/Utils/Money.php';
require_once 'CRM/Utils/Date.php';
require_once 'CRM/Contribute/PseudoConstant.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]);
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session =& CRM_Core_Session::singleton();
if (CRM_Utils_Array::value('note', $params)) {
require_once 'CRM/Core/BAO/Note.php';
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids));
}
// check if activity record exist for this contribution, if
// not add activity
require_once "CRM/Activity/DAO/Activity.php";
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find()) {
require_once "CRM/Activity/BAO/Activity.php";
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
}
if (CRM_Utils_Array::value('soft_credit_to', $params)) {
$csParams = array();
if ($id = CRM_Utils_Array::value('softID', $params)) {
$csParams['id'] = $params['softID'];
}
$csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) {
if (CRM_Utils_Array::value($val, $params)) {
$csParams[$val] = $params[$val];
}
}
$csParams['contribution_id'] = $contribution->id;
$csParams['contact_id'] = $params['soft_credit_to'];
// first stage: we register whole amount as credited to given person
$csParams['amount'] = $contribution->total_amount;
self::addSoftContribution($csParams);
}
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
require_once 'CRM/Utils/Recent.php';
require_once 'CRM/Contribute/PseudoConstant.php';
require_once 'CRM/Contact/BAO/Contact.php';
$url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
$contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->contribution_type_id] . ')';
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
// add the recently created Contribution
CRM_Utils_Recent::add($title, $url, $contribution->id, 'Contribution', $contribution->contact_id, null, $recentOther);
}
return $contribution;
}
示例6: browse
/**
* Browse all Public Holidays
*
*
* @return void
* @access public
* @static
*/
function browse()
{
$publicHoliday = array();
$dao = new CRM_Activity_DAO_Activity();
$dao->activity_type_id = civicrm_api3('OptionValue', 'getvalue', array('name' => 'Public Holiday', 'return' => 'value'));
$dao->find();
while ($dao->fetch()) {
$publicHoliday[$dao->id] = array();
$publicHoliday[$dao->id]['id'] = $dao->id;
$publicHoliday[$dao->id]['subject'] = $dao->subject;
if (array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus()) == $dao->status_id) {
$publicHoliday[$dao->id]['status'] = 1;
} else {
$publicHoliday[$dao->id]['status'] = 0;
}
$publicHoliday[$dao->id]['date'] = $dao->activity_date_time;
// form all action links
$action = array_sum(array_keys($this->links()));
$publicHoliday[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
}
$this->assign('rows', $publicHoliday);
}
示例7: registerInterview
static function registerInterview($params)
{
$activityId = CRM_Utils_Array::value('activity_id', $params);
$surveyTypeId = CRM_Utils_Array::value('activity_type_id', $params);
if (!is_array($params) || !$surveyTypeId || !$activityId) {
return false;
}
static $surveyFields;
if (!is_array($surveyFields)) {
require_once 'CRM/Core/BAO/CustomField.php';
$surveyFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $surveyTypeId, null, false, true);
}
static $statusId;
if (!$statusId) {
require_once 'CRM/Core/PseudoConstant.php';
$statusId = array_search('Completed', CRM_Core_PseudoConstant::activityStatus('name'));
}
//format custom fields.
$customParams = CRM_Core_BAO_CustomField::postProcess($params, $surveyFields, $activityId, 'Activity');
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($customParams, 'civicrm_activity', $activityId);
//update activity record.
require_once 'CRM/Activity/DAO/Activity.php';
$activity = new CRM_Activity_DAO_Activity();
$activity->id = $activityId;
$activity->selectAdd();
$activity->selectAdd('activity_date_time, status_id, result, subject');
$activity->find(true);
$activity->activity_date_time = date('Ymdhis');
$activity->status_id = $statusId;
if (CRM_Utils_Array::value('details', $params)) {
$activity->details = $params['details'];
}
if ($result = CRM_Utils_Array::value('result', $params)) {
$activity->result = $result;
}
$subject = '';
$surveyTitle = CRM_Utils_Array::value('surveyTitle', $params);
if ($surveyTitle) {
$subject = ts('%1', array(1 => $surveyTitle));
$subject .= ' - ';
}
$subject .= ts('Respondent Interview');
$activity->subject = $subject;
$activity->save();
$activity->free();
return $activityId;
}
示例8: checkPermission
/**
* Does user has sufficient permission for view/edit activity record.
*
* @param int $activityId
* Activity record id.
* @param int $action
* Edit/view.
*
* @return bool
*/
public static function checkPermission($activityId, $action)
{
$allow = FALSE;
if (!$activityId || !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW))) {
return $allow;
}
$activity = new CRM_Activity_DAO_Activity();
$activity->id = $activityId;
if (!$activity->find(TRUE)) {
return $allow;
}
// Component related permissions.
$compPermissions = array('CiviCase' => array('administer CiviCase', 'access my cases and activities', 'access all cases and activities'), 'CiviMail' => array('access CiviMail'), 'CiviEvent' => array('access CiviEvent'), 'CiviGrant' => array('access CiviGrant'), 'CiviPledge' => array('access CiviPledge'), 'CiviMember' => array('access CiviMember'), 'CiviReport' => array('access CiviReport'), 'CiviContribute' => array('access CiviContribute'), 'CiviCampaign' => array('administer CiviCampaign'));
// Return early when it is case activity.
$isCaseActivity = CRM_Case_BAO_Case::isCaseActivity($activityId);
// Check for civicase related permission.
if ($isCaseActivity) {
$allow = FALSE;
foreach ($compPermissions['CiviCase'] as $per) {
if (CRM_Core_Permission::check($per)) {
$allow = TRUE;
break;
}
}
// Check for case specific permissions.
if ($allow) {
$oper = 'view';
if ($action == CRM_Core_Action::UPDATE) {
$oper = 'edit';
}
$allow = CRM_Case_BAO_Case::checkPermission($activityId, $oper, $activity->activity_type_id);
}
return $allow;
}
// First check the component permission.
$sql = "\n SELECT component_id\n FROM civicrm_option_value val\nINNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.name = %1 )\n WHERE val.value = %2";
$params = array(1 => array('activity_type', 'String'), 2 => array($activity->activity_type_id, 'Integer'));
$componentId = CRM_Core_DAO::singleValueQuery($sql, $params);
if ($componentId) {
$componentName = CRM_Core_Component::getComponentName($componentId);
$compPermission = CRM_Utils_Array::value($componentName, $compPermissions);
// Here we are interesting in any single permission.
if (is_array($compPermission)) {
foreach ($compPermission as $per) {
if (CRM_Core_Permission::check($per)) {
$allow = TRUE;
break;
}
}
}
}
// Check for this permission related to contact.
$permission = CRM_Core_Permission::VIEW;
if ($action == CRM_Core_Action::UPDATE) {
$permission = CRM_Core_Permission::EDIT;
}
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
// Check for source contact.
if (!$componentId || $allow) {
$sourceContactId = self::getActivityContact($activity->id, $sourceID);
// Account for possibility of activity not having a source contact (as it may have been deleted).
if ($sourceContactId) {
$allow = CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission);
}
}
// Check for target and assignee contacts.
if ($allow) {
// First check for supper permission.
$supPermission = 'view all contacts';
if ($action == CRM_Core_Action::UPDATE) {
$supPermission = 'edit all contacts';
}
$allow = CRM_Core_Permission::check($supPermission);
// User might have sufficient permission, through acls.
if (!$allow) {
$allow = TRUE;
// Get the target contacts.
$targetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID);
foreach ($targetContacts as $cnt => $contactId) {
if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) {
$allow = FALSE;
break;
}
}
// Get the assignee contacts.
if ($allow) {
$assigneeContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
//.........這裏部分代碼省略.........
示例9: recordAdditionPayment
static function recordAdditionPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL)
{
$statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
$getInfoOf['id'] = $contributionId;
$defaults = array();
$contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray);
if ($paymentType == 'owed') {
// build params for recording financial trxn entry
$params['contribution'] = $contributionDAO;
$params = array_merge($defaults, $params);
$params['skipLineItem'] = TRUE;
$params['partial_payment_total'] = $contributionDAO->total_amount;
$params['partial_amount_pay'] = $trxnsData['total_amount'];
$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
$trxnId = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId, $contributionDAO->financial_type_id);
$trxnId = $trxnId['trxn_id'];
// update statuses
// criteria for updates contribution total_amount == financial_trxns of partial_payments
$sql = "SELECT SUM(ft.total_amount) as sum_of_payments\nFROM civicrm_financial_trxn ft\nLEFT JOIN civicrm_entity_financial_trxn eft\n ON (ft.id = eft.financial_trxn_id)\nWHERE eft.entity_table = 'civicrm_contribution'\n AND eft.entity_id = {$contributionId}\n AND ft.to_financial_account_id != {$toFinancialAccount}\n AND ft.status_id = {$statusId}\n";
$sumOfPayments = CRM_Core_DAO::singleValueQuery($sql);
// update statuses
if ($contributionDAO->total_amount == $sumOfPayments) {
// update contribution status
$contributionUpdate['id'] = $contributionId;
$contributionUpdate['contribution_status_id'] = $statusId;
$contributionUpdate['skipLineItem'] = TRUE;
// note : not using the self::add method,
// the reason because it performs 'status change' related code execution for financial records
// which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
$contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
if ($participantId) {
// update participant status
$participantUpdate['id'] = $participantId;
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
$participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
CRM_Event_BAO_Participant::add($participantUpdate);
}
// update financial item statuses
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$paidStatus = array_search('Paid', $financialItemStatus);
$sqlFinancialItemUpdate = "\nUPDATE civicrm_financial_item fi\n LEFT JOIN civicrm_entity_financial_trxn eft\n ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET status_id = {$paidStatus}\nWHERE eft.financial_trxn_id = {$trxnId}\n";
CRM_Core_DAO::executeQuery($sqlFinancialItemUpdate);
}
} elseif ($paymentType == 'refund') {
// build params for recording financial trxn entry
$params['contribution'] = $contributionDAO;
$params = array_merge($defaults, $params);
$params['skipLineItem'] = TRUE;
$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
$trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
// note : not using the self::add method,
// the reason because it performs 'status change' related code execution for financial records
// which in 'Pending Refund' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
$contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
// add financial item entry
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$getLine['entity_id'] = $contributionDAO->id;
$getLine['entity_table'] = 'civicrm_contribution';
$lineItemId = CRM_Price_BAO_LineItem::retrieve($getLine, CRM_Core_DAO::$_nullArray);
$addFinancialEntry = array('transaction_date' => $financialTrxn->trxn_date, 'contact_id' => $contributionDAO->contact_id, 'amount' => $financialTrxn->total_amount, 'status_id' => array_search('Paid', $financialItemStatus), 'entity_id' => $lineItemId->id, 'entity_table' => 'civicrm_line_item');
$trxnIds['id'] = $financialTrxn->id;
CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds);
if ($participantId) {
// update participant status
$participantUpdate['id'] = $participantId;
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
$participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
CRM_Event_BAO_Participant::add($participantUpdate);
}
}
// activity creation
if (!empty($financialTrxn)) {
if ($participantId) {
$inputParams['id'] = $participantId;
$values = array();
$ids = array();
$component = 'event';
$entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids);
$entityObj = $entityObj[$participantId];
}
$activityType = $paymentType == 'refund' ? 'Refund' : 'Payment';
// creation of activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $financialTrxn->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name');
if (!$activity->find(TRUE)) {
self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component);
}
}
return $financialTrxn;
}
示例10: registerInterview
/**
* @param array $params
*
* @return mixed
*/
public static function registerInterview($params)
{
$activityId = CRM_Utils_Array::value('activity_id', $params);
$surveyTypeId = CRM_Utils_Array::value('activity_type_id', $params);
if (!is_array($params) || !$surveyTypeId || !$activityId) {
return FALSE;
}
static $surveyFields;
if (!is_array($surveyFields)) {
$surveyFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $surveyTypeId, NULL, FALSE, TRUE);
}
static $statusId;
if (!$statusId) {
$statusId = array_search('Completed', CRM_Core_PseudoConstant::activityStatus('name'));
}
//format custom fields.
$customParams = CRM_Core_BAO_CustomField::postProcess($params, $activityId, 'Activity');
CRM_Core_BAO_CustomValueTable::store($customParams, 'civicrm_activity', $activityId);
//process contact data.
$contactParams = $fields = array();
$contactFieldTypes = array_merge(array('Contact'), CRM_Contact_BAO_ContactType::basicTypes());
$responseFields = CRM_Campaign_BAO_Survey::getSurveyResponseFields($params['survey_id']);
if (!empty($responseFields)) {
foreach ($params as $key => $value) {
if (array_key_exists($key, $responseFields)) {
if (in_array($responseFields[$key]['field_type'], $contactFieldTypes)) {
$fields[$key] = $responseFields[$key];
$contactParams[$key] = $value;
if (isset($params["{$key}_id"])) {
$contactParams["{$key}_id"] = $params["{$key}_id"];
}
}
}
}
}
$contactId = CRM_Utils_Array::value('voter_id', $params);
if ($contactId && !empty($contactParams)) {
CRM_Contact_BAO_Contact::createProfileContact($contactParams, $fields, $contactId);
}
//update activity record.
$activity = new CRM_Activity_DAO_Activity();
$activity->id = $activityId;
$activity->selectAdd();
$activity->selectAdd('activity_date_time, status_id, result, subject');
$activity->find(TRUE);
$activity->activity_date_time = date('YmdHis');
$activity->status_id = $statusId;
if (!empty($params['activity_date_time'])) {
$activity->activity_date_time = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
}
$subject = '';
$surveyTitle = CRM_Utils_Array::value('surveyTitle', $params);
if ($surveyTitle) {
$subject = $surveyTitle . ' - ';
}
$subject .= ts('Respondent Interview');
$activity->subject = $subject;
$activityParams = array('details' => 'details', 'result' => 'result', 'engagement_level' => 'activity_engagement_level', 'subject' => 'activity_subject', 'status_id' => 'activity_status_id', 'source_contact_id' => 'source_contact', 'location' => 'activity_location', 'campaign_id' => 'activity_campaign_id', 'duration' => 'activity_duration');
foreach ($activityParams as $key => $field) {
if (!empty($params[$field])) {
$activity->{$key} = $params[$field];
}
}
$activity->save();
//really this should use Activity BAO& not be here but refactoring will have to be later
//actually the whole ajax call could be done as an api ajax call & post hook would be sorted
CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity);
$activity->free();
return $activityId;
}
示例11: isSurveyActivity
static function isSurveyActivity($activityId)
{
$isSurveyActivity = false;
if (!$activityId) {
return $isSurveyActivity;
}
require_once 'CRM/Activity/DAO/Activity.php';
$activity = new CRM_Activity_DAO_Activity();
$activity->id = $activityId;
$activity->selectAdd('source_record_id, activity_type_id');
if ($activity->find(true) && $activity->source_record_id) {
$surveyActTypes = self::getSurveyActivityType();
if (array_key_exists($activity->activity_type_id, $surveyActTypes)) {
$isSurveyActivity = true;
}
}
return $isSurveyActivity;
}
示例12: convertToCaseActivity
static function convertToCaseActivity()
{
$params = array('caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode');
foreach ($params as $param) {
${$param} = CRM_Utils_Array::value($param, $_POST);
}
if (!$activityID || !$caseID) {
echo json_encode(array('error_msg' => 'required params missing.'));
CRM_Utils_System::civiExit();
}
require_once "CRM/Activity/DAO/Activity.php";
$otherActivity = new CRM_Activity_DAO_Activity();
$otherActivity->id = $activityID;
if (!$otherActivity->find(true)) {
echo json_encode(array('error_msg' => 'activity record is missing.'));
CRM_Utils_System::civiExit();
}
$actDateTime = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
//create new activity record.
$mainActivity = new CRM_Activity_DAO_Activity();
$mainActVals = array();
CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
//get new activity subject.
if (!empty($newSubject)) {
$mainActVals['subject'] = $newSubject;
}
$mainActivity->copyValues($mainActVals);
$mainActivity->id = null;
$mainActivity->activity_date_time = $actDateTime;
//make sure this is current revision.
$mainActivity->is_current_revision = true;
//drop all relations.
$mainActivity->parent_id = $mainActivity->original_id = null;
$mainActivity->save();
$mainActivityId = $mainActivity->id;
require_once 'CRM/Activity/BAO/Activity.php';
CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
$mainActivity->free();
//mark previous activity as deleted.
if (in_array($mode, array('move', 'file'))) {
$otherActivity->activity_date_time = $actDateTime;
$otherActivity->is_deleted = 1;
$otherActivity->save();
}
$otherActivity->free();
require_once "CRM/Activity/BAO/Activity.php";
$targetContacts = array();
if (!empty($targetContactIds)) {
$targetContacts = array_unique(explode(',', $targetContactIds));
}
foreach ($targetContacts as $key => $value) {
$params = array('activity_id' => $mainActivityId, 'target_contact_id' => $value);
CRM_Activity_BAO_Activity::createActivityTarget($params);
}
//attach newly created activity to case.
require_once "CRM/Case/DAO/CaseActivity.php";
$caseActivity = new CRM_Case_DAO_CaseActivity();
$caseActivity->case_id = $caseID;
$caseActivity->activity_id = $mainActivityId;
$caseActivity->save();
$error_msg = $caseActivity->_lastError;
$caseActivity->free();
echo json_encode(array('error_msg' => $error_msg));
CRM_Utils_System::civiExit();
}
示例13: array
/**
* 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
*/
static function &create(&$params, &$ids)
{
// 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]);
}
}
if (CRM_Utils_Array::value('contribution', $ids) && !CRM_Utils_Array::value('softID', $params)) {
if ($softID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionSoft', $ids['contribution'], 'id', 'contribution_id')) {
$params['softID'] = $softID;
}
}
$transaction = new CRM_Core_Transaction();
// delete the soft credit record if no soft credit contact ID AND no PCP is set in the form
if (CRM_Utils_Array::value('contribution', $ids) && (!CRM_Utils_Array::value('soft_credit_to', $params) && !CRM_Utils_Array::value('pcp_made_through_id', $params)) && CRM_Utils_Array::value('softID', $params)) {
$softCredit = new CRM_Contribute_DAO_ContributionSoft();
$softCredit->id = $params['softID'];
$softCredit->delete();
}
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (CRM_Utils_Array::value('note', $params)) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids));
}
// make entry in batch entity batch table
if (CRM_Utils_Array::value('batch_id', $params)) {
$entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id);
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'contribution_type_id');
$retrieverequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieverequired = 1;
break;
}
}
if ($retrieverequired == 1) {
$contribution->find(true);
}
CRM_Core_BAO_Batch::addBatchEntity($entityParams);
}
// check if activity record exist for this contribution, if
// not add activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find()) {
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
}
// Handle soft credit and / or link to personal campaign page
if (CRM_Utils_Array::value('soft_credit_to', $params) || CRM_Utils_Array::value('pcp_made_through_id', $params)) {
$csParams = array();
if ($id = CRM_Utils_Array::value('softID', $params)) {
$csParams['id'] = $params['softID'];
}
$csParams['contribution_id'] = $contribution->id;
// If pcp_made_through_id set, we define soft_credit_to contact based on selected PCP,
// else use passed soft_credit_to
if (CRM_Utils_Array::value('pcp_made_through_id', $params)) {
$csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) {
$csParams[$val] = $params[$val];
}
$csParams['pcp_id'] = CRM_Utils_Array::value('pcp_made_through_id', $params);
$csParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $csParams['pcp_id'], 'contact_id');
} else {
$csParams['contact_id'] = $params['soft_credit_to'];
$csParams['pcp_id'] = '';
}
// first stage: we register whole amount as credited to given person
$csParams['amount'] = $contribution->total_amount;
self::addSoftContribution($csParams);
}
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
//.........這裏部分代碼省略.........
示例14: create
/**
* 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 CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = array())
{
$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]);
}
}
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (!empty($params['note'])) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams);
}
// make entry in batch entity batch table
if (!empty($params['batch_id'])) {
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
}
// Handle soft credit and / or link to personal campaign page
$softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id);
$pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE);
if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
$softParams = array();
$softParams['id'] = $pcpId ? $pcpId : NULL;
$softParams['contribution_id'] = $contribution->id;
$softParams['pcp_id'] = $pcp['pcp_made_through_id'];
$softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp['pcp_made_through_id'], 'contact_id');
$softParams['currency'] = $contribution->currency;
$softParams['amount'] = $contribution->total_amount;
$softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
$softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
$softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
$softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
$contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($softParams);
//Send notification to owner for PCP
if ($contributionSoft->pcp_id && empty($pcpId)) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
}
} elseif (array_key_exists('pcp', $params) && $pcpId) {
$deleteParams = array('id' => $pcpId);
CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
}
if (isset($params['soft_credit'])) {
$softParams = $params['soft_credit'];
foreach ($softParams as $softParam) {
if (!empty($softIDs)) {
$key = key($softIDs);
$softParam['id'] = $softIDs[$key];
unset($softIDs[$key]);
}
$softParam['contribution_id'] = $contribution->id;
$softParam['currency'] = $contribution->currency;
//case during Contribution Import when we assign soft contribution amount as contribution's total_amount by default
if (empty($softParam['amount'])) {
$softParam['amount'] = $contribution->total_amount;
}
CRM_Contribute_BAO_ContributionSoft::add($softParam);
}
if (!empty($softIDs)) {
foreach ($softIDs as $softID) {
if (!in_array($softID, $params['soft_credit_ids'])) {
$deleteParams = array('id' => $softID);
CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
}
}
}
}
//.........這裏部分代碼省略.........
示例15: cleanupActivity
/**
* This function delete activity record related to contact record,
* when there are no target and assignee record w/ other contact.
*
* @param int $contactId contactId
*
* @return true/null
* @access public
*/
public function cleanupActivity($contactId)
{
$result = null;
if (!$contactId) {
return $result;
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
// delete activity if there are no record in
// civicrm_activity_assignment or civicrm_activity_target
// pointing to any other contact record.
require_once 'CRM/Activity/DAO/ActivityTarget.php';
require_once 'CRM/Activity/DAO/ActivityAssignment.php';
$activity = new CRM_Activity_DAO_Activity();
$activity->source_contact_id = $contactId;
$activity->find();
while ($activity->fetch()) {
$noTarget = $noAssignee = true;
// check for target activity record.
$target = new CRM_Activity_DAO_ActivityTarget();
$target->activity_id = $activity->id;
$target->find();
while ($target->fetch()) {
if ($target->target_contact_id != $contactId) {
$noTarget = false;
break;
}
}
$target->free();
// check for assignee activity record.
$assignee = new CRM_Activity_DAO_ActivityAssignment();
$assignee->activity_id = $activity->id;
$assignee->find();
while ($assignee->fetch()) {
if ($assignee->assignee_contact_id != $contactId) {
$noAssignee = false;
break;
}
}
$assignee->free();
// finally delete activity.
if ($noTarget && $noAssignee) {
$activityParams = array('id' => $activity->id);
$result = self::deleteActivity($activityParams);
}
}
$activity->free();
$transaction->commit();
return $result;
}