function subscriptions_taxonomy_taxa_form in Subscriptions 5.2
Same name and namespace in other branches
- 6 subscriptions_taxonomy.module \subscriptions_taxonomy_taxa_form()
Build the Categories subscription form at user/UID/subscriptions/taxa.
1 string reference to 'subscriptions_taxonomy_taxa_form'
- subscriptions_taxonomy_page_taxa in ./
subscriptions_taxonomy.module - Returns a list of taxonomy subscriptions.
File
- ./
subscriptions_taxonomy.module, line 210 - Subscriptions to taxonomy terms.
Code
function subscriptions_taxonomy_taxa_form($vocabularies, $account, $form) {
$uid = isset($account) ? $account->uid : (is_numeric(arg(5)) ? -arg(5) : -DRUPAL_AUTHENTICATED_RID);
$sql = db_rewrite_sql("\n SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, t.tid, t.vid, t.name\n FROM {term_data} t\n INNER JOIN {subscriptions} s ON " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "t.tid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " = s.value\n WHERE s.module = 'node' AND s.field = 'tid' AND s.recipient_uid = %d\n ORDER BY s.author_uid", 't', 'tid');
$result = db_query($sql, $uid);
while ($s = db_fetch_array($result)) {
$subscriptions[$s['vid']][$s['value']][$s['author_uid']] = $s;
$subscriptions_terms_by_vid[$s['vid']][$s['value']] = $s;
}
foreach ($vocabularies as $vocab) {
// display vocabulary name and group terms together
$form[$vocab->vid] = array(
'#type' => 'fieldset',
'#title' => $vocab->name,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form[$vocab->vid][0] = array(
'#tree' => TRUE,
'#theme' => 'subscriptions_form_table',
);
$subscriptions_vid = isset($subscriptions[$vocab->vid]) ? $subscriptions[$vocab->vid] : NULL;
$vids_to_restrict = variable_get('subscriptions_restricted_taxa', array());
$tree = NULL;
if (!in_array($vocab->vid, $vids_to_restrict)) {
// @ TODO create mechanism to allow users to
// subscribe to all terms under this vocabulary
$tree = taxonomy_get_tree($vocab->vid);
}
else {
if (isset($subscriptions_terms_by_vid[$vocab->vid])) {
$tree = $subscriptions_terms_by_vid[$vocab->vid];
$form[$vocab->vid][1] = array(
'#type' => 'item',
'#description' => '<div>' . t('This is a restricted category group; to subscribe to an unlisted category, go to a post in that category and subscribe from there.') . '</div>',
);
}
}
$forum_containers = NULL;
if (module_exists('forum') && $vocab->vid == _forum_get_vid()) {
$forum_containers = variable_get('forum_containers', array());
}
$defaults = array();
if (isset($tree)) {
foreach ($tree as $term) {
if (is_array($term)) {
$term = (object) $term;
}
$title = str_repeat('-- ', $term->depth) . l($term->name, 'taxonomy/term/' . $term->tid);
if (!isset($subscriptions_vid[$term->tid][-1])) {
// author-less item is missing -- add it here:
$subscriptions_vid[$term->tid][-1] = array(
'send_interval' => _subscriptions_get_setting('send_interval', $uid < 0 ? $uid : $account),
'send_comments' => _subscriptions_get_setting('send_comments', $uid < 0 ? $uid : $account),
'send_updates' => _subscriptions_get_setting('send_updates', $uid < 0 ? $uid : $account),
'author_uid' => FALSE,
);
}
// add the active subscriptions
foreach ($subscriptions_vid[$term->tid] as $author_uid => $subscription) {
// TODO: support multi-parent hierarchies (currently, the child is not repeated)
subscriptions_form_helper($form[$vocab->vid][0], $defaults, $author_uid, $term->tid, $title, $subscription);
if (isset($forum_containers) && in_array($term->tid, $forum_containers)) {
$tids = array_keys($form[$vocab->vid][0]['checkboxes']);
$tid = end($tids);
$form[$vocab->vid][0]['checkboxes'][$tid][-1]['#disabled'] = TRUE;
}
}
}
}
else {
$form[$vocab->vid]['info']['#value'] = '<p>' . t('This is a restricted category group; only subscribed categories show up in this list.<br />To subscribe to a category in this group, go to a post in that category and subscribe from there.') . '</p>';
}
$form[$vocab->vid][0]['defaults'] = array(
'#type' => 'value',
'#value' => $defaults,
);
subscriptions_form_column_filter($form[$vocab->vid][0], $uid);
}
if (empty($form)) {
$form = array(
'#value' => t('There are no active categories.'),
);
}
else {
$form['#tree'] = TRUE;
$form['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
$form['access_key'] = array(
'#type' => 'value',
'#value' => 'taxa',
);
$form['module'] = array(
'#type' => 'value',
'#value' => 'node',
);
$form['field'] = array(
'#type' => 'value',
'#value' => 'tid',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 10,
);
$form['#submit']['subscriptions_page_form_submit'] = array();
}
return $form;
}