Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created June 27, 2016 18:13
Show Gist options
  • Select an option

  • Save clrockwell/5ee6032ad3196948082b8dfc9284c6b9 to your computer and use it in GitHub Desktop.

Select an option

Save clrockwell/5ee6032ad3196948082b8dfc9284c6b9 to your computer and use it in GitHub Desktop.
<?php
/**
* Get count of holidays in a given month
* Holidays are a content type with a date field
*
* @param int $month The month
* @param int $year The year
*/
function cela_reports__working_hours__holidays_month($month, $year) {
$holidays = db_select('field_revision_field_event_dates', 'f')
->fields('f', array('field_event_dates_value'))
->condition('entity_type', 'event')
->condition('bundle', 'holiday')
->execute()
->fetchAll();
$holidays_this_month = array_filter($holidays, function($item) use ($month, $year) {
return date('Y-n', strtotime($item->field_event_dates_value)) == date('Y-n', strtotime($year . '-' . $month));
});
return count($holidays_this_month);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment