You are here

function _subscriptions_blog_ui_blog_form in Subscriptions 7

Same name and namespace in other branches
  1. 2.0.x subscriptions_blog_ui/subscriptions_blog_ui.module \_subscriptions_blog_ui_blog_form()

Returns the blog subscription form.

Parameters

array $blogs:

array $form:

$uid: ID of a user if >0 or of a role if <0.

Return value

array

1 call to _subscriptions_blog_ui_blog_form()
subscriptions_blog_ui_page_blog in ./subscriptions_blog_ui.module
Returns a list of blog subscriptions.

File

./subscriptions_blog_ui.module, line 135
Provide a Subscriptions UI for the blog content type subscriptions

Code

function _subscriptions_blog_ui_blog_form(array $blogs, array $form, $uid) {
  $subscriptions = array();
  $bulk_op = empty($_SESSION['subscriptions']['bulk_op']) ? '' : $_SESSION['subscriptions']['bulk_op'];
  if ($bulk_op) {

    // No initialization for bulk subscription.
    $uid = -DRUPAL_AUTHENTICATED_RID;
  }
  else {
    $result = db_query("\n      SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, u.name\n      FROM {subscriptions} s\n      INNER JOIN {users} u ON s.author_uid = u.uid\n      WHERE s.module = 'node' AND s.field = 'type' AND s.value = 'blog' AND s.recipient_uid = :recipient_uid\n      ORDER BY u.name", array(
      ':recipient_uid' => $uid,
    ), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    foreach ($result as $s) {
      $subscriptions[$s['author_uid']] = $s;
    }
  }
  $form[0] = array(
    '#type' => 'item',
    '#title' => '',
    '#tree' => TRUE,
    '#theme' => 'subscriptions_form_table',
  );
  $defaults = array();
  foreach ($blogs as $blog) {
    $title = $blog['has_blog'] ? l($blog['name'], 'blog/' . $blog['uid']) : $blog['name'];

    // add the active subscriptions
    if (!isset($subscriptions[$blog['uid']])) {

      // author-less item is missing -- add it here:
      $subscriptions[$blog['uid']] = array(
        'send_interval' => _subscriptions_get_setting('send_interval', $uid),
        'send_comments' => _subscriptions_get_setting('send_comments', $uid),
        'send_updates' => _subscriptions_get_setting('send_updates', $uid),
      );
    }
    subscriptions_form_helper($form[0], $defaults, $blog['uid'], 'blog', $title, $subscriptions[$blog['uid']]);
  }
  unset($form[0]['author']);
  $form[0]['defaults'] = array(
    '#type' => 'value',
    '#value' => $defaults,
  );
  subscriptions_form_column_filter($form[0], $uid);
  $form['access_key'] = array(
    '#type' => 'value',
    '#value' => 'blog',
  );
  return $form;
}