Skip to content

Commit

Permalink
[#4] Adjust API calls for changes in de.systopia.newsletter
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed Nov 11, 2020
1 parent 53fddf3 commit bb55d2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 29 additions & 2 deletions civicrm_newsletter.cmrf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ function _civicrm_newsletter_send_call($entity, $action, $parameters = array(),
* The Advanced Newsletter Management profile configuration, or NULL if the
* profile could not be retrieved.
*/
function _civicrm_newsletter_profile_get($profile_name = NULL) {
function _civicrm_newsletter_profile_getsingle($profile_name = NULL) {
$params = array();
if ($profile_name) {
$params['name'] = $profile_name;
}
$call = _civicrm_newsletter_send_call(
'NewsletterProfile',
'get',
'getsingle',
$params,
array(),
_civicrm_newsletter_get_cmrf_profile()
Expand All @@ -96,6 +96,33 @@ function _civicrm_newsletter_profile_get($profile_name = NULL) {
return $return;
}

/**
* Retrieves the configuration for all Advanced Newsletter Management profiles
* from CiviCRM.
*
* @return array
* An array of Advanced Newsletter Management profile configurations.
*/
function _civicrm_newsletter_profile_get() {
$params = array();
$call = _civicrm_newsletter_send_call(
'NewsletterProfile',
'get',
$params,
array(),
_civicrm_newsletter_get_cmrf_profile()
);
$reply = $call->getReply();
if ($reply['is_error'] == 1) {
$return = NULL;
}
else {
$return = $reply['values'];
}

return $return;
}

/**
* Retrieves the subscription status for a given contact hash.
*
Expand Down
6 changes: 3 additions & 3 deletions civicrm_newsletter.module
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function _civicrm_newsletter_subscription_form($form, &$form_state, $profile_nam

// Retrieve CiviCRM Advanced Newsletter Management extension configuration for
// given profile.
if (!$profile = _civicrm_newsletter_profile_get($profile_name)) {
if (!$profile = _civicrm_newsletter_profile_getsingle($profile_name)) {
drupal_not_found();
}
else {
Expand Down Expand Up @@ -242,7 +242,7 @@ function _civicrm_newsletter_preferences_form($form, &$form_state, $profile_name

// Retrieve CiviCRM Advanced Newsletter Management extension configuration for
// given profile.
if (!$profile = _civicrm_newsletter_profile_get($profile_name)) {
if (!$profile = _civicrm_newsletter_profile_getsingle($profile_name)) {
drupal_not_found();
}
else {
Expand Down Expand Up @@ -412,7 +412,7 @@ function _civicrm_newsletter_request_form($form, &$form_state, $profile_name, $c

// Retrieve CiviCRM Advanced Newsletter Management extension configuration for
// given profile.
if (!$profile = _civicrm_newsletter_profile_get($profile_name)) {
if (!$profile = _civicrm_newsletter_profile_getsingle($profile_name)) {
drupal_not_found();
}
else {
Expand Down

0 comments on commit bb55d2d

Please sign in to comment.