I have OG installed and working (finally). I also have Simplenews. I know that I can assign Group visibility to individual newsletter editions (created using create content >> newsletters).

However, I would like to restrict the ability to subscribe to a newsletter subject (created using administer >> newsletters >> add newsletter) by group.

I know you can't assign a newsletter subject to a group, but has someone figured out some sort of workaround. For example, I noted that you *can* assign group visibility to a Container and Categories, but not to Vocabulary and Terms. Since Taxonomy Access can not be used with OG I had to disable it. So, Simplenews seems to use Vocbulary and Terms for newsletter subjects. If there were some way to get it to use Containers instead, I could get it to do what I want.

Any suggestions? Thanks!

-ron

Comments

ngstigator’s picture

Ron, I just replied to another one of your posts. Seems we are on the same path.

I'm working on a simplenews patch that uses the user hook to automatically subscribe a new registrant to a group newsletter when they check off the groups that they wish to join. I'll probably submit this as a simplenews_og.inc or some such.

I've exposed simplenews to the registration process. Code here:
http://drupal.org/node/41745

ngstigator’s picture

The following function subscribes users to a newsletter when they join a group of the same name. (i.e. When I join the group "Xubuntu users SIG", I automatically subscribe to the newsletter "Xubuntu users SIG".) Unsubscribing from a group also automatically unsubscribes a user from the respective newsletter.

Just paste it anywhere in simplenews.module. Be sure to create the newsletter with the appropriate name for the groups that you wish to have this functionality.

function simplenews_og($op, $gid, $uid, $args=null) {
		$newsletter = db_fetch_object(db_query("SELECT td.tid, td.name FROM {term_data} AS td "
							. "INNER JOIN {vocabulary} AS v ON v.module = 'simplenews' AND v.vid = td.vid "
							. "INNER JOIN {node} AS n ON n.title = td.name AND n.nid = %d", $gid));

		$user = db_fetch_object(db_query("SELECT * FROM {users} AS u WHERE u.uid = %d", $uid));

		if ($subscription = db_fetch_object(db_query("SELECT sn.snid FROM {sn_subscriptions} AS sn WHERE sn.uid = %d", $uid))) {
			$snid = $subscription->snid;
		} else {
			db_query("INSERT INTO {sn_subscriptions} (mail, uid, a_status) VALUES ('%s', %d, %d)", $user->mail, $uid, 1);
			$snid = db_result(db_query("SELECT snid FROM {sn_subscriptions} WHERE mail = '%s'", $user->mail));
		}

		switch ($op) {
			case 'user insert':
				db_query("INSERT INTO {sn_snid_tid} (snid, tid) VALUES (%d, %d)", $snid, $newsletter->tid);
			break;
			case 'user delete':
				db_query("DELETE FROM {sn_snid_tid} WHERE snid = %d AND tid = %d", $snid, $newsletter->tid);
			break;
		}
}
nisguy’s picture

I don't know a word of PHP but this caught my eye...

switch ($op) {
case 'user insert':
db_query("INSERT INTO {sn_snid_tid} (snid, tid) VALUES (%d, %d)", $snid, $newsletter->tid);
break;
case 'user delete':
db_query("DELETE FROM {sn_snid_tid} WHERE snid = %d AND tid = %d", $snid, $newsletter->tid);
break;
}

Can I use an iteration of that to automatically subscribe new users as they are added to the newsletter of the web site and unsubscribe them when their profile is deleted? For example, I use the simplenews module on an internal company website. When the employee leaves I want them to be automatically unsubscribed from all newsletters when I remove their account.

ngstigator’s picture

Right idea, but should probably use simplenews functions instead of queries. Here's another thread that has more details:

http://drupal.org/node/41745

guillaumeduveau’s picture

sub, any newer thread ?