function _resource_conflict_query_for_conflicts in Resource Conflict 7.3
Determine if any conflict enabled nodes overlap the specified times.
1. $start is within the event time 2. $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
array $time_spans: An array of 'time span' arrays with the following keys:
- start: Start of an event
- end: End of an event
The date format of each pair is that of the unsaved node's date format All date fields that are compared must be of the same format.
int $nid: The node ID of the resource that we're conflict checking for.
Return value
array An array of node IDs.
1 call to _resource_conflict_query_for_conflicts()
- _resource_conflict_get_conflicting_nids in ./
resource_conflict.module - Check a node for conflicts.
File
- ./
resource_conflict.module, line 190 - Provides general functionality for the resource conflict module.
Code
function _resource_conflict_query_for_conflicts(array $time_spans, $nid) {
$nids = array();
$conflict_types = variable_get('rc_types', array());
foreach ($conflict_types as $type) {
$date_field = variable_get('rc_date_field_' . $type, FALSE);
$date_table = '{field_data_' . $date_field . '}';
$start_field = 'date_table.' . $date_field . '_value';
$end_field = 'date_table.' . $date_field . '_value2';
foreach ($time_spans as $time_span) {
$query = db_select('node', 'n');
$query
->join($date_table, 'date_table', 'n.vid = date_table.revision_id');
$query
->fields('n', array(
'nid',
))
->condition(db_or()
->condition(db_and()
->condition($start_field, $time_span['start'], '<=')
->condition($end_field, $time_span['start'], '>'))
->condition(db_and()
->condition($start_field, $time_span['end'], '<')
->condition($end_field, $time_span['end'], '>='))
->condition(db_and()
->condition($start_field, $time_span['start'], '>=')
->condition($end_field, $time_span['end'], '<=')))
->addTag('resource_conflict')
->distinct();
// $nid may be null if the unsaved node was not yet created.
if ($nid) {
$query
->condition('n.nid', $nid, '<>');
}
$result = $query
->execute();
$nids = array_merge($nids, $result
->fetchCol());
}
}
return array_unique($nids);
}