本文整理匯總了PHP中CRM_Activity_DAO_Activity::copyValues方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Activity_DAO_Activity::copyValues方法的具體用法?PHP CRM_Activity_DAO_Activity::copyValues怎麽用?PHP CRM_Activity_DAO_Activity::copyValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Activity_DAO_Activity
的用法示例。
在下文中一共展示了CRM_Activity_DAO_Activity::copyValues方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: mergeCases
//.........這裏部分代碼省略.........
if (!$otherActId || in_array($otherActId, $otherActivityIds)) {
continue;
}
$otherActivityIds[] = $otherActId;
}
if ($duplicateCases) {
if ($openCaseType = array_search('Open Case', $activityTypes)) {
$sql = "\nSELECT id\n FROM civicrm_activity\n WHERE activity_type_id = {$openCaseType}\n AND id IN ( " . implode(',', array_values($otherActivityIds)) . ');';
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$singletonActivityIds[] = $dao->id;
}
$dao->free();
}
}
// migrate all activities and connect to main contact.
$copiedActivityIds = $activityMappingIds = array();
sort($otherActivityIds);
foreach ($otherActivityIds as $otherActivityId) {
//for duplicate cases -
//do not migrate singleton activities.
if (!$otherActivityId || in_array($otherActivityId, $singletonActivityIds)) {
continue;
}
//migrate activity record.
$otherActivity = new CRM_Activity_DAO_Activity();
$otherActivity->id = $otherActivityId;
if (!$otherActivity->find(TRUE)) {
continue;
}
$mainActVals = array();
$mainActivity = new CRM_Activity_DAO_Activity();
CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
$mainActivity->copyValues($mainActVals);
$mainActivity->id = NULL;
$mainActivity->activity_date_time = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
$mainActivity->source_record_id = CRM_Utils_Array::value($mainActivity->source_record_id, $activityMappingIds);
$mainActivity->original_id = CRM_Utils_Array::value($mainActivity->original_id, $activityMappingIds);
$mainActivity->parent_id = CRM_Utils_Array::value($mainActivity->parent_id, $activityMappingIds);
$mainActivity->save();
$mainActivityId = $mainActivity->id;
if (!$mainActivityId) {
continue;
}
$activityMappingIds[$otherActivityId] = $mainActivityId;
// insert log of all activities
CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
$otherActivity->free();
$mainActivity->free();
$copiedActivityIds[] = $otherActivityId;
//create case activity record.
$mainCaseActivity = new CRM_Case_DAO_CaseActivity();
$mainCaseActivity->case_id = $mainCaseId;
$mainCaseActivity->activity_id = $mainActivityId;
$mainCaseActivity->save();
$mainCaseActivity->free();
//migrate source activity.
$otherSourceActivity = new CRM_Activity_DAO_ActivityContact();
$otherSourceActivity->activity_id = $otherActivityId;
$otherSourceActivity->record_type_id = $sourceID;
$otherSourceActivity->find();
while ($otherSourceActivity->fetch()) {
$mainActivitySource = new CRM_Activity_DAO_ActivityContact();
$mainActivitySource->record_type_id = $sourceID;
$mainActivitySource->activity_id = $mainActivityId;
$mainActivitySource->contact_id = $otherSourceActivity->contact_id;
示例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: restoreActivity
/**
* Restore the activity.
*
* @param array $params
*
* @return CRM_Activity_DAO_Activity
*/
public static function restoreActivity(&$params)
{
$activity = new CRM_Activity_DAO_Activity();
$activity->copyValues($params);
$activity->is_deleted = 0;
$result = $activity->save();
return $result;
}
示例4: endPostProcess
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param $activity
*/
public static function endPostProcess(&$form, &$params, $activity)
{
if (!empty($params['start_date'])) {
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
}
$caseType = CRM_Utils_Array::first($form->_caseType);
$caseId = CRM_Utils_Array::first($form->_caseId);
if (!$caseType && $caseId) {
$caseType = CRM_Case_BAO_Case::getCaseType($caseId, 'title');
}
if (!$form->_currentlyViewedContactId || !$form->_currentUserId || !$caseId || !$caseType) {
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
}
$config = CRM_Core_Config::singleton();
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activity->status_id = $params['status_id'];
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
$activity->priority_id = $params['priority_id'];
// 1. save activity subject with new start date
$currentStartDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'start_date'), $config->dateformatFull);
$newStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Date::mysqlToIso($params['start_date']), $config->dateformatFull);
$subject = 'Change Case Start Date from ' . $currentStartDate . ' to ' . $newStartDate;
$activity->subject = $subject;
$activity->save();
// 2. initiate xml processor
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$xmlProcessorParams = array('clientID' => $form->_currentlyViewedContactId, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 0, 'activity_date_time' => $params['start_date'], 'caseID' => $caseId, 'caseType' => $caseType, 'activityTypeName' => 'Change Case Start Date', 'activitySetName' => 'standard_timeline', 'resetTimeline' => 1);
$xmlProcessor->run($caseType, $xmlProcessorParams);
// 2.5 Update open case activity date
// Multiple steps since revisioned
if ($form->openCaseActivityId) {
$abao = new CRM_Activity_BAO_Activity();
$oldParams = array('id' => $form->openCaseActivityId);
$oldActivityDefaults = array();
$oldActivity = $abao->retrieve($oldParams, $oldActivityDefaults);
// save the old values
require_once 'api/v3/utils.php';
$openCaseParams = array();
//@todo calling api functions directly is not supported
_civicrm_api3_object_to_array($oldActivity, $openCaseParams);
// update existing revision
$oldParams = array('id' => $form->openCaseActivityId, 'is_current_revision' => 0);
$oldActivity = new CRM_Activity_DAO_Activity();
$oldActivity->copyValues($oldParams);
$oldActivity->save();
// change some params for the new one
unset($openCaseParams['id']);
$openCaseParams['activity_date_time'] = $params['start_date'];
$openCaseParams['target_contact_id'] = $oldActivityDefaults['target_contact'];
$openCaseParams['assignee_contact_id'] = $oldActivityDefaults['assignee_contact'];
$session = CRM_Core_Session::singleton();
$openCaseParams['source_contact_id'] = $session->get('userID');
// original_id always refers to the first activity, so only update if null (i.e. this is the second revision)
$openCaseParams['original_id'] = $openCaseParams['original_id'] ? $openCaseParams['original_id'] : $form->openCaseActivityId;
$newActivity = CRM_Activity_BAO_Activity::create($openCaseParams);
if (is_a($newActivity, 'CRM_Core_Error')) {
CRM_Core_Error::fatal('Unable to update Open Case activity');
} else {
// Create linkage to case
$caseActivityParams = array('activity_id' => $newActivity->id, 'case_id' => $caseId);
CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
$caseActivityParams = array('activityID' => $form->openCaseActivityId, 'mainActivityId' => $newActivity->id);
CRM_Activity_BAO_Activity::copyExtendedActivityData($caseActivityParams);
}
}
// 3.status msg
$params['statusMsg'] = ts('Case Start Date changed successfully.');
}
示例5: postProcess
//.........這裏部分代碼省略.........
$params['assignee_contact_id'] = array();
}
if (isset($this->_activityId)) {
// activity which hasn't been modified by a user yet
if ($this->_defaults['is_auto'] == 1) {
$params['is_auto'] = 0;
}
// always create a revision of an case activity. CRM-4533
$newActParams = $params;
// add target contact values in update mode
if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) {
$newActParams['target_contact_id'] = $this->_defaults['target_contact'];
}
}
if (!isset($newActParams)) {
// add more attachments if needed for old activity
CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity');
// call begin post process, before the activity is created/updated.
$this->beginPostProcess($params);
foreach ($this->_caseId as $key => $val) {
$params['case_id'] = $val;
// activity create/update
$activity = CRM_Activity_BAO_Activity::create($params);
$vvalue[] = array('case_id' => $val, 'actId' => $activity->id);
// call end post process, after the activity has been created/updated.
$this->endPostProcess($params, $activity);
}
} else {
// since the params we need to set are very few, and we don't want rest of the
// work done by bao create method , lets use dao object to make the changes
$params = array('id' => $this->_activityId);
$params['is_current_revision'] = 0;
$activity = new CRM_Activity_DAO_Activity();
$activity->copyValues($params);
$activity->save();
}
// create a new version of activity if activity was found to
// have been modified/created by user
if (isset($newActParams)) {
// set proper original_id
if (!empty($this->_defaults['original_id'])) {
$newActParams['original_id'] = $this->_defaults['original_id'];
} else {
$newActParams['original_id'] = $activity->id;
}
//is_current_revision will be set to 1 by default.
// add attachments if any
CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity');
// call begin post process, before the activity is created/updated.
$this->beginPostProcess($newActParams);
foreach ($this->_caseId as $key => $val) {
$newActParams['case_id'] = $val;
$activity = CRM_Activity_BAO_Activity::create($newActParams);
$vvalue[] = array('case_id' => $val, 'actId' => $activity->id);
// call end post process, after the activity has been created/updated.
$this->endPostProcess($newActParams, $activity);
}
// copy files attached to old activity if any, to new one,
// as long as users have not selected the 'delete attachment' option.
if (empty($newActParams['is_delete_attachment'])) {
CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id);
}
// copy back params to original var
$params = $newActParams;
}
foreach ($vvalue as $vkey => $vval) {
示例6: deleteActivity
/**
* Function to delete the activity
* @param array $params associated array
*
* @return void
* @access public
*
*/
public function deleteActivity(&$params, $moveToTrash = false)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
if (!$moveToTrash) {
if (!isset($params['id'])) {
if (is_array($params['activity_type_id'])) {
$activityTypes = implode(',', $params['activity_type_id']);
} else {
$activityTypes = $params['activity_type_id'];
}
$query = "DELETE FROM civicrm_activity WHERE source_record_id = {$params['source_record_id']} AND activity_type_id IN ( {$activityTypes} )";
$dao = CRM_Core_DAO::executeQuery($query);
} else {
$activity = new CRM_Activity_DAO_Activity();
$activity->copyValues($params);
$result = $activity->delete();
}
} else {
$activity = new CRM_Activity_DAO_Activity();
$activity->copyValues($params);
$activity->is_deleted = 1;
$result = $activity->save();
//log activty delete.CRM-4525.
$logMsg = "Case Activity deleted for";
$msgs = array();
$sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id');
if ($sourceContactId) {
$msgs[] = " source={$sourceContactId}";
}
//get target contacts.
$targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
if (!empty($targetContactIds)) {
$msgs[] = " target =" . implode(',', array_keys($targetContactIds));
}
//get assignee contacts.
$assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
if (!empty($assigneeContactIds)) {
$msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds));
}
$logMsg .= implode(', ', $msgs);
self::logActivityAction($activity, $logMsg);
}
// delete the recently created Activity
require_once 'CRM/Utils/Recent.php';
if ($result) {
$activityRecent = array('id' => $activity->id, 'type' => 'Activity');
CRM_Utils_Recent::del($activityRecent);
}
$transaction->commit();
return $result;
}
示例7: 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();
}
示例8: postProcess
//.........這裏部分代碼省略.........
} else {
$params['assignee_contact_id'] = $assineeContacts = array();
}
if (isset($this->_activityId)) {
// activity which hasn't been modified by a user yet
if ($this->_defaults['is_auto'] == 1) {
$params['is_auto'] = 0;
}
// always create a revision of an case activity. CRM-4533
$newActParams = $params;
// add target contact values in update mode
if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) {
$newActParams['target_contact_id'] = $this->_defaults['target_contact'];
}
// record status for status msg
$recordStatus = 'updated';
}
if (!isset($newActParams)) {
// add more attachments if needed for old activity
CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity');
// call begin post process, before the activity is created/updated.
$this->beginPostProcess($params);
$params['case_id'] = $this->_caseId;
// activity create/update
$activity = CRM_Activity_BAO_Activity::create($params);
// call end post process, after the activity has been created/updated.
$this->endPostProcess($params, $activity);
} else {
// since the params we need to set are very few, and we don't want rest of the
// work done by bao create method , lets use dao object to make the changes
$params = array('id' => $this->_activityId);
$params['is_current_revision'] = 0;
$activity = new CRM_Activity_DAO_Activity();
$activity->copyValues($params);
$activity->save();
}
// create a new version of activity if activity was found to
// have been modified/created by user
if (isset($newActParams)) {
// set proper original_id
if (CRM_Utils_Array::value('original_id', $this->_defaults)) {
$newActParams['original_id'] = $this->_defaults['original_id'];
} else {
$newActParams['original_id'] = $activity->id;
}
//is_current_revision will be set to 1 by default.
// add attachments if any
CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity');
// call begin post process, before the activity is created/updated.
$this->beginPostProcess($newActParams);
$newActParams['case_id'] = $this->_caseId;
$activity = CRM_Activity_BAO_Activity::create($newActParams);
// call end post process, after the activity has been created/updated.
$this->endPostProcess($newActParams, $activity);
// copy files attached to old activity if any, to new one,
// as long as users have not selected the 'delete attachment' option.
if (!CRM_Utils_Array::value('is_delete_attachment', $newActParams)) {
CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id);
}
// copy back params to original var
$params = $newActParams;
}
if ($activity->id) {
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
示例9: endPostProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function endPostProcess(&$form, &$params, $activity)
{
if (CRM_Utils_Array::value('start_date', $params)) {
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
}
$caseType = $form->_caseType;
if (!$caseType && $form->_caseId) {
$query = "\nSELECT cov_type.label as case_type FROM civicrm_case \nLEFT JOIN civicrm_option_group cog_type ON cog_type.name = 'case_type'\nLEFT JOIN civicrm_option_value cov_type ON \n( civicrm_case.case_type_id = cov_type.value AND cog_type.id = cov_type.option_group_id ) \nWHERE civicrm_case.id= %1";
$queryParams = array(1 => array($form->_caseId, 'Integer'));
$caseType = CRM_Core_DAO::singleValueQuery($query, $queryParams);
}
if (!$form->_currentlyViewedContactId || !$form->_currentUserId || !$form->_caseId || !$caseType) {
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
}
$config =& CRM_Core_Config::singleton();
// 1. save activity subject with new start date
$currentStartDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $form->_caseId, 'start_date'), $config->dateformatFull);
$newStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Date::mysqlToIso($params['start_date']), $config->dateformatFull);
$subject = 'Change Case Start Date from ' . $currentStartDate . ' to ' . $newStartDate;
$activity->subject = $subject;
$activity->save();
// 2. initiate xml processor
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$xmlProcessorParams = array('clientID' => $form->_currentlyViewedContactId, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 0, 'activity_date_time' => $params['start_date'], 'caseID' => $form->_caseId, 'caseType' => $caseType, 'activityTypeName' => 'Change Case Start Date', 'activitySetName' => 'standard_timeline', 'resetTimeline' => 1);
$xmlProcessor->run($caseType, $xmlProcessorParams);
// 2.5 Update open case activity date
// Multiple steps since revisioned
if ($form->openCaseActivityId) {
require_once 'CRM/Activity/BAO/Activity.php';
$abao = new CRM_Activity_BAO_Activity();
$oldParams = array('id' => $form->openCaseActivityId);
$oldActivityDefaults = array();
$oldActivity = $abao->retrieve($oldParams, $oldActivityDefaults);
// save the old values
require_once 'api/v2/utils.php';
$openCaseParams = array();
_civicrm_object_to_array($oldActivity, $openCaseParams);
// update existing revision
$oldParams = array('id' => $form->openCaseActivityId, 'is_current_revision' => 0);
require_once 'CRM/Activity/DAO/Activity.php';
$oldActivity = new CRM_Activity_DAO_Activity();
$oldActivity->copyValues($oldParams);
$oldActivity->save();
// change some params for the new one
unset($openCaseParams['id']);
$openCaseParams['activity_date_time'] = $params['start_date'];
$openCaseParams['target_contact_id'] = $oldActivityDefaults['target_contact'];
$openCaseParams['assignee_contact_id'] = $oldActivityDefaults['assignee_contact'];
$session =& CRM_Core_Session::singleton();
$openCaseParams['source_contact_id'] = $session->get('userID');
// original_id always refers to the first activity, so only update if null (i.e. this is the second revision)
$openCaseParams['original_id'] = $openCaseParams['original_id'] ? $openCaseParams['original_id'] : $form->openCaseActivityId;
$newActivity = CRM_Activity_BAO_Activity::create($openCaseParams);
if (is_a($newActivity, 'CRM_Core_Error')) {
CRM_Core_Error::fatal('Unable to update Open Case activity');
} else {
// Create linkage to case
$caseActivityParams = array('activity_id' => $newActivity->id, 'case_id' => $form->_caseId);
require_once "CRM/Case/BAO/Case.php";
CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
}
}
// 3.status msg
$params['statusMsg'] = ts('Case Start Date changed successfully.');
}
示例10: mergeCases
//.........這裏部分代碼省略.........
if (!$otherActId || in_array($otherActId, $otherActivityIds)) {
continue;
}
$otherActivityIds[] = $otherActId;
}
if ($duplicateCases) {
if ($openCaseType = array_search('Open Case', $activityTypes)) {
$sql = "\nSELECT id\n FROM civicrm_activity \n WHERE activity_type_id = {$openCaseType} \n AND id IN ( " . implode(',', array_values($otherActivityIds)) . ');';
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$singletonActivityIds[] = $dao->id;
}
$dao->free();
}
}
// migrate all activities and connect to main contact.
$copiedActivityIds = $activityMappingIds = array();
sort($otherActivityIds);
foreach ($otherActivityIds as $otherActivityId) {
//for duplicate cases -
//do not migrate singleton activities.
if (!$otherActivityId || in_array($otherActivityId, $singletonActivityIds)) {
continue;
}
//migrate activity record.
$otherActivity = new CRM_Activity_DAO_Activity();
$otherActivity->id = $otherActivityId;
if (!$otherActivity->find(true)) {
continue;
}
$mainActVals = array();
$mainActivity = new CRM_Activity_DAO_Activity();
CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
$mainActivity->copyValues($mainActVals);
$mainActivity->id = null;
$mainActivity->activity_date_time = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
//do check for merging contact,
if ($mainActivity->source_contact_id == $otherContactId) {
$mainActivity->source_contact_id = $mainContactId;
}
$mainActivity->source_record_id = CRM_Utils_Array::value($mainActivity->source_record_id, $activityMappingIds);
$mainActivity->original_id = CRM_Utils_Array::value($mainActivity->original_id, $activityMappingIds);
$mainActivity->parent_id = CRM_Utils_Array::value($mainActivity->parent_id, $activityMappingIds);
$mainActivity->save();
$mainActivityId = $mainActivity->id;
if (!$mainActivityId) {
continue;
}
$activityMappingIds[$otherActivityId] = $mainActivityId;
// insert log of all activites
CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
$otherActivity->free();
$mainActivity->free();
$copiedActivityIds[] = $otherActivityId;
//create case activity record.
$mainCaseActivity = new CRM_Case_DAO_CaseActivity();
$mainCaseActivity->case_id = $mainCaseId;
$mainCaseActivity->activity_id = $mainActivityId;
$mainCaseActivity->save();
$mainCaseActivity->free();
//migrate target activities.
$otherTargetActivity = new CRM_Activity_DAO_ActivityTarget();
$otherTargetActivity->activity_id = $otherActivityId;
$otherTargetActivity->find();
while ($otherTargetActivity->fetch()) {
$mainActivityTarget = new CRM_Activity_DAO_ActivityTarget();