You are here

function oa_events_send_reminders in Open Atrium Events 7.2

Send create message and send reminders for upcoming events.

Parameters

array $nids: An array of event nids to send reminders for.

int $start_date: The date to start from. This is used to find the next event in recurring series.

int $end_date: The end date, for finding the next event in a recurring series.

1 call to oa_events_send_reminders()
oa_events_cron in ./oa_events.module
Implements hook_cron().
2 string references to 'oa_events_send_reminders'
oa_events_cron in ./oa_events.module
Implements hook_cron().
oa_events_oa_settings_form in ./oa_events.module
Implements hook_oa_settings_form().

File

./oa_events.module, line 336
Code for the OA Events feature.

Code

function oa_events_send_reminders($nids, $start_date, $end_date) {
  $nodes = entity_load('node', $nids);
  foreach ($nodes as $node) {
    $next_event = NULL;
    $dates = field_get_items('node', $node, 'field_oa_date');
    foreach ($dates as $date) {
      if ($date['value'] >= $start_date && $date['value'] <= $end_date) {
        $next_event = $date;
      }
    }
    $params = (object) array(
      'entity_id' => $node->nid,
      'entity_type' => 'node',
      'timestamp' => $next_event['value'],
    );

    // Don't store recurrence rules on the date arg.
    if (is_array($next_event)) {
      unset($next_event['rrule']);
    }
    $record_found = db_select('oa_events_notifications_log', 'n')
      ->fields('n', array(
      'entity_id',
    ))
      ->condition('entity_id', $params->entity_id)
      ->condition('entity_type', $params->entity_type)
      ->condition('timestamp', $params->timestamp)
      ->execute()
      ->fetchField();
    if (empty($record_found) && module_exists('oa_messages')) {
      $message = oa_messages_create('oa_event_notification', $node, 'node', '', array(
        'date' => $next_event,
      ), 1);
      drupal_write_record('oa_events_notifications_log', $params);
    }
  }
}