Add capability of more then one list
ssherriff - October 9, 2008 - 11:35
| Project: | Campaign Monitor |
| Version: | 6.x-1.1 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | ssherriff |
| Status: | closed |
Description
I want to add the capability of being able to have more then one list. Multiple lists with multiple blocks, etc.

#1
that would be a useful feature
#2
I did a quick and dirty implementation of multiple lists. It handles them via a text area, allowing you to enter LISTKEY|list name|list description. It provides options for display the unsubscribe option, name field, and archive link. It only displays one email field with a list of radio buttons which controls the signup/unsubscribe. It provides an update to move the old API key into the new form.
Ultimately, it would better to build an admin form that was dynamic to add lists- probably the easiest way to do this is to track lists in a db table, but I just needed to get this done.
What this patch doesn't cover is the user page or the registration form. I think it would be trivial to port this over to those forms, but I haven't gotten that far yet.
#3
This is a slightly different version that replaces the radios with checkboxes if the unsubscribe options is off.
#4
Ok, here's a third go at things. I think this is a better approach
#5
I have a need for similar functionality, but what I have in mind if using the Campaign Monitor API to pull down the lists per client.
Maybe have an option on the CM admin page to either specify your lists, or "get all from this client"? ... or even better, something like a button on the admin form "fetch lists", and have the user check off the lists?
If anyone else would like to have this functionality, I'll be happy to code it up and submit a patch.
EDIT: On the second thought, maybe there should be two options on the CM admin form:
1. Use all lists for this client (in case the client adds lists, user will always see the latest on their account page)
2. Use specific lists for this client (display a list of checkboxes on the admin page)
#6
Is this against 6-1.1 or 2.1 or dev?
#7
I cant get patch at #4 to patch against either 1.1 or 2.1....
The below is against 1.1
patch < diff_14.txtpatching file campaignmonitor.module
Hunk #1 succeeded at 25 (offset 6 lines).
Hunk #3 succeeded at 52 (offset 6 lines).
Hunk #5 succeeded at 105 (offset 6 lines).
Hunk #6 succeeded at 115 with fuzz 1.
Hunk #7 FAILED at 125.
Hunk #8 succeeded at 169 (offset 6 lines).
Hunk #9 FAILED at 178.
Hunk #10 FAILED at 415.
Hunk #12 FAILED at 451.
Hunk #13 succeeded at 498 (offset 6 lines).
Hunk #14 FAILED at 518.
Hunk #15 FAILED at 537.
Hunk #16 FAILED at 551.
Hunk #17 succeeded at 550 (offset -4 lines).
Hunk #18 FAILED at 563.
Hunk #19 FAILED at 596.
Hunk #20 FAILED at 618.
Hunk #21 FAILED at 629.
#8
Ok, looks like people are needing this feature, so I'll start working on it. I haven't taken a close look at arthurf's code, but it seems like I should be able to use that, and then just add a better admin front to it so that the lists can be retrieved through the API, etc.
If you wish to put your 2 cents in about the functionality of this, please do so now. I will take into consideration the comments in this post currently.
Thanks again artherf for your work.
#9
ssheriff-
Not sure my code is a good basis- it's really a hack. The right way to do it is as fearfox mentions is to use the API to build the list data- I don't know the API at all so I didn't try that route. I'd be happy to split some of the work with you if you want some help- let me know if that makes sense and I'll do what I can.
best,
a.
#10
I have started the AHAH radio buttons on the admin screen, I'll post my patch in a couple of hours, if that's helpful.
#11
Here's a first try at the admin screen AHAH UI. This is not a functional patch yet - it only adds the UI on the admin side.
EDIT: The patch is against 2.1
#12
Thanks fearfox, I've integrated your AHAH UI stuff, and I've added the function that gets the lists from CM's API. I just have a question for you, I don't know too much about all the AHAH stuff, where now would the user's choices be stored. Do I have to update my admin settings page to have its own submit so I can save them myself? I might figure this out before you answer, but any help would be appreciated.
arthurf, I'll let you know if I need any extra help. I actually think this won't be too much work to implement, but who knows what happens with work, I might get stuck.
EDIT: Ok, more problems, how do I get the javascript to run on the form load, so that if the user has already set-up the module and chosen lists, when they go to the admin config page, it loads that they chose 'some' and selected a list? If I set the default value, it selects the radio button, but it doesn't run the javascript, so the lists don't show.
#13
ssherriff,
I'm just starting playing around with AHAH myself so I don't know if you can have it run on the form load; but this is what I would try next:
- for saving the values of the checked off lists, I would add a custom submit to the form, like you said, and save all the values using drupal_set_variable (that's what it does behind the scenes anyway). That function should serialize the array automatically. You can check in your db (variable) it the values are somehow ALREADY getting saved in that key. Now that I think about it, that form item (lists or whatever I called), might need to be renamed to campaignmonitor_list_ids or something like that, for consistency.
- To populate the form: when you describe the form, check if the value is already set (drupal_get_variable), and if it is, actually add the values to the "lists" form item - I think that should work.
I'm not 100% positive if this would actually work, but I can play around with it as well, if it's not working for you (yay, teamwork!)
#14
Ok, for anyone who is experimental, you can try the 6.x-2.x-dev version of the code. I've added in multiple lists and at the moment, it creates a block for each chosen list. I may also have it create a block that has all lists in one. I've tested it some, but not 100%. I've also added in an update function that updates from the one list version to the multiple list version.
If some people can test it and report any bugs, that would be great. Also mention anything you want added.
#15
Found a couple of issues so far.
1. When there are no lists or only one list the admin form was misbehaving. This should be fixed in the code below (sorry, I can't seem to generate a decent patch with WinMerge, it keeps thinking the whole file is different):
function _campaignmonitor_get_lists($api_key, $client_id) {
$retval = array();
$client = _campaignmonitor_create_client();
try{
//make soap call
$result = $client->__soapCall("Client.GetLists",
array(new SoapVar($api_key, XSD_STRING, null, null, "ApiKey", "http://api.createsend.com/api/"),
new SoapVar($client_id, XSD_STRING, null, null, "ClientID", "http://api.createsend.com/api/"),
),
array("soapaction" => "http://api.createsend.com/api/Client.GetLists")
);
if ($result->Code != 0) {
watchdog('campaignmonitor', 'Code - %code, Message - %message',
array('%code' => $result->Code, '%message' => $result->Message));
if ($show_errors) {
drupal_set_message('There is an error with the newsletter server. Please try again later.', 'error');
}
}
else {
if (!empty($result->List)) {
$lists = $result->List;
// if there is only one list
if (!empty($lists->ListID)) {
$retval[$lists->ListID] = $lists->Name;
}
else {
foreach($lists as $list) {
$retval[$list->ListID] = $list->Name;
}
}
}
}
} catch (SoapFault $e) {
watchdog('campaignmonitor', 'There was an error getting client lists: %fault', array('%fault' => $e->faultstring), WATCHDOG_ERROR);
if ($show_errors) {
drupal_set_message("There is an error with the newsletter server. Please try again later.", 'error');
}
}
return $retval;
}
2. On "My Newsletters" tab, if you are subscribe to several lists, then un-subscribe from one only, you get unsubcribed from all of them at once. I couldn't figure out why that is happening.
#16
Just in case, attaching my "patch" with the fix.
#17
Ok, I've made some updates. I think I'm getting close to releasing this, but I wouldn't mind if some people could try it out first. If you download the 6.x-3.x-dev version, it has this functionality. Please report any issues here.
#18
Another comment in regard to fearfox's issue 2 in post #15. It seems that there is a setting in Campaign Monitor where if someone unsubscribes to one list, they get unsubscribed from all of the lists. It is under unsubscribe settings for each list. This took me forever to figure out, but it was Campaign Monitor causing this, not my code. I will have to add some details to the README to explain this.
#19
@ssherriff,
I tested and it looks good. I can think of a couple more caveats... like if users subscribe to a list, and the site admin un-checks it from the list of available lists; then the users have to ability to unsubscribe from it from the system. But I don't think that's super-critical.
#20
Thanks @ssherriff for all your hard work on this (and everyone else that has contributed). This seems to be working well for me also, will be using on a production install v.soon so will help where we can with any issues that might arise.
#21
Because I need to multiple lists as well, I upgraded from 6--2 to 6--3. The update script went well and the module worked as advertised. Great work. I'll do some more testing on a staging server this week.
#22
Anyone else getting an issue when more than one subscription block (multiple lists) are used on the same page? I find only the first form is being submitted. Wondered if this was due to both forms having the same id/token id?
#23
I can't comment on the actual code, but I would love to see something like this -- I've divided up my organization's email marketing into a couple of different "clients" and lists, and it would be fantastic to add more than just the main newsletter list.
#24
kjay, I will try to have a look at this possible issue. Do you have any other information on it? Meaning is it still occurring?
#25
What's the latest on this issue?
#26
This functionality has been added to the 6.x-3.x branch starting at 6.x-3.0-beta1
#27
Automatically closed -- issue fixed for 2 weeks with no activity.