本文整理汇总了PHP中CRM_Case_BAO_Case::getCaseIdByActivityId方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Case_BAO_Case::getCaseIdByActivityId方法的具体用法?PHP CRM_Case_BAO_Case::getCaseIdByActivityId怎么用?PHP CRM_Case_BAO_Case::getCaseIdByActivityId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Case_BAO_Case
的用法示例。
在下文中一共展示了CRM_Case_BAO_Case::getCaseIdByActivityId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Process the activities.
*
* @param array $params
* Associated array of the submitted values.
*
* @throws CRM_Core_Exception
*
* @return CRM_Activity_BAO_Activity|null|object
*/
public static function create(&$params)
{
// check required params
if (!self::dataExists($params)) {
throw new CRM_Core_Exception('Not enough data to create activity object');
}
$activity = new CRM_Activity_DAO_Activity();
if (isset($params['id']) && empty($params['id'])) {
unset($params['id']);
}
if (empty($params['status_id']) && empty($params['activity_status_id']) && empty($params['id'])) {
if (isset($params['activity_date_time']) && strcmp($params['activity_date_time'], CRM_Utils_Date::processDate(date('Ymd')) == -1)) {
$params['status_id'] = 2;
} else {
$params['status_id'] = 1;
}
}
// Set priority to Normal for Auto-populated activities (for Cases)
if (CRM_Utils_Array::value('priority_id', $params) === NULL && !CRM_Utils_Array::value('id', $params)) {
$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
$params['priority_id'] = array_search('Normal', $priority);
}
if (!empty($params['target_contact_id']) && is_array($params['target_contact_id'])) {
$params['target_contact_id'] = array_unique($params['target_contact_id']);
}
if (!empty($params['assignee_contact_id']) && is_array($params['assignee_contact_id'])) {
$params['assignee_contact_id'] = array_unique($params['assignee_contact_id']);
}
// CRM-9137
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Activity', $activity->id, $params);
} else {
CRM_Utils_Hook::pre('create', 'Activity', NULL, $params);
}
$activity->copyValues($params);
if (isset($params['case_id'])) {
// CRM-8708, preserve case ID even though it's not part of the SQL model
$activity->case_id = $params['case_id'];
} elseif (is_numeric($activity->id)) {
// CRM-8708, preserve case ID even though it's not part of the SQL model
$activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id);
}
// start transaction
$transaction = new CRM_Core_Transaction();
$result = $activity->save();
if (is_a($result, 'CRM_Core_Error')) {
$transaction->rollback();
return $result;
}
$activityId = $activity->id;
$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);
if (isset($params['source_contact_id'])) {
$acParams = array('activity_id' => $activityId, 'contact_id' => $params['source_contact_id'], 'record_type_id' => $sourceID);
self::deleteActivityContact($activityId, $sourceID);
CRM_Activity_BAO_ActivityContact::create($acParams);
}
// check and attach and files as needed
CRM_Core_BAO_File::processAttachment($params, 'civicrm_activity', $activityId);
// attempt to save activity assignment
$resultAssignment = NULL;
if (!empty($params['assignee_contact_id'])) {
$assignmentParams = array('activity_id' => $activityId);
if (is_array($params['assignee_contact_id'])) {
if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) {
// first delete existing assignments if any
self::deleteActivityContact($activityId, $assigneeID);
}
$values = array();
foreach ($params['assignee_contact_id'] as $acID) {
if ($acID) {
$values[] = "( {$activityId}, {$acID}, {$assigneeID} )";
}
}
while (!empty($values)) {
$input = array_splice($values, 0, CRM_Core_DAO::BULK_INSERT_COUNT);
$str = implode(',', $input);
$sql = "INSERT IGNORE INTO civicrm_activity_contact ( activity_id, contact_id, record_type_id ) VALUES {$str};";
CRM_Core_DAO::executeQuery($sql);
}
} else {
$assignmentParams['contact_id'] = $params['assignee_contact_id'];
$assignmentParams['record_type_id'] = $assigneeID;
if (!empty($params['id'])) {
$assignment = new CRM_Activity_BAO_ActivityContact();
$assignment->activity_id = $activityId;
$assignment->record_type_id = $assigneeID;
$assignment->find(TRUE);
//.........这里部分代码省略.........
示例2: civicrm_api3_case_get
/**
* Get details of a particular case, or search for cases, depending on params
*
* Please provide one (and only one) of the four get/search parameters:
*
* @param array(
'id' => if set, will get all available info about a case, including contacts and activities
*
* // if no case_id provided, this function will use one of the following search parameters:
* 'client_id' => finds all cases with a specific client
* 'activity_id' => returns the case containing a specific activity
* 'contact_id' => finds all cases associated with a contact (in any role, not just client)
*
* {@getfields case_get}
*
* @return (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found
* @access public
* @todo Erik Hommel 16 dec 2010 check if all DB fields are returned
*/
function civicrm_api3_case_get($params)
{
$options = _civicrm_api3_get_options_from_params($params);
//search by client
if (!empty($params['contact_id'])) {
$ids = array();
foreach ((array) $params['contact_id'] as $cid) {
if (is_numeric($cid)) {
$ids = array_merge($ids, CRM_Case_BAO_Case::retrieveCaseIdsByContactId($cid, TRUE));
}
}
$cases = array();
foreach ($ids as $id) {
if ($case = _civicrm_api3_case_read($id, $options)) {
$cases[$id] = $case;
}
}
return civicrm_api3_create_success($cases, $params, 'case', 'get');
}
//search by activity
if (!empty($params['activity_id'])) {
if (!is_numeric($params['activity_id'])) {
return civicrm_api3_create_error('Invalid parameter: activity_id. Must provide a numeric value.');
}
$caseId = CRM_Case_BAO_Case::getCaseIdByActivityId($params['activity_id']);
if (!$caseId) {
return civicrm_api3_create_success(array(), $params, 'case', 'get');
}
$case = array($caseId => _civicrm_api3_case_read($caseId, $options));
return civicrm_api3_create_success($case, $params, 'case', 'get');
}
//search by contacts
if ($contact = CRM_Utils_Array::value('contact_id', $params)) {
if (!is_numeric($contact)) {
return civicrm_api3_create_error('Invalid parameter: contact_id. Must provide a numeric value.');
}
$sql = "\nSELECT DISTINCT case_id\n FROM civicrm_relationship\n WHERE (contact_id_a = {$contact}\n OR contact_id_b = {$contact})\n AND case_id IS NOT NULL";
$dao =& CRM_Core_DAO::executeQuery($sql);
$cases = array();
while ($dao->fetch()) {
$cases[$dao->case_id] = _civicrm_api3_case_read($dao->case_id, $options);
}
return civicrm_api3_create_success($cases, $params, 'case', 'get');
}
// For historic reasons we always return these when an id is provided
$caseId = CRM_Utils_Array::value('id', $params);
if ($caseId) {
$options['return'] = array('contacts' => 1, 'activities' => 1);
}
$foundcases = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Case');
$cases = array();
foreach ($foundcases['values'] as $foundcase) {
if ($case = _civicrm_api3_case_read($foundcase['id'], $options)) {
$cases[$foundcase['id']] = $case;
}
}
return civicrm_api3_create_success($cases, $params, 'case', 'get');
}
示例3: civicrm_api3_case_get
/**
* Get details of a particular case, or search for cases, depending on params
*
* Please provide one (and only one) of the four get/search parameters:
*
* @param array(
'case_id' => if set, will get all available info about a case, including contacts and activities
*
* // if no case_id provided, this function will use one of the following search parameters:
* 'client_id' => finds all cases with a specific client
* 'activity_id' => returns the case containing a specific activity
* 'contact_id' => finds all cases associated with a contact (in any role, not just client)
*
* {@getfields case_get}
*
* @return (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found
* @access public
* @todo Eileen McNaughton 13 Oct 2011 No unit test
* @todo Erik Hommel 16 dec 2010 check if all DB fields are returned
*/
function civicrm_api3_case_get($params)
{
// Get mode
if (!($caseId = CRM_Utils_Array::value('id', $params))) {
$caseId = CRM_Utils_Array::value('case_id', $params);
}
if ($caseId) {
// Validate param
if (!is_numeric($caseId)) {
return civicrm_api3_create_error('Invalid parameter: case_id. Must provide a numeric value.');
}
$case = _civicrm_api3_case_read($caseId);
if ($case) {
//get case contacts
$contacts = CRM_Case_BAO_Case::getcontactNames($caseId);
$relations = CRM_Case_BAO_Case::getRelatedContacts($caseId);
$case['contacts'] = array_merge($contacts, $relations);
//get case activities
$query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = {$caseId}";
$dao = CRM_Core_DAO::executeQuery($query);
$case['activities'] = array();
while ($dao->fetch()) {
$case['activities'][] = $dao->activity_id;
}
$cases = array($caseId => $case);
return civicrm_api3_create_success($cases);
} else {
return civicrm_api3_create_success(array());
}
}
//search by client
if ($client = CRM_Utils_Array::value('client_id', $params)) {
$ids = array();
foreach ((array) $client as $cid) {
if (is_numeric($cid)) {
$ids = array_merge($ids, CRM_Case_BAO_Case::retrieveCaseIdsByContactId($cid, TRUE));
}
}
if (empty($ids)) {
return civicrm_api3_create_success(array());
}
$cases = array();
foreach ($ids as $id) {
$cases[$id] = _civicrm_api3_case_read($id);
}
return civicrm_api3_create_success($cases);
}
//search by activity
if ($act = CRM_Utils_Array::value('activity_id', $params)) {
if (!is_numeric($act)) {
return civicrm_api3_create_error('Invalid parameter: activity_id. Must provide a numeric value.');
}
$caseId = CRM_Case_BAO_Case::getCaseIdByActivityId($act);
if (!$caseId) {
return civicrm_api3_create_success(array());
}
$case = array($caseId => _civicrm_api3_case_read($caseId));
return civicrm_api3_create_success($case);
}
//search by contacts
if ($contact = CRM_Utils_Array::value('contact_id', $params)) {
if (!is_numeric($contact)) {
return civicrm_api3_create_error('Invalid parameter: contact_id. Must provide a numeric value.');
}
$sql = "\nSELECT DISTINCT case_id\n FROM civicrm_relationship\n WHERE (contact_id_a = {$contact}\n OR contact_id_b = {$contact})\n AND case_id IS NOT NULL";
$dao =& CRM_Core_DAO::executeQuery($sql);
$cases = array();
while ($dao->fetch()) {
$cases[$dao->case_id] = _civicrm_api3_case_read($dao->case_id);
}
return civicrm_api3_create_success($cases);
}
return civicrm_api3_create_error('Missing required parameter. Must provide case_id, client_id, activity_id, or contact_id.');
}