You are here

protected function NewsletterAutomated::getQuery in Newsletter 7

Same name and namespace in other branches
  1. 7.2 includes/newsletter.automated.inc \NewsletterAutomated::getQuery()

Builds a dynamic query that gets the current nodes to be sent with the current newsletter.

1 call to NewsletterAutomated::getQuery()
NewsletterAutomated::getSubscriberNodes in includes/newsletter.automated.inc
Get this newsletter nodes if list is exposed.

File

includes/newsletter.automated.inc, line 95
Contains NewsletterMail and NewsletterCustom that extend NewsletterBasic.

Class

NewsletterAutomated
Newsletter class that sends automated, non-custom newsletters with dynamic content based on taxonomy terms.

Code

protected function getQuery() {
  $tids = newsletter_get_template_terms($this->template->ntid);
  $tids = array_keys($tids) ? array_keys($tids) : array(
    0,
  );
  $query = db_select('taxonomy_index', 'tax');
  $query
    ->fields('tax', array(
    'nid',
  ));
  $query
    ->join('newsletter_list', 'list', 'list.nlid = ' . (int) $this->list->nlid);
  $query
    ->join('node', 'node', 'tax.nid = node.nid');
  $query
    ->addField('node', 'created', 'created');
  $query
    ->condition('tax.tid', $tids, 'IN');
  $query
    ->where('(list.last_sent <= node.created) OR (list.last_sent IS NULL )');
  if (!$this->manualSendRate && !$this->customSendRate) {
    $query
      ->where('list.send_again = CURDATE() OR list.send_again IS NULL');
  }
  if ($this->customSendRate) {
    $query
      ->range(0, (int) $this->list->send_rate);
  }
  else {
    $query
      ->range(0, (int) variable_get('newsletter_node_limit', 50));
  }
  $query
    ->orderBy('created', 'DESC');
  $query
    ->distinct();
  return $query;
}