You are here

function notify_admin_skip in Notify 7

Menu callback, show admin list of queued notification settings.

1 string reference to 'notify_admin_skip'
notify_menu in ./notify.module
Implements hook_menu().

File

./notify.admin.inc, line 417
Administrative pages callbacks for the Notify module.

Code

function notify_admin_skip($form, &$form_state) {

  // Fetch list of nodes and comments scheduled for notification
  list($res_nodes, $res_comms, $res_nopub, $res_copub, $res_nounp, $res_counp) = _notify_select_content();

  // Get the nodes and comments queued.
  $count = 0;
  $nodes = $comments = array();

  // Ordinary nodes
  foreach ($res_nodes as $row) {
    $nodes[$row->nid] = node_load($row->nid);
    $count++;
  }

  // Ordinary comments
  if ($res_comms) {
    foreach ($res_nopub as $row) {
      if (!isset($nodes[$row->nid])) {
        $nodes[$row->nid] = node_load($row->nid);
        $count++;
      }
    }
    foreach ($res_comms as $row) {
      $comment = comment_load($row->cid);
      $comments[$comment->nid][$row->cid] = $comment;
      $count++;
    }
    foreach ($res_copub as $row) {
      if (!isset($comments[$row->nid][$row->cid])) {
        $comments[$row->nid][$row->cid] = comment_load($row->cid);
        $count++;
      }
    }
  }

  // Published nodes in unpublished queue
  foreach ($res_nopub as $row) {
    if (!isset($nodes[$row->nid])) {
      $nodes[$row->nid] = node_load($row->nid);
      $count++;
    }
  }

  // Unpublished nodes in unpublished queue
  foreach ($res_nounp as $row) {
    if (!isset($nodes[$row->nid])) {
      $nodes[$row->nid] = node_load($row->nid);
      $count++;
    }
  }
  $form = array();
  $form['#tree'] = TRUE;
  $form['info'] = array(
    '#markup' => '<p>' . t('The following table shows all messages that are scheduled to be sent as notifications:' . '</p>'),
  );
  $skpnodes = variable_get('notify_skip_nodes', array());
  $skpcomts = variable_get('notify_skip_comments', array());
  $ii = 0;
  $entities = array();
  foreach ($nodes as $node) {
    $ii++;
    $entities[$ii] = array();
    $entities[$ii]['nid'] = array(
      '#markup' => $node->nid,
    );
    $entities[$ii]['cid'] = array(
      '#markup' => '-',
    );
    $entities[$ii]['created'] = array(
      '#markup' => format_date($node->created, 'short'),
    );
    $entities[$ii]['updated'] = array(
      '#markup' => $node->changed != $node->created ? format_date($node->changed, 'short') : '-',
    );
    $entities[$ii]['title'] = array(
      '#markup' => $node->title,
    );
    $flag = in_array($node->nid, $skpnodes) ? 1 : 0;
    $entities[$ii]['dist'] = array(
      '#type' => 'checkbox',
      '#default_value' => $flag,
    );
  }
  foreach ($comments as $thread) {
    foreach ($thread as $comment) {
      $ii++;
      $entities[$ii] = array();
      $entities[$ii]['nid'] = array(
        '#markup' => $comment->nid,
      );
      $entities[$ii]['cid'] = array(
        '#markup' => $comment->cid,
      );
      $entities[$ii]['created'] = array(
        '#markup' => format_date($comment->created, 'short'),
      );
      $entities[$ii]['updated'] = array(
        '#markup' => $comment->changed != $comment->created ? format_date($comment->changed, 'short') : '-',
      );
      $entities[$ii]['title'] = array(
        '#markup' => $comment->subject,
      );
      $flag = in_array($comment->cid, $skpcomts) ? 1 : 0;
      $entities[$ii]['dist'] = array(
        '#type' => 'checkbox',
        '#default_value' => $flag,
      );
    }
  }
  $form['entities'] = $entities;
  $batch_remain = count(variable_get('notify_users', array()));
  if ($batch_remain) {
    $form['info2'] = array(
      '#markup' => '<p>' . t('Please note that the list above may be out of sync.  Saving an altered list of skip flags is disabled as long as notifications are being processed.') . '</p> ',
    );
  }
  else {
    $form['info2'] = array(
      '#markup' => '<p>' . t('To flag that <em>no</em> notification about a particular message should be sent, check the checkbox in the “Skip” column. Press “Save skip flags” to save the flags.') . '</p> ',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save skip flags'),
    '#disabled' => $batch_remain,
  );
  return $form;
}