Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created November 14, 2013 19:29
Show Gist options
  • Save lkacenja/7472856 to your computer and use it in GitHub Desktop.
Save lkacenja/7472856 to your computer and use it in GitHub Desktop.
$start = 1383845472;
$end = 1384450272;
$query = db_select('field_data_field_om_airing_dates', 'dates');
$query->join('field_data_field_om_show_id', 'om_show', 'dates.entity_id=om_show.entity_id');
$query->join('field_data_field_om_show_project', 'project', 'om_show.field_om_show_id_value=project.entity_id');
$query->fields('project', array('field_om_show_project_nid'));
$query->fields('om_show', array('field_om_show_id_value'));
$query->fields('dates', array('field_om_airing_dates_value', 'field_om_airing_dates_value2'));
$query->condition('dates.field_om_airing_dates_value', $start, '>=');
$query->condition('dates.field_om_airing_dates_value2', $end, '<=');
$resource = $query->execute();
$result = $resource->fetchAll();
foreach ($result AS $key => $airing) {
$ts_query = db_select('field_data_field_om_timeslot_date', 'dates');
$ts_query->fields('dates', array('entity_id'));
$ts_query->condition('dates.field_om_timeslot_date_value', $airing->field_om_airing_dates_value, '<=');
$ts_query->condition('dates.field_om_timeslot_date_value2', $airing->field_om_airing_dates_value2, '>=');
$resource2 = $ts_query->execute();
$result2 = $resource2->fetchAll();
if (!empty($result2)) {
$result[$key]->timeslot = $result2[0]->entity_id;
}
}
$final_output = array();
foreach ($result AS $item) {
$final_output[$item->timeslot] = !empty( $final_output[$item->timeslot]) ? $final_output[$item->timeslot] : array('count' => 0, 'projects' => array(),'items' => array());
if (in_array($item->field_om_show_project_nid , $final_output[$item->timeslot]['projects'])) {
$final_output[$item->timeslot]['count'] ++;
}
$final_output[$item->timeslot]['projects'][] = $item->field_om_show_project_nid;
$final_output[$item->timeslot]['items'][] = $item;
}
dsm($final_output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment