$activity->copyValues($params);
if ($activity->find(TRUE)) {
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+
// TODO: at some stage we'll have to deal
// TODO: with multiple values for assignees and targets, but
// TODO: for now, let's just fetch first row
- $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id);
- $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
-
+ $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
+ $assignee_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID);
$defaults['assignee_contact_value'] = implode('; ', $assignee_contact_names);
if ($activity->activity_type_id != CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name')) {
- $defaults['target_contact'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id);
- $target_contact_names = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
-
+ $defaults['target_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID);
+ $target_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID);
$defaults['target_contact_value'] = implode('; ', $target_contact_names);
}
elseif (CRM_Core_Permission::check('access CiviMail') ||
$defaults['target_contact_value'] = ts('(recipients)');
}
- $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
- $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$sourceContactId = self::getActivityContact($activity->id, $sourceID);
if ($sourceContactId &&
//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'
- );
+
+ $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);
+ $sourceContactId = self::getActivityContact($activity->id, $sourceID);
if ($sourceContactId) {
$msgs[] = " source={$sourceContactId}";
}
+
//get target contacts.
- $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
+ $targetContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID);
if (!empty($targetContactIds)) {
$msgs[] = " target =" . implode(',', array_keys($targetContactIds));
}
//get assignee contacts.
- $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
+ $assigneeContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID);
if (!empty($assigneeContactIds)) {
$msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds));
}
}
else {
$assignmentParams['assignee_contact_id'] = $params['assignee_contact_id'];
-
+ $assignmentParams['record_type_id'] = $assigneeID;
if (CRM_Utils_Array::value('id', $params)) {
$assignment = new CRM_Activity_BAO_ActivityAssignment();
$assignment->activity_id = $activityId;
+ $assignment->record_type_id = $assigneeID;
$assignment->find(TRUE);
if ($assignment->assignee_contact_id != $params['assignee_contact_id']) {
$assignmentParams['id'] = $assignment->id;
- $resultAssignment = CRM_Activity_BAO_ActivityAssignment::create($assignmentParams);
+ $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams);
}
}
else {
- $resultAssignment = CRM_Activity_BAO_ActivityAssignment::create($assignmentParams);
+ $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams);
}
}
}
}
else {
$targetParams['target_contact_id'] = $params['target_contact_id'];
-
+ $targetParams['record_type_id'] = $targetID;
if (CRM_Utils_Array::value('id', $params)) {
- $target = new CRM_Activity_BAO_ActivityTarget();
+ $target = new CRM_Activity_BAO_ActivityContact();
$target->activity_id = $activityId;
+ $target->record_type_id = $targetID;
$target->find(TRUE);
if ($target->target_contact_id != $params['target_contact_id']) {
$targetParams['id'] = $target->id;
- $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+ $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
}
}
else {
- $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+ $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
}
}
}
$permission = CRM_Core_Permission::EDIT;
}
+ $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);
+
//check for source contact.
if (!$componentId || $allow) {
- $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
- $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$sourceContactId = self::getActivityContact($activity->id, $sourceID);
$allow = CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission);
}
if (!$allow) {
$allow = TRUE;
//get the target contacts.
- $targetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id);
+ $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;
//get the assignee contacts.
if ($allow) {
- $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id);
+ $assigneeContacts = CRM_Activity_BAO_Contact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
foreach ($assigneeContacts as $cnt => $contactId) {
if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) {
$allow = FALSE;
return $alsoIDs ? array($names, $ids) : $names;
}
+ /**
+ * function to retrieve id of target contact by activity_id
+ *
+ * @param int $id ID of the activity
+ *
+ * @return mixed
+ *
+ * @access public
+ *
+ */
+ static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
+ $activityContact = array();
+ if (!CRM_Utils_Rule::positiveInteger($activityID) ||
+ !CRM_Utils_Rule::positiveInteger($recordTypeID)) {
+ return $activityContact;
+ }
+
+ $sql = " SELECT contact_id
+FROM civicrm_activity_contact
+INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
+WHERE activity_id = %1
+AND record_type_id = %2
+AND civicrm_contact.is_deleted = 0
+";
+ $params = array(
+ 1 => array($activityID, 'Integer'),
+ 2 => array($recordTypeID, 'Integer')
+ );
+
+ $dao = CRM_Core_DAO::executeQuery($sql, $params);
+ while ($dao->fetch()) {
+ $activityContact[] = $dao->contact_id;
+ }
+ return $activityContact;
+ }
+
}
*/
protected function processActivity(&$params) {
$activityAssigned = array();
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
// format assignee params
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
//skip those assignee contacts which are already assigned
//while sending a copy.CRM-4509.
$activityAssigned = array_flip($params['assignee_contact_id']);
if ($this->_activityId) {
- $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId);
+ $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID);
$activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
}
}
)
) {
$mailToContacts = array();
- $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+ //FIX ME : add more parameters to 'getNames' function
+ $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID, TRUE, FALSE);
//build an associative array with unique email addresses.
foreach ($activityAssigned as $id => $dnc) {
$this->controller->resetPage('Email');
$params = $this->exportValues();
$this->_contacts = array();
+
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
//get assignee contacts
if (!empty($params['assigned_to'])) {
foreach ($this->_activityHolderIds as $key => $id) {
- $ids = array_keys(CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($id));
+ $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $assigneeID));
$this->_contacts = array_merge($this->_contacts, $ids);
}
}
//get target contacts
if (!empty($params['with_contact'])) {
foreach ($this->_activityHolderIds as $key => $id) {
- $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id));
+ $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
$this->_contacts = array_merge($this->_contacts, $ids);
}
}
$activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $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.
$where .= " AND ca.is_deleted = 0";
}
-
if (CRM_Utils_Array::value('activity_type_id', $params)) {
$where .= " AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer');
}
$reporterName = '<a href="' . $contactViewUrl . $dao->reporter_id . '">' . $dao->reporter . '</a>';
}
$values[$dao->id]['reporter'] = $reporterName;
-
- $targetNames = CRM_Activity_BAO_ActivityTarget::getTargetNames($dao->id);
+ $targetNames = CRM_Activity_BAO_ActivityContact::getNames($dao->id, $targetID);
$targetContactUrls = $withContacts = array();
foreach ($targetNames as $targetId => $targetName) {
if (!in_array($targetId, $clientIds)) {
//while sending a copy.CRM-4509.
$activityAssigned = array_flip($params['assignee_contact_id']);
$activityId = isset($this->_activityId) ? $this->_activityId : $activity->id;
- $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId);
+ $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($activityId, $assigneeID);
$activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
foreach ($params['assignee_contact_id'] as $key => $id) {
//CRM-5695
//check for notification settings for assignee contacts
$selectedContacts = array('contact_check');
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'activity_assignee_notification'
)) {
$mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
}
else {
- $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+ $this->_relatedContacts = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID, TRUE, FALSE);
$mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
}
//build an associative array with unique email addresses.
//viewing activity should get diplayed in recent list.CRM-4670
$activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
- $activityTargetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityID);
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
if (!empty($activityTargetContacts)) {
$recentContactId = $activityTargetContacts[0];
}
);
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
if (!empty($activityDAO->targetID)) {
// Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
// Maybe not the best solution.
- $targetNames = CRM_Activity_BAO_ActivityTarget::getTargetNames($activityDAO->id);
+ $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID);
$processTarget = FALSE;
$label = ts('With Contact(s)');
if (in_array($activityTypeInfo['name'], array(
'value' => $this->redact($creator),
'type' => 'String',
);
-
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+ $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID);
$reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
- $activityDAO->source_contact_id,
+ $source_contact_id,
'display_name'
);
if (!empty($activityDAO->assigneeID)) {
//allow multiple assignee contacts.CRM-4503.
- $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, TRUE);
+ $assignee_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $assigneeID, TRUE);
foreach ($assignee_contact_names as & $assignee) {
// add Assignee to the strings to be redacted across the case session
continue;
}
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
//target contacts limit check
- $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id));
+ $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
if (count($ids) > 1) {
$extendTargetContacts++;
$activityContact->contact_id = $contact;
$activityContact->find(TRUE);
if (empty($activityContact->id)) {
- $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+ $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
}
}