You are here

function simplenews_admin_issues in Simplenews 7

Same name and namespace in other branches
  1. 7.2 includes/simplenews.admin.inc \simplenews_admin_issues()

Form builder: Builds a list of newsletters with operations.

See also

simplenews_admin_issues_validate()

simplenews_admin_issues_submit()

1 call to simplenews_admin_issues()
simplenews_admin_newsletter_issues in includes/simplenews.admin.inc
Menu callback: Admin form for sent and draft newsletters.

File

includes/simplenews.admin.inc, line 115
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_admin_issues() {

  // Build an 'Update options' form.
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  foreach (module_invoke_all('simplenews_issue_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'activate',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#submit' => array(
      'simplenews_admin_issues_submit',
    ),
    '#validate' => array(
      'simplenews_admin_issues_validate',
    ),
  );
  if (variable_get('simplenews_last_cron', '')) {
    $form['last_sent'] = array(
      '#markup' => '<p>' . format_plural(variable_get('simplenews_last_sent', 0), 'Last batch: 1 mail sent at !time.', 'Last batch: !count mails sent at !time.', array(
        '!time' => format_date(variable_get('simplenews_last_cron', ''), 'small'),
        '!count' => variable_get('simplenews_last_sent', 0),
      )) . "</p>\n",
    );
  }

  // Table header. Used as tablesort default
  $header = array(
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    'category' => array(
      'data' => t('Newsletter category'),
      'field' => 'sc.name',
    ),
    'created' => array(
      'data' => t('Created'),
      'field' => 'n.created',
      'sort' => 'desc',
    ),
    'published' => array(
      'data' => t('Published'),
    ),
    'sent' => array(
      'data' => t('Sent'),
    ),
    'subscribers' => array(
      'data' => t('Subscribers'),
    ),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('node', 'n')
    ->extend('PagerDefault')
    ->extend('TableSort');
  simplenews_build_issue_filter_query($query);
  $query
    ->innerJoin('simplenews_newsletter', 'sn', 'n.nid = sn.nid');
  $query
    ->leftJoin('simplenews_category', 'sc', 'sn.tid = sc.tid');
  $query
    ->leftJoin('taxonomy_term_data', 't', 'sc.tid = t.tid');

  //$query->leftJoin('users', 'u', 'ss.uid = u.uid');
  $query
    ->fields('n', array(
    'nid',
    'title',
    'created',
    'status',
  ))
    ->fields('sn', array(
    'tid',
  ))
    ->fields('t', array(
    'name',
  ))
    ->limit(30)
    ->orderByHeader($header);
  $query
    ->addField('sn', 'status', 'sent_status');
  $options = array();
  $destination = drupal_get_destination();
  module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
  foreach ($query
    ->execute() as $issue) {
    $categories = simplenews_category_list();
    $subscriber_count = simplenews_count_subscriptions($issue->tid);
    $pending_count = simplenews_count_spool(array(
      'nid' => $issue->nid,
    ));
    $send_status = $issue->sent_status == SIMPLENEWS_STATUS_SEND_PENDING ? $subscriber_count - $pending_count : theme('simplenews_status', array(
      'source' => 'sent',
      'status' => $issue->sent_status,
    ));
    $options[$issue->nid] = array(
      'title' => l($issue->title, 'node/' . $issue->nid),
      'category' => $issue->tid && isset($categories[$issue->tid]) ? $categories[$issue->tid] : t('- Unassigned -'),
      'created' => format_date($issue->created, 'small'),
      'published' => theme('simplenews_status', array(
        'source' => 'published',
        'status' => $issue->status,
      )),
      'sent' => $send_status,
      'subscribers' => $subscriber_count,
      'operations' => l(t('edit'), 'node/' . $issue->nid . '/edit', array(
        'query' => drupal_get_destination(),
      )),
    );
  }
  $form['issues'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No newsletters available.'),
  );
  $form['pager'] = array(
    '#theme' => 'pager',
  );
  return $form;
}