You are here

function node_registration_cron in Node registration 7

Implements hook_cron().

File

./node_registration.module, line 1193

Code

function node_registration_cron() {

  // Find event nodes.
  $nodes = _node_registration_event_nodes();

  // Find registrations with no reminder sent.
  $registrations = node_registration_load_multiple(FALSE, array(
    'reminder_sent' => 0,
    'cancelled' => 0,
  ));
  $reminders_sent = array();
  foreach ($registrations as $registration) {
    if (isset($nodes[$registration->nid])) {
      $node = $nodes[$registration->nid];
      $settings = $node->registration;
      $send = $settings->send_reminder_mail_to_registrees;
      $subject = $settings->reminder_mail_to_registrees_subject;
      $message = $settings->reminder_mail_to_registrees_body;
      if ($send && $subject && $message) {
        if ($settings
          ->reminder_time_passed()) {

          // Send e-mail.
          $registration->node = $node;
          node_registration_send_broadcast($node, $subject, $message, array(
            $registration,
          ));

          // Save it, so the registree doesn't get another e-mail next cron run.
          $updated = db_update('node_registration')
            ->fields(array(
            'reminder_sent' => REQUEST_TIME,
          ))
            ->condition('registration_id', $registration->registration_id)
            ->execute();
          $reminders_sent[] = l($node->title, 'node/' . $node->nid);
        }
      }
    }
  }
  if ($reminders_sent) {
    watchdog('node_registration', 'Reminders sent: !links', array(
      '!links' => implode(', ', $reminders_sent),
    ));
  }
}