From 9a2f601e9c9beca829932005e8cb51bc1e89f984 Mon Sep 17 00:00:00 2001 From: yashodha Date: Thu, 2 Jan 2014 15:46:39 +0530 Subject: [PATCH] CRM-13977 - fixed behavior for adding target contacts to groups --- CRM/Report/Form/Activity.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index 8e7b3a9086..dbb643ce86 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -540,6 +540,38 @@ class CRM_Report_Form_Activity extends CRM_Report_Form { $this->_aclWhere = NULL; } + function add2group($groupID) { + if (CRM_Utils_Array::value("contact_target_op", $this->_params) == 'nll') { + CRM_Core_Error::fatal(ts('Current filter criteria didn\'t have any target contact to add to group')); + } + + $query = "{$this->_select} +FROM civireport_activity_temp_target tar +GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy}"; + $select = 'AS addtogroup_contact_id'; + $query = str_ireplace('AS civicrm_contact_contact_target_id', $select, $query); + $dao = CRM_Core_DAO::executeQuery($query); + + $contactIDs = array(); + // Add resulting contacts to group + while ($dao->fetch()) { + if ($dao->addtogroup_contact_id) { + $contact_id = explode(';', $dao->addtogroup_contact_id); + if ($contact_id[0]) { + $contactIDs[] = $contact_id[0]; + } + } + } + + if ( !empty($contactIDs) ) { + CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIDs, $groupID); + CRM_Core_Session::setStatus(ts("Listed contact(s) have been added to the selected group."), ts('Contacts Added'), 'success'); + } + else { + CRM_Core_Session::setStatus(ts("The listed records(s) cannot be added to the group.")); + } + } + function postProcess() { $this->buildACLClause(array('civicrm_contact_source', 'civicrm_contact_target', 'civicrm_contact_assignee')); $this->beginPostProcess(); -- 2.25.1