本文整理匯總了PHP中CRM_Activity_DAO_Activity類的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Activity_DAO_Activity類的具體用法?PHP CRM_Activity_DAO_Activity怎麽用?PHP CRM_Activity_DAO_Activity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CRM_Activity_DAO_Activity類的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: retrieve
/**
* Get a list of Commendations matching the params, where each param key is:
* 1. the key of a field in civicrm_activity, except for activity_type_id
* 2. the key of a custom field on the activity (volunteer_project_id)
* 3. the key of a field in civicrm_contact
*
* @param array $params
* @return array of CRM_Volunteer_BAO_Project objects
*/
public static function retrieve(array $params)
{
$activity_fields = CRM_Activity_DAO_Activity::fields();
$contact_fields = CRM_Contact_DAO_Contact::fields();
$custom_fields = self::getCustomFields();
// This is the "real" id
$activity_fields['id'] = $activity_fields['activity_id'];
unset($activity_fields['activity_id']);
// enforce restrictions on parameters
$allowed_params = array_flip(array_merge(array_keys($activity_fields), array_keys($contact_fields), array_keys($custom_fields)));
unset($allowed_params['activity_type_id']);
$filtered_params = array_intersect_key($params, $allowed_params);
$custom_group = self::getCustomGroup();
$customTableName = $custom_group['table_name'];
foreach ($custom_fields as $name => $field) {
$selectClause[] = "{$customTableName}.{$field['column_name']} AS {$name}";
}
$customSelect = implode(', ', $selectClause);
$activityContactTypes = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContactTypes);
$placeholders = array(1 => array($targetID, 'Integer'), 2 => array(self::getActivityTypeId(), 'Integer'));
$i = count($placeholders) + 1;
$where = array();
$whereClause = NULL;
foreach ($filtered_params as $key => $value) {
if (CRM_Utils_Array::value($key, $activity_fields)) {
$dataType = CRM_Utils_Type::typeToString($activity_fields[$key]['type']);
$fieldName = $activity_fields[$key]['name'];
$tableName = CRM_Activity_DAO_Activity::$_tableName;
} elseif (CRM_Utils_Array::value($key, $contact_fields)) {
$dataType = CRM_Utils_Type::typeToString($contact_fields[$key]['type']);
$fieldName = $contact_fields[$key]['name'];
$tableName = CRM_Contact_DAO_Contact::$_tableName;
} elseif (CRM_Utils_Array::value($key, $custom_fields)) {
$dataType = $custom_fields[$key]['data_type'];
$fieldName = $custom_fields[$key]['column_name'];
$tableName = $customTableName;
}
$where[] = "{$tableName}.{$fieldName} = %{$i}";
$placeholders[$i] = array($value, $dataType);
$i++;
}
if (count($where)) {
$whereClause = 'AND ' . implode("\nAND ", $where);
}
$query = "\n SELECT\n civicrm_activity.*,\n {$customSelect},\n activityContact.contact_id AS volunteer_contact_id,\n volunteer_contact.sort_name AS volunteer_sort_name,\n volunteer_contact.display_name AS volunteer_display_name\n FROM civicrm_activity\n INNER JOIN civicrm_activity_contact activityContact\n ON (\n activityContact.activity_id = civicrm_activity.id\n AND activityContact.record_type_id = %1\n )\n INNER JOIN civicrm_contact volunteer_contact\n ON activityContact.contact_id = volunteer_contact.id\n INNER JOIN {$customTableName}\n ON ({$customTableName}.entity_id = civicrm_activity.id)\n WHERE civicrm_activity.activity_type_id = %2\n {$whereClause}\n ";
$dao = CRM_Core_DAO::executeQuery($query, $placeholders);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->id] = $dao->toArray();
}
return $rows;
}
示例3: _civicrm_api3_deprecated_activity_formatted_param
/**
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
* @param array $params
* Associative array of property name/value.
* pairs to insert in new contact.
* @param array $values
* The reformatted properties that we can use internally.
*
* @param array|bool $create Is the formatted Values array going to
* be used for CRM_Activity_BAO_Activity::create()
*
* @return array|CRM_Error
*/
function _civicrm_api3_deprecated_activity_formatted_param(&$params, &$values, $create = FALSE)
{
// copy all the activity fields as is
$fields = CRM_Activity_DAO_Activity::fields();
_civicrm_api3_store_values($fields, $params, $values);
require_once 'CRM/Core/OptionGroup.php';
$customFields = CRM_Core_BAO_CustomField::getFields('Activity');
foreach ($params as $key => $value) {
// ignore empty values or empty arrays etc
if (CRM_Utils_System::isNull($value)) {
continue;
}
//Handling Custom Data
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
$values[$key] = $value;
$type = $customFields[$customFieldID]['html_type'];
if ($type == 'CheckBox' || $type == 'Multi-Select') {
$mulValues = explode(',', $value);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
$values[$key] = array();
foreach ($mulValues as $v1) {
foreach ($customOption as $customValueID => $customLabel) {
$customValue = $customLabel['value'];
if (strtolower(trim($customLabel['label'])) == strtolower(trim($v1)) || strtolower(trim($customValue)) == strtolower(trim($v1))) {
if ($type == 'CheckBox') {
$values[$key][$customValue] = 1;
} else {
$values[$key][] = $customValue;
}
}
}
}
} elseif ($type == 'Select' || $type == 'Radio') {
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
foreach ($customOption as $customFldID => $customValue) {
$val = CRM_Utils_Array::value('value', $customValue);
$label = CRM_Utils_Array::value('label', $customValue);
$label = strtolower($label);
$value = strtolower(trim($value));
if ($value == $label || $value == strtolower($val)) {
$values[$key] = $val;
}
}
}
}
if ($key == 'target_contact_id') {
if (!CRM_Utils_Rule::integer($value)) {
return civicrm_api3_create_error("contact_id not valid: {$value}");
}
$contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}");
if (!$contactID) {
return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
}
}
}
return NULL;
}
示例4: 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();
}
示例5: create
//.........這裏部分代碼省略.........
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);
}
}
}
}
$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");
}
// add the recently created Contribution
CRM_Utils_Recent::add($title, $url, $contribution->id, 'Contribution', $contribution->contact_id, NULL, $recentOther);
}
return $contribution;
}
示例6: 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);
//.........這裏部分代碼省略.........
示例7: 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;
}
示例8: postProcess
//.........這裏部分代碼省略.........
} else {
$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;
}
示例9: 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;
}
示例10: _civicrm_activity_formatted_param
/**
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
* @param array $params Associative array of property name/value
* pairs to insert in new contact.
* @param array $values The reformatted properties that we can use internally
*
* @param array $create Is the formatted Values array going to
* be used for CRM_Activity_BAO_Activity::create()
*
* @return array|CRM_Error
* @access public
*/
function _civicrm_activity_formatted_param(&$params, &$values, $create = false)
{
$fields =& CRM_Activity_DAO_Activity::fields();
_civicrm_store_values($fields, $params, $values);
require_once 'CRM/Core/OptionGroup.php';
$customFields = CRM_Core_BAO_CustomField::getFields('Activity');
foreach ($params as $key => $value) {
// ignore empty values or empty arrays etc
if (CRM_Utils_System::isNull($value)) {
continue;
}
//Handling Custom Data
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
$values[$key] = $value;
$type = $customFields[$customFieldID]['html_type'];
if ($type == 'CheckBox' || $type == 'Multi-Select') {
$mulValues = explode(',', $value);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
$values[$key] = array();
foreach ($mulValues as $v1) {
foreach ($customOption as $customValueID => $customLabel) {
$customValue = $customLabel['value'];
if (strtolower($customLabel['label']) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
if ($type == 'CheckBox') {
$values[$key][$customValue] = 1;
} else {
$values[$key][] = $customValue;
}
}
}
}
} else {
if ($type == 'Select' || $type == 'Radio') {
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
foreach ($customOption as $customValue => $customLabel) {
if (strtolower($customLabel) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
$values[$key] = $customValue;
}
}
}
}
}
}
return null;
}
示例11: 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;
}
示例12: 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;
}
示例13: civicrm_api3_activity_create
/**
* Creates or updates an Activity. See the example for usage
*
* @param array $params Associative array of property name/value
* pairs for the activity.
* {@getfields activity_create}
*
* @return array Array containing 'is_error' to denote success or failure and details of the created activity
*
* @example ActivityCreate.php Standard create example
* @example Activity/ContactRefCustomField.php Create example including setting a contact reference custom field
* {@example ActivityCreate.php 0}
*
*/
function civicrm_api3_activity_create($params)
{
if (!CRM_Utils_Array::value('id', $params)) {
// an update does not require any mandatory parameters
civicrm_api3_verify_one_mandatory($params, NULL, array('activity_name', 'activity_type_id', 'activity_label'));
}
$errors = array();
// check for various error and required conditions
$errors = _civicrm_api3_activity_check_params($params);
if (!empty($errors)) {
return $errors;
}
// processing for custom data
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Activity');
if (!empty($values['custom'])) {
$params['custom'] = $values['custom'];
}
$params['skipRecentView'] = TRUE;
// If this is a case activity, see if there is an existing activity
// and set it as an old revision. Also retrieve details we'll need.
$case_id = '';
$createRevision = FALSE;
$oldActivityValues = array();
if (CRM_Utils_Array::value('case_id', $params)) {
$case_id = $params['case_id'];
if (CRM_Utils_Array::value('id', $params)) {
$oldActivityParams = array('id' => $params['id']);
if (!$oldActivityValues) {
CRM_Activity_BAO_Activity::retrieve($oldActivityParams, $oldActivityValues);
}
if (empty($oldActivityValues)) {
return civicrm_api3_create_error(ts("Unable to locate existing activity."), NULL, CRM_Core_DAO::$_nullObject);
} else {
require_once 'CRM/Activity/DAO/Activity.php';
$activityDAO = new CRM_Activity_DAO_Activity();
$activityDAO->id = $params['id'];
$activityDAO->is_current_revision = 0;
if (!$activityDAO->save()) {
return civicrm_api3_create_error(ts("Unable to revision existing case activity."), NULL, $activityDAO);
}
$createRevision = TRUE;
}
}
}
$deleteActivityAssignment = FALSE;
if (isset($params['assignee_contact_id'])) {
$deleteActivityAssignment = TRUE;
}
$deleteActivityTarget = FALSE;
if (isset($params['target_contact_id'])) {
$deleteActivityTarget = TRUE;
}
$params['deleteActivityAssignment'] = CRM_Utils_Array::value('deleteActivityAssignment', $params, $deleteActivityAssignment);
$params['deleteActivityTarget'] = CRM_Utils_Array::value('deleteActivityTarget', $params, $deleteActivityTarget);
if ($case_id && $createRevision) {
// This is very similar to the copy-to-case action.
if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['target_contact'])) {
$oldActivityValues['targetContactIds'] = implode(',', array_unique($oldActivityValues['target_contact']));
}
if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['assignee_contact'])) {
$oldActivityValues['assigneeContactIds'] = implode(',', array_unique($oldActivityValues['assignee_contact']));
}
$oldActivityValues['mode'] = 'copy';
$oldActivityValues['caseID'] = $case_id;
$oldActivityValues['activityID'] = $oldActivityValues['id'];
$oldActivityValues['contactID'] = $oldActivityValues['source_contact_id'];
require_once 'CRM/Activity/Page/AJAX.php';
$copyToCase = CRM_Activity_Page_AJAX::_convertToCaseActivity($oldActivityValues);
if (empty($copyToCase['error_msg'])) {
// now fix some things that are different from copy-to-case
// then fall through to the create below to update with the passed in params
$params['id'] = $copyToCase['newId'];
$params['is_auto'] = 0;
$params['original_id'] = empty($oldActivityValues['original_id']) ? $oldActivityValues['id'] : $oldActivityValues['original_id'];
} else {
return civicrm_api3_create_error(ts("Unable to create new revision of case activity."), NULL, CRM_Core_DAO::$_nullObject);
}
}
// create activity
$activityBAO = CRM_Activity_BAO_Activity::create($params);
if (isset($activityBAO->id)) {
if ($case_id && !$createRevision) {
// If this is a brand new case activity we need to add this
$caseActivityParams = array('activity_id' => $activityBAO->id, 'case_id' => $case_id);
require_once 'CRM/Case/BAO/Case.php';
//.........這裏部分代碼省略.........
示例14: 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;
}
示例15: 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;
}