CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Using hook_civicrm_mailingGroups
Pages: [1]

Author Topic: Using hook_civicrm_mailingGroups  (Read 663 times)

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Using hook_civicrm_mailingGroups
February 10, 2011, 07:06:09 am
hi guys,

I have a simple use case where I needed to exclude a group every time a bulk mailing goes out so I was looking at

hook_civicrm_mailingGroups(&$form, &$groups, &$mailings)

THe problem is it seems that the $groups is just an associate array of All of the groups in civi in the format of group_id => group name, it is not providing me with the groups that was included/excluded for the mailing I was testing with.

I was expecting something more like

Code: [Select]
$groups = array(
     'include' => array(3, 5, 7),
     'exclude' => array(2),
)


Any help would be appreciated,



Cheers!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using hook_civicrm_mailingGroups
February 10, 2011, 07:15:25 am

hey chang:

this hook is called when the include/exclude list of groups/mailings is displayed. i.e. this is the list of groups SHOWN to the user, and then the user selects.

how do u know its a bulk mailing?  can u just remove that group from the above list

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Re: Using hook_civicrm_mailingGroups
February 10, 2011, 07:21:11 am
Thanks lobo,

Do you think hook_civicrm_alterMailParams will be better suited for my use case?

I'm afraid of using that hook because

1. I don't know if it contains the group information for the mailing
2. By the time this hook is fired the # emails for the mailing has already been calculated.


Thanks,


Chang

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using hook_civicrm_mailingGroups
February 10, 2011, 09:38:40 am

hey chang:

i dont think alterMailParams is a good spot

if we think of:

hook_civicrm_mailingGroups(&$form, &$groups, &$mailings)

as the pre hook (i.e. before the groups are selected)

we can potentially also invoke it, after the groups are selected. To avoid hook proliferation, we could potentially change the signature to:

hook_civicrm_mailingGroups(&$form, &$groups, &$mailings, $type = 'pre' )

and invoke the same function after

the format of the arrays change when $type = 'post' and they are more of how u expect them

$groups = array( 'include' => array( .. ), 'exclude' => array( ... ) );

wanna submit a patch for 3.4? update the docs etc

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Re: Using hook_civicrm_mailingGroups
February 15, 2011, 02:42:23 pm
That sounds good Lobo,

what's possible currently without the hook and without hacking the core.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Using hook_civicrm_mailingGroups

This forum was archived on 2017-11-26.