You are here

function _notify_select_content in Notify 7

Same name and namespace in other branches
  1. 8 notify.module \_notify_select_content()
  2. 2.0.x notify.module \_notify_select_content()
  3. 1.0.x notify.module \_notify_select_content()

Helper function to set up query objects to select content for counting and sending.

Return array has six values:

  • ordinary published entities: nodes, comments;
  • in unpublished queue: published nodes, published comments, unpublished nodes, unpublished comments,

Return value

array res_nodes, res_comms, res_nopub, res_copub, res_nounp, res_counp

4 calls to _notify_select_content()
notify_admin_queue_submit in ./notify.admin.inc
Submit for the notify_admin_queue form.
notify_admin_skip in ./notify.admin.inc
Menu callback, show admin list of queued notification settings.
_notify_count in ./notify.module
Count the carious types of content.
_notify_send in ./notify.module
Helper function to send the notification e-mail batch.

File

./notify.module, line 541
Notify module sends e-mail digests of new content and comments.

Code

function _notify_select_content() {
  $batch_remain = count(variable_get('notify_users', array()));
  $since = variable_get('notify_send_last', 0);
  if ($batch_remain) {
    $send_start = variable_get('notify_send_start', 0);
  }
  else {
    $send_start = REQUEST_TIME;
  }
  if (!$since) {
    $period = variable_get('notify_period', 86400);
    if ($period > 0) {
      $since = $send_start - $period;
    }
  }
  $all = node_type_get_types();
  $ntype = array();
  foreach ($all as $obj) {
    $ntype[] = $obj->type;
  }

  // Build query object to fetch new nodes.
  $q = db_select('node', 'n');
  $q
    ->fields('n', array(
    'nid',
  ));
  if (count($ntype) >= 1) {
    $q
      ->condition('n.type', $ntype, 'IN');
  }
  if (variable_get('notify_include_updates', 0)) {
    $q
      ->condition(db_or()
      ->condition(db_and()
      ->condition('n.created', $since, '>')
      ->condition('n.created', $send_start, '<='))
      ->condition(db_and()
      ->condition('n.changed', $since, '>')
      ->condition('n.changed', $send_start, '<=')));
  }
  else {
    $q
      ->condition('n.created', $since, '>');
    $q
      ->condition('n.created', $send_start, '<=');
  }
  $q
    ->orderBy('n.created', 'asc');
  $res_nodes = $q
    ->execute();

  // Get published nodes in unpublished queue
  $res_nopub = db_query('SELECT q.nid
    FROM {notify_unpublished_queue} q
    INNER JOIN {node} n
    ON q.nid = n.nid
    WHERE q.cid = :cid AND n.status = :status
    ORDER BY q.nid asc', array(
    ':cid' => 0,
    ':status' => NODE_PUBLISHED,
  ));

  // Get unpublished nodes in unpublished queue
  $res_nounp = db_query('SELECT q.nid
    FROM {notify_unpublished_queue} q
    INNER JOIN {node} n
    ON q.nid = n.nid
    WHERE q.cid = :cid AND n.status = :status
    ORDER BY q.nid asc', array(
    ':cid' => 0,
    ':status' => NODE_NOT_PUBLISHED,
  ));
  if (module_exists('comment')) {

    // Fetch new published comments.
    $q = db_select('comment', 'c');
    $q
      ->join('node', 'n', 'c.nid = n.nid');
    $q
      ->fields('c', array(
      'cid',
    ));
    if (count($ntype) >= 1) {
      $q
        ->condition('n.type', $ntype, 'IN');
    }
    if (variable_get('notify_include_updates', 0)) {
      $q
        ->condition(db_or()
        ->condition(db_and()
        ->condition('c.created', $since, '>')
        ->condition('c.created', $send_start, '<='))
        ->condition(db_and()
        ->condition('c.changed', $since, '>')
        ->condition('c.changed', $send_start, '<=')));
    }
    else {
      $q
        ->condition('c.created', $since, '>');
      $q
        ->condition('c.created', $send_start, '<=');
    }
    $q
      ->orderBy('c.created', 'asc');
    $res_comms = $q
      ->execute();

    // Get published comments in unpublished queue
    $res_copub = db_query('SELECT q.nid, q.cid
      FROM {notify_unpublished_queue} q
      INNER JOIN {comment} c
      ON q.cid = c.cid
      WHERE c.status = :status
      ORDER BY q.cid asc', array(
      ':status' => COMMENT_PUBLISHED,
    ));

    // Get unpublished comments in unpublished queue
    $res_counp = db_query('SELECT q.nid, q.cid
      FROM {notify_unpublished_queue} q
      INNER JOIN {comment} c
      ON q.cid = c.cid
      WHERE c.status = :status
      ORDER BY q.cid asc', array(
      ':status' => COMMENT_NOT_PUBLISHED,
    ));
  }
  else {
    $res_comms = $res_copub = $res_counp = NULL;
  }
  return array(
    $res_nodes,
    $res_comms,
    $res_nopub,
    $res_copub,
    $res_nounp,
    $res_counp,
  );
}