);
if ($isSMSmode) {
-
$criteria = array(
'is_opt_out' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_opt_out = 0"),
'is_deceased' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_deceased <> 1"),
'location_filter' => CRM_Utils_SQL_Select::fragment()->where($location_filter),
'email_not_null' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.email IS NOT NULL"),
'email_not_empty' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.email != ''"),
+ 'email_not_on_hold' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.on_hold = 0"),
'mailing_id' => CRM_Utils_SQL_Select::fragment()->where("mg.mailing_id = #mailingID"),
'temp_contact_null' => CRM_Utils_SQL_Select::fragment()->where('temp.contact_id IS NULL'),
'order_by' => CRM_Utils_SQL_Select::fragment()->orderBy($order_by),
*/
public function testAlterMailingRecipientsHook() {
$groupID = $this->groupCreate();
+ $this->tagCreate(array('name' => 'Tagged'));
// Create deseased Contact 1 and add in group
$contactID1 = $this->individualCreate(array('email' => 'abc@test.com', 'is_deceased' => 1), 0);
// Create deseased Contact 2 and add in group
$contactID2 = $this->individualCreate(array('email' => 'def@test.com'), 1);
+ // Create deseased Contact 3 and add in group
+ $contactID3 = $this->individualCreate(array('email' => 'ghi@test.com', 'is_deceased' => 1), 2);
+
// Add both the created contacts in group
$this->callAPISuccess('GroupContact', 'Create', array(
'group_id' => $groupID,
'group_id' => $groupID,
'contact_id' => $contactID2,
));
+ $this->callAPISuccess('GroupContact', 'Create', array(
+ 'group_id' => $groupID,
+ 'contact_id' => $contactID3,
+ ));
+ $this->entityTagAdd(array('contact_id' => $contactID3, 'tag_id' => 'Tagged'));
+
// trigger the alterMailingRecipients hook
$this->hookClass->setHook('civicrm_alterMailingRecipients', array($this, 'alterMailingRecipients'));
* @implements CRM_Utils_Hook::alterMailingRecipients
*
* @param object $mailingObject
- * @param array $params
+ * @param array $criteria
* @param string $context
*/
- public function alterMailingRecipients(&$mailingObject, &$params, $context) {
+ public function alterMailingRecipients(&$mailingObject, &$criteria, $context) {
if ($context == 'pre') {
- // modify the filter to include only deceased recipient(s)
- $params['filters']['is_deceased'] = 'civicrm_contact.is_deceased = 1';
+ // modify the filter to include only deceased recipient(s) that is Tagged
+ $criteria['is_deceased'] = CRM_Utils_SQL_Select::fragment()->where("civicrm_contact.is_deceased = 1");
+ $criteria['tagged_contact'] = CRM_Utils_SQL_Select::fragment()
+ ->join('civicrm_entity_tag', "INNER JOIN civicrm_entity_tag et ON et.entity_id = civicrm_contact.id AND et.entity_table = 'civicrm_contact'")
+ ->join('civicrm_tag', "INNER JOIN civicrm_tag t ON t.id = et.tag_id")
+ ->where("t.name = 'Tagged'");
}
else {
$mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', array(
),
));
$this->assertEquals(1, $mailingRecipients['count'], 'Check recipient count');
- $this->assertEquals('abc@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact');
+ $this->assertEquals('ghi@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact');
}
}