function _resource_conflict_get_timespans in Resource Conflict 7.3
Load an array of start/end times for the RC enabled date field on the node.
1 call to _resource_conflict_get_timespans()
- _resource_conflict_get_conflicting_nids in ./
resource_conflict.module - Check a node for conflicts.
File
- ./
resource_conflict.module, line 61 - Provides general functionality for the resource conflict module.
Code
function _resource_conflict_get_timespans($node) {
$time_spans = array();
$date_field = variable_get('rc_date_field_' . $node->type, FALSE);
if (!$date_field) {
return array();
}
$start_buffer = variable_get('rc_conflict_buffer_start_' . $node->type, '');
$end_buffer = variable_get('rc_conflict_buffer_end_' . $node->type, '');
$date_field_info = field_info_field($date_field);
$date_format = date_type_format($date_field_info['type']);
$date_items = field_get_items('node', $node, $date_field);
if (!$date_items) {
return array();
}
// Date repeat fields may have multiple values, so we iterate over each.
foreach ($date_items as $single_repetition_date) {
// Avoid the "Add another item" element that is added for date repeat
// fields.
if (!is_array($single_repetition_date)) {
continue;
}
$start = $single_repetition_date['value'];
$end = $single_repetition_date['value2'];
// Skip unless the user filled in a start and end date.
if (empty($start) || empty($end)) {
continue;
}
if (!empty($start_buffer)) {
$dateobj = DateObject::createFromFormat($date_format, $start);
if ($dateobj
->modify($start_buffer)) {
$start = $dateobj
->format($date_format);
}
}
if (!empty($end_buffer)) {
$dateobj = DateObject::createFromFormat($date_format, $end);
if ($dateobj
->modify($end_buffer)) {
$end = $dateobj
->format($date_format);
}
}
// Unix stamps should be interpreted as integers, but field_get_items pulls
// them out as strings. We need to cast back to int or our database
// comparisons fail.
if ($date_format == DATE_FORMAT_UNIX) {
$start = (int) $start;
$end = (int) $end;
}
$time_spans[] = array(
'start' => $start,
'end' => $end,
);
}
return $time_spans;
}