You are here

function newsletter_list in Newsletter 7

Same name and namespace in other branches
  1. 7.2 modules/list/includes/newsletter_list.admin.inc \newsletter_list()

Menu callback; Form to list subscriber lists on a table and provide certain actions.

18 string references to 'newsletter_list'
NewsletterAutomated::getQuery in includes/newsletter.automated.inc
Builds a dynamic query that gets the current nodes to be sent with the current newsletter.
NewsletterAutomated::__construct in includes/newsletter.automated.inc
NewsletterListController::delete in includes/newsletter.list.controller.inc
NewsletterListController::save in includes/newsletter.list.controller.inc
NewsletterListController::__construct in includes/newsletter.list.controller.inc
Constructor: sets basic variables.

... See full list

File

includes/newsletter.admin.inc, line 560
Admin page callbacks for the newsletter module.

Code

function newsletter_list($form, &$form_state) {
  if (isset($form_state['storage']['confirm'])) {
    $form['operation'] = array(
      '#type' => 'hidden',
      '#value' => 'delete',
    );
    $form['list'] = array(
      '#type' => 'hidden',
      '#value' => $form_state['values']['list'],
    );
    $lists = newsletter_list_load($form_state['values']['list']);
    $output = t('Are you sure you want to delete the following newsletter lists?');
    $output .= '<ul>';
    foreach ($lists as $list) {
      $output .= !empty($list) ? '<li>' . check_plain($list->title) . '</li>' : '';
    }
    $output .= '</ul>';
    $output .= t('This action cannot be undone.');
    return confirm_form($form, t('Delete the following?'), 'admin/config/media/newsletter/lists', filter_xss($output));
  }
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Options'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $options['delete'] = t('Delete the selected lists');
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'delete',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $header = array(
    'id' => array(
      'data' => t('ID'),
      'field' => 'nlid',
    ),
    'title' => array(
      'data' => t('Title'),
      'field' => 'title',
    ),
    'send_rate' => array(
      'data' => t('Send Rate'),
      'field' => 'send_rate',
    ),
    'template' => array(
      'data' => t('Template'),
      'field' => 'ntid',
    ),
    'created' => array(
      'data' => t('Created'),
      'field' => 'lists.created',
      'sort' => 'desc',
    ),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('newsletter_list', 'lists')
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->join('field_data_field_newsletter_template', 'template_field', 'lists.nlid = template_field.entity_id');
  $query
    ->join('newsletter_template', 'templates', 'template_field.field_newsletter_template_target_id = templates.ntid');
  $query
    ->addField('templates', 'subject', 'template_title');
  $query
    ->fields('lists');
  $result = $query
    ->limit(50)
    ->orderByHeader($header)
    ->execute();
  $options = array();
  $destination = drupal_get_destination();
  foreach ($result as $row) {
    $operations = array(
      'data' => array(
        array(
          '#type' => 'link',
          '#title' => t('edit'),
          '#href' => 'admin/config/media/newsletter/lists/edit/' . $row->nlid,
          '#options' => array(
            'query' => $destination,
          ),
        ),
        array(
          '#markup' => ' | ',
        ),
        array(
          '#type' => 'link',
          '#title' => t('delete'),
          '#href' => 'admin/config/media/newsletter/lists/delete/' . $row->nlid,
          '#options' => array(
            'query' => $destination,
          ),
        ),
      ),
    );
    $options[$row->nlid] = array(
      'id' => (int) $row->nlid,
      'title' => check_plain($row->title),
      'send_rate' => check_plain($row->send_rate),
      'template' => check_plain($row->template_title),
      'created' => format_date($row->created, 'short'),
      'operations' => $operations,
    );
  }
  $form['list'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No lists available.'),
  );
  $form['pager'] = array(
    '#theme' => 'pager',
  );
  return $form;
}