You are here

function _resource_conflict_get_overlaps in Resource Conflict 6.2

Same name and namespace in other branches
  1. 5.2 resource_conflict.module \_resource_conflict_get_overlaps()
  2. 7.2 resource_conflict.module \_resource_conflict_get_overlaps()

Determine if any conflict enabled nodes overlap the specified times

1. $start is within the event time 2. $end end is within the event time 3. The event encompasses $start and $end 4. Allow the end of one event to occur at the start of the next

Parameters

$start: The start time of events to search as dateAPI object

$end: The end time of events to search as dateAPI object

Return value

An array of node ID's

2 calls to _resource_conflict_get_overlaps()
_resource_conflict_overlaps_from_date in ./resource_conflict.module
Determine if any nodes conflict between the specified dates using Date API.
_resource_conflict_overlaps_from_event in ./resource_conflict.module
Determine if any nodes conflict between the specified dates using Event.

File

./resource_conflict.module, line 377

Code

function _resource_conflict_get_overlaps($start, $end) {
  $date_start = date_convert($start, DATE_OBJECT, DATE_ISO);
  $date_end = date_convert($end, DATE_OBJECT, DATE_ISO);
  $event_start = date_convert($start, DATE_OBJECT, DATE_UNIX);
  $event_end = date_convert($end, DATE_OBJECT, DATE_UNIX);
  $rows = array();
  $conflict_types = _resource_conflict_get_conflict_enabled_types();
  foreach ($conflict_types as $type) {
    $date_field = variable_get('rc_date_field_' . $type, FALSE);
    if (strpos($date_field, 'field_', 0) === 0) {
      $date_db_info = content_database_info(content_fields($date_field));
      $date_table = '{' . $date_db_info['table'] . '}';
      $start_field_name = $date_db_info['columns']['value']['column'];
      $end_field_name = $date_db_info['columns']['value2']['column'];
      $query = "SELECT DISTINCT {node}.nid FROM {node} INNER JOIN {$date_table} date_table ON {node}.vid = date_table.vid\n        WHERE('%s' >= date_table.{$start_field_name} AND '%s' < date_table.{$end_field_name})\n        OR('%s' > date_table.{$start_field_name} AND '%s' <= date_table.{$end_field_name})\n        OR('%s' <= date_table.{$start_field_name} AND '%s' >= date_table.{$end_field_name})";
      $result = db_query($query, $date_start, $date_start, $date_end, $date_end, $date_start, $date_end);

      // Create an array of all of the results
      while ($row = db_fetch_array($result)) {
        $rows[] = $row['nid'];
      }
    }
    elseif ($date_field == 'event') {

      //event enabled
      $query = "SELECT DISTINCT nid FROM {event} WHERE (%d >= event_start AND %d < event_end)\n        OR (%d > event_start AND %d <= event_end)\n        OR (%d <= event_start AND %d >= event_end)";
      $result = db_query($query, $event_start, $event_start, $event_end, $event_end, $event_start, $event_end);

      // Create an array of all of the results
      while ($row = db_fetch_array($result)) {
        $rows[] = $row['nid'];
      }
    }
  }
  return array_unique($rows);
}