From: Donald A. Lobo Date: Thu, 4 Apr 2013 05:28:35 +0000 (-0700) Subject: first set of patches for activity restructuring X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f04255e449e59c2984599ecbf418693b1dc87e9e;p=civicrm-core.git first set of patches for activity restructuring --- diff --git a/CRM/Activity/BAO/ActivityContact.php b/CRM/Activity/BAO/ActivityContact.php index ec9bc9200f..0b8694e9f6 100644 --- a/CRM/Activity/BAO/ActivityContact.php +++ b/CRM/Activity/BAO/ActivityContact.php @@ -61,4 +61,46 @@ class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact $activityContact->copyValues($params); return $activityContact->save(); } + + /** + * function to retrieve names of contact by activity_id + * + * @param int $id ID of the activity + * @param string $type type of interaction + * + * @return array + * + * @access public + * + */ + static function getNames($activityID, $recordType, $alsoIDs = FALSE) { + $names = array(); + $ids = array(); + + if (empty($activityID)) { + return $alsoIDs ? array($names, $ids) : $names; + } + + $query = " +SELECT contact_a.id, contact_a.sort_name +FROM civicrm_contact contact_a +INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id +WHERE civicrm_activity_contact.activity_id = %1 +AND civicrm_activity_contact.record_type = %2 +AND contact_a.is_deleted = 0 +"; + $params = array( + 1 => array($activityID, 'Integer'), + 2 => array($recordType, 'String') + ); + + $dao = CRM_Core_DAO::executeQuery($query, $params); + while ($dao->fetch()) { + $names[$dao->id] = $dao->sort_name; + $ids[] = $dao->id; + } + + return $alsoIDs ? array($names, $ids) : $names; + } + } diff --git a/CRM/Activity/Selector/Search.php b/CRM/Activity/Selector/Search.php index 353c3bf26c..463de81925 100644 --- a/CRM/Activity/Selector/Search.php +++ b/CRM/Activity/Selector/Search.php @@ -73,9 +73,7 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM 'activity_status_id', 'activity_status', 'activity_subject', - 'source_contact_id', 'source_record_id', - 'source_contact_name', 'activity_type_id', 'activity_type', 'activity_is_test', @@ -236,7 +234,8 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { - $result = $this->_query->searchQuery($offset, $rowCount, $sort, + $result = $this->_query->searchQuery( + $offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, @@ -271,12 +270,12 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM $contactId = CRM_Utils_Array::value('source_contact_id', $row); } - $row['target_contact_name'] = CRM_Activity_BAO_ActivityTarget::getTargetNames($row['activity_id']); - $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($row['activity_id']); + $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], 'Target'); + $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], 'Assignee'); + list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], 'Source', TRUE); + $row['source_contact_name'] = implode(',', array_values($row['source_contact_name'])); + $row['source_contact_id'] = implode(',', $row['source_contact_id']); - if (CRM_Utils_Array::value('source_contact_id', $row)) { - $row['source_contact_name'] = CRM_Contact_BAO_Contact::displayName($row['source_contact_id']); - } if ($this->_context == 'search') { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id; }