You are here

function merci_hours_instantiate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Load the requested calendar or site's default if none given.

6 calls to merci_hours_instantiate()
merci_holiday_day_is_holiday in merci_hours/merci_holiday.module
merci_hours_day_is_open in merci_hours/merci_hours.module
Wrapper for WorkCalendar::isOpenDay().
merci_hours_get_open_days_in_month in merci_hours/merci_hours.module
Wrapper for WorkCalendar::openDays().
merci_hours_get_open_days_in_year in merci_hours/merci_hours.module
Wrapper for WorkCalendar::openDays().
merci_hours_get_open_hours_by_day in merci_hours/merci_hours.module
Return array of office hours keyed by day of the week.

... See full list

File

merci_hours/merci_hours.module, line 352

Code

function merci_hours_instantiate($name = NULL) {
  if (empty($name)) {
    $name = variable_get('merci_hours_default');
    if (empty($name)) {
      throw new Exception('Default merci hours not configured.');
    }
  }
  $wc = entity_load_single('merci_hours', $name);
  if (!$wc) {
    throw new Exception($name . ' merci hours doesn\'t exist.');
  }
  $week_days = array();
  $weekdays = date_week_days_untranslated();
  foreach ($wc->{MERCI_HOURS_FIELD}[LANGUAGE_NONE] as $timefield) {
    $open = new DateObject($timefield['value']);
    $day = $open
      ->format('w');
    $week_days[] = $weekdays[$day];
  }
  $wc
    ->updateWeek($week_days);
  return $wc;
}