I'm developing subscriptions_og with your latest 2.0-beta10, so, current function subscriptions_page_user_overview() at subscriptions.admin.inc makes a custom query for getting a count of subscriptions to a blog:
// blog is a subtype of 'type' -- must do it separately
$count['blog']['author_uid'] = db_result(db_query("SELECT count(*) FROM {subscriptions} WHERE module = 'node' AND field = 'type' AND value = 'blog' AND recipient_uid = %d", $uid));
In order to provide similar functionality(with a hook), I included a new hook within this patch just after previous code:
// develCuy: Organic groups may have many subtypes of 'types' -- must do it separately
$count = module_invoke_all('count_user_subscriptions', $count, $uid);
It opens the door for another modules to provide a count of user subscriptions. This is critical for subscriptions_og because there is not another elegant way I found.
Additionally, I've added a the new function subscriptions_get_full_subscription() at subscriptions.module, similar to subscriptions_get_subscription(), but provides an object with full subscription fields:
/**
* Return all subscription fields for given parameters
*/
function subscriptions_get_full_subscription($uid, $module, $field, $value, $author_uid = -1) {
static $subscriptions;
if (!isset($subscriptions[$uid][$module][$field][$value][$author_uid])) {
$sql = "SELECT * FROM {subscriptions} WHERE module = '%s' AND field = '%s' AND value = '%s' AND author_uid = %d AND recipient_uid = %d";
$subscriptions[$uid][$module][$field][$value][$author_uid] = db_fetch_object(db_query($sql, $module, $field, $value, $author_uid, $uid));
}
return $subscriptions[$uid][$module][$field][$value][$author_uid];
}
This function is used by current subscriptions_og 5.x branch
Blessings!
| Comment | File | Size | Author |
|---|---|---|---|
| subscriptions-newhook.patch | 2.37 KB | develcuy |
Comments
Comment #1
salvisGood idea with the hook — much better than may kludge.
And the function is ok, too, but I wonder whether the caching is a beneficial. How do you use this function? Are you (or another module) really going to ask twice for the same record? We could be using up some serious memory here...
Comment #2
develcuy commentedOK salvis, I agree on that, because it is used only for subscriptions control. Code should look like:
Blessings.
Comment #3
salvis@develCuy: your OP code was buggy: module_invoke_all() returns nothing if no module implements the hook, and this caused all the counts to go to 0.
It's working fine with subscriptions_blog_ui.module — please let me know whether it works with subscriptions_og.module and also with both modules.
Comment #4
develcuy commentedThank you Salvis, I've updated subscriptions_og module to work with 2.0-beta11, it is working fine.
Blessings!
Comment #5
salvisGood, thanks.
Please try enabling subscriptions_blog_ui.module at the same time and check whether the two get along.
Comment #6
develcuy commentedI've checked activating all subscriptions modules and subscriptions_og, blogs and og counts are fine activating only one both or no-one.
Blessings!
Comment #7
salvisPerfect, thanks!
Comment #8
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #9
gustav commentedI do not like this extra hook at all. Instead of introducing this hook the subscriptions_blog_ui module should be rewritten to use its own unique combination of ('module', 'field') instead of reusing ('node', 'type') that is already used by subscriptions_content. Then the existing way of counting subscriptions
will work for all modules and no extra hook is needed.
Comment #10
gustav commentedSorry, I hadn't meant to mark this as critical.
Comment #11
salvisWhat's wrong with the hook? No one needs to use it. Has subscriptions_og stopped using it?
The problem with subscriptions_blog_ui is the "_ui" part. It's not a full add-on module, it only provides a user interface for the 'blog' content type, but all the work is done by subscriptions_content (content type subscriptions). Before the hook, there was a very kludgy solution in subscriptions_page_user_overview() for getting the blog subscriptions count.
Is it the name of the hook that you don't like? I didn't like it either and I talked about it to chx at the time, but he said it was long and unique enough to not be a problem.
Comment #12
salvis