return $from;
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('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);
+
switch ($name) {
case self::CIVICRM_ACTIVITY_TARGET:
$from = " INNER JOIN civicrm_activity_contact civicrm_activity_target
- ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type = 'Target') ";
+ ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = $targetID) ";
break;
case self::CIVICRM_ACTIVITY:
case self::CIVICRM_ACTIVITY_ASSIGNMENT:
$from = "
INNER JOIN civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
-civicrm_activity_assignment.record_type = 'Assignee' ) ";
+civicrm_activity_assignment.record_type_id = $assigneeID ) ";
break;
case 'civicrm_survey':
}
$targetContactIds = ' ( ' . implode(',', $voterIds) . ' ) ';
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$query = "
SELECT activity.id, activity.status_id,
activityTarget.contact_id as voter_id,
activityAssignment.contact_id as interviewer_id
FROM civicrm_activity activity
INNER JOIN civicrm_activity_contact activityTarget
- ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type = 'Target')
+ ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type_id = $targetID )
INNER JOIN civicrm_activity_contact activityAssignment
- ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type = 'Assignee')
+ ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type_id = $assigneeID )
WHERE activity.source_record_id = %1
AND ( activity.is_deleted IS NULL OR activity.is_deleted = 0 )
AND activityAssignment.contact_id = %2
contact_a.display_name as voter_name";
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$query = "
$select
FROM civicrm_activity activity
INNER JOIN civicrm_activity_contact activityTarget
- ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type = 'Target')
+ ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type_id = $targetID )
INNER JOIN civicrm_activity_contact activityAssignment
- ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type = 'Assignee')
+ ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type_id = $assigneeID )
INNER JOIN civicrm_contact contact_a ON ( activityTarget.contact_id = contact_a.id )
WHERE activity.source_record_id = %1
AND activity.activity_type_id = %2
}
$interviewers = array();
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$query = "
SELECT contact.id as id,
contact.sort_name as sort_name
FROM civicrm_contact contact
-INNER JOIN civicrm_activity_contact assignment ON ( assignment.contact_id = contact.id AND record_type = 'Assignee' )
+INNER JOIN civicrm_activity_contact assignment ON ( assignment.contact_id = contact.id AND record_type_id = $assigneeID )
INNER JOIN civicrm_activity activity ON ( activity.id = assignment.activity_id )
INNER JOIN civicrm_survey survey ON ( activity.source_record_id = survey.id )
{$whereClause}";
static function getCaseActivity($caseID, &$params, $contactID, $context = NULL, $userID = NULL, $type = NULL) {
$values = array();
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+
// CRM-5081 - formatting the dates to omit seconds.
// Note the 00 in the date format string is needed otherwise later on it thinks scheduled ones are overdue.
$select = "SELECT count(ca.id) as ismultiple, ca.id as id,
LEFT OUTER JOIN civicrm_option_group og ON og.name="activity_status"
LEFT OUTER JOIN civicrm_option_value ov ON ov.option_group_id=og.id AND ov.name="Scheduled"
LEFT JOIN civicrm_activity_contact caa
- ON caa.activity_id = ca.id AND caa.record_type = "Assignee"
+ ON caa.activity_id = ca.id AND caa.record_type_id = $assigneeID
LEFT JOIN civicrm_contact acc ON acc.id = caa.contact_id ';
$where = 'WHERE cca.case_id= %1
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
$activityStatuses = CRM_Core_PseudoConstant::activityStatus('name');
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('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
$processCaseIds = array($otherCaseId);
if ($duplicateContacts && !$duplicateCases) {
if ($changeClient) {
//migrate target activities.
$otherTargetActivity = new CRM_Activity_DAO_ActivityContact();
$otherTargetActivity->activity_id = $otherActivityId;
- $otherTargetActivity->record_type = 'Target';
+ $otherTargetActivity->record_type_id = $targetID;
$otherTargetActivity->find();
while ($otherTargetActivity->fetch()) {
$mainActivityTarget = new CRM_Activity_DAO_ActivityContact();
- $mainActivityTarget->record_type = 'Target';
+ $mainActivityTarget->record_type_id = $targetID;
$mainActivityTarget->activity_id = $mainActivityId;
$mainActivityTarget->contact_id = $otherTargetActivity->contact_id;
if ($mainActivityTarget->contact_id == $otherContactId) {
//migrate assignee activities.
$otherAssigneeActivity = new CRM_Activity_DAO_ActivityContact();
$otherAssigneeActivity->activity_id = $otherActivityId;
- $otherAssigneeActivity->record_type = 'Assignee';
+ $otherAssigneeActivity->record_type_id = $assigneeID;
$otherAssigneeActivity->find();
while ($otherAssigneeActivity->fetch()) {
$mainAssigneeActivity = new CRM_Activity_DAO_ActivityContact();
$mainAssigneeActivity->activity_id = $mainActivityId;
- $mainAssigneeActivity->record_type = 'Assignee';
+ $mainAssigneeActivity->record_type_id = $assigneeID;
$mainAssigneeActivity->contact_id = $otherAssigneeActivity->contact_id;
if ($mainAssigneeActivity->contact_id == $otherContactId) {
$mainAssigneeActivity->contact_id = $mainContactId;
$isTarget = $isAssignee = $isSource = FALSE;
$target = new CRM_Activity_DAO_ActivityContact();
- $target->record_type = 'Target';
+ $target->record_type_id = $targetID;
$target->activity_id = $activityId;
$target->contact_id = $contactId;
if ($target->find(TRUE)) {
$assignee = new CRM_Activity_DAO_ActivityContact();
$assignee->activity_id = $activityId;
- $assignee->record_type = 'Assignee';
+ $assignee->record_type_id = $assigneeID;
$assignee->contact_id = $contactId;
if ($assignee->find(TRUE)) {
$isAssignee = TRUE;
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
// create activity assignee records
$assigneeParams = array(
'activity_id' => $activity->id,
- 'record_type' => 'Assignee'
+ 'record_type_id' => $assigneeID
);
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
}
function deleteEmptyActivity(&$params) {
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$query = "
DELETE a
FROM civicrm_activity a
INNER JOIN civicrm_activity_contact t ON t.activity_id = a.id
WHERE t.contact_id = %1
-AND t.record_type = 'Target'
+AND t.record_type_id = $targetID
AND a.is_auto = 1
AND a.is_current_revision = 1
";
$joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+
$query = "
SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
{$selectCaseActivity}
FROM civicrm_activity a
{$joinCaseActivity}
-LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type = 'Target'
-LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type = 'Assignee'
+LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
+LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
WHERE a.id = %1
";
$params = array(1 => array($activityID, 'Integer'));
// search tag in activities
$etActTable = "`civicrm_entity_act_tag-" . $value . "`";
$tActTable = "`civicrm_act_tag-" . $value . "`";
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$this->_tables[$etActTable] =
$this->_whereTables[$etActTable] =
" LEFT JOIN civicrm_activity_contact
- ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type = 'Target' )
+ ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type_id = {$targetID} )
LEFT JOIN civicrm_activity
ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )
// search tag in cases
$etCaseTable = "`civicrm_entity_case_tag-" . $value . "`";
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$this->_tables[$etCaseTable] =
$this->_whereTables[$etCaseTable] =
" LEFT JOIN civicrm_case_contact ON civicrm_case_contact.contact_id = contact_a.id
$this->_tables[$etActTable] =
$this->_whereTables[$etActTable] =
" LEFT JOIN civicrm_activity_contact
- ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type = 'Target' )
+ ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type_id = {$targetID} )
LEFT JOIN civicrm_activity
ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )
// Regular JOIN statements here to limit results to contacts who have activities.
function from() {
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
return "
civicrm_contact contact_a
JOIN civicrm_activity activity
LEFT JOIN civicrm_case_activity cca
ON activity.id = cca.activity_id
LEFT JOIN civicrm_activity_contact assignment
- ON activity.id = assignment.activity_id AND assignment.record_type = 'Assignee'
+ ON activity.id = assignment.activity_id AND assignment.record_type_id = {$assigneeID}
LEFT JOIN civicrm_contact contact_c
ON assignment.contact_id = contact_c.id ";
}
}
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
foreach ($form->_contactIds as $contactId) {
$activityTargetParams = array(
'activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id,
'contact_id' => $contactId,
- 'record_type' => 'Target'
+ 'record_type_id' => $targetID
);
CRM_Activity_BAO_ActivityContact::create($activityTargetParams);
}
if ($mapping->entity == 'civicrm_activity') {
$contactField = 'r.contact_id';
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('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);
+
switch (CRM_Utils_Array::value($actionSchedule->recipient, $recipientOptions)) {
case 'Activity Assignees':
- $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Assignee'";
+ $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$assigneeID}";
break;
case 'Activity Source':
- $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Source'";
+ $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$sourceID}";
break;
default:
case 'Activity Targets':
- $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Target'";
+ $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$targetID}";
break;
}
//activity creation
$activity = CRM_Activity_BAO_Activity::create($activityParams);
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
//friend contacts creation
foreach ($contactParams as $key => $value) {
$targetParams = array(
'activity_id' => $activity->id,
'contact_id' => $contact,
- 'record_type' => 'Target'
+ 'record_type_id' => $targetID
);
// See if it already exists
$contactIdClause = "AND (contact_id_a = %3 OR contact_id_b = %3)";
break;
case 'civicrm_activity':
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('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);
+
$join = "
-LEFT JOIN civicrm_activity_contact at ON at.activity_id = lt.id AND at.contact_id = %3 AND at.record_type = 'Target'
-LEFT JOIN civicrm_activity_contact aa ON aa.activity_id = lt.id AND aa.contact_id = %3 AND aa.record_type = 'Assignee'
-LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND source.contact_id = %3 AND source.record_type = 'Source' ";
+LEFT JOIN civicrm_activity_contact at ON at.activity_id = lt.id AND at.contact_id = %3 AND at.record_type_id = {$targetID}
+LEFT JOIN civicrm_activity_contact aa ON aa.activity_id = lt.id AND aa.contact_id = %3 AND aa.record_type_id = {$assigneeID}
+LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND source.contact_id = %3 AND source.record_type_id = {$sourceID} ";
$contactIdClause = "AND (at.id IS NOT NULL OR aa.id IS NOT NULL OR source.id IS NOT NULL)";
break;
case 'civicrm_case':
}
function from() {
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$this->_from = "
FROM civicrm_activity {$this->_aliases['civicrm_activity']}
LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_target']}
ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_target']}.activity_id AND
- {$this->_aliases['civicrm_activity_target']}.record_type = 'Target'
+ {$this->_aliases['civicrm_activity_target']}.record_type_id = {$targetID}
LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_assignment']}
ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_assignment']}.activity_id AND
- {$this->_aliases['civicrm_activity_assignment']}.record_type = 'Assignee'
+ {$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID}
LEFT JOIN civicrm_contact civicrm_contact_source
ON {$this->_aliases['civicrm_activity']}.source_contact_id = civicrm_contact_source.id
LEFT JOIN civicrm_contact contact_civireport
function from() {
$this->_from = " FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} ";
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
//get the activity table joins.
- $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_target ON ( {$this->_aliases['civicrm_contact']}.id = civicrm_activity_target.contact_id AND civicrm_activity_target.record_type = 'Target') \n";
- $this->_from .= " INNER JOIN civicrm_activity {$this->_aliases['civicrm_activity']} ON ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id )\n";
- $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_assignment ON ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type = 'Assignee' )\n";
+ $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_target ON
+ ( {$this->_aliases['civicrm_contact']}.id = civicrm_activity_target.contact_id AND civicrm_activity_target.record_type_id = {$targetID}) \n";
+ $this->_from .= " INNER JOIN civicrm_activity {$this->_aliases['civicrm_activity']} ON
+ ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id )\n";
+ $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_assignment ON
+ ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID} )\n";
//get the address table.
- $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
+ $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON
+ {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
if ($this->_emailField) {
- $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
+ $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON
+ {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
}
if ($this->_phoneField) {
- $this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
+ $this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON
+ {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
}
if($this->_locationBasedPhoneField){
}
if (CRM_Utils_Array::value('activity_civireport', $this->_selectComponent)) {
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$this->_formComponent['activity_civireport'] = "FROM
civicrm_activity {$this->_aliases['civicrm_activity']}
LEFT JOIN civicrm_activity_contact civicrm_activity_target ON
{$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
- civicrm_activity_target.record_type = 'Target'
+ civicrm_activity_target.record_type_id = {$targetID}
LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
- {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type = 'Assignee'
+ {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID}
LEFT JOIN civicrm_contact sourceContact ON
{$this->_aliases['civicrm_activity']}.source_contact_id = sourceContact.id
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
function activity(&$contactIDs, &$additionalContacts) {
static $_activitiesHandled = array();
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$ids = implode(',', $contactIDs);
$sql = "(
SELECT a.*
FROM civicrm_activity a
- INNER JOIN civicrm_activity_contact aa ON aa.activity_id = a.id AND aa.record_type = 'Assignee'
+ INNER JOIN civicrm_activity_contact aa ON aa.activity_id = a.id AND aa.record_type_id = $assigneeID
WHERE aa.contact_id IN ( $ids )
AND ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
) UNION (
SELECT a.*
FROM civicrm_activity a
- INNER JOIN civicrm_activity_contact at ON at.activity_id = a.id AND at.record_type = 'Target'
+ INNER JOIN civicrm_activity_contact at ON at.activity_id = a.id AND at.record_type_id = $targetID
WHERE at.contact_id IN ( $ids )
AND ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
)