function hours_today($library, $time=NULL) { if ($time === NULL) { $time = time(); } $cal = LibraryInfo::get_calendar($library); $hours = $cal->get_day_events($time); $hour_strings = Array(); foreach ($hours as $hour) { if (stripos($hour->get_summary(), 'closed') !== FALSE) continue; $hourstr = $hour->get_range()->format('g:ia'); $hourstr = str_replace(':00', '', $hourstr); if (stripos($hour->get_summary(), 'by appointment') !== FALSE) { $hourstr .= ' (by appointment)'; } $hour_strings[] = $hourstr; } if (count($hour_strings) > 0) { $hours_today = implode(', ', $hour_strings); } else { $hours_today = 'Closed'; } return $hours_today; }
public static function get_libraries() { if (self::$libraries === NULL) { $libraries = Array(); $drupalDB = DrupalDB::$connection; $stmt = $drupalDB->stmt_init(); $stmt->prepare("SELECT title FROM node WHERE type = 'library_office' ORDER BY title"); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($library); while ($stmt->fetch()) { // hide closed libraries; eventually need a way to delete if ($library != 'Aeronautics and Astronautics Library' && $library != 'Lindgren Library') { $libraries[] = $library; } } $stmt->close(); self::$libraries = $libraries; } return self::$libraries; }
<? $docRoot = getenv("DOCUMENT_ROOT"); require_once $docRoot . "/mobi-config/mobi_web_constants.php"; require_once WEBROOT . 'page_builder/page_header.php'; require_once LIBDIR . 'mit_ical_lib.php'; require_once LIBDIR . 'LibraryInfo.php'; require WEBROOT . "libraries/libraries_lib.php"; $libraries = LibraryInfo::get_libraries(); $hours_today = Array(); foreach ($libraries as $library) { $hourstr = hours_today($library); if ($hourstr != 'Closed') { $hours_today[$library] = 'Open ' . $hourstr; } else { $hours_today[$library] = 'Closed'; } } require "$page->branch/locations.html"; $page->output(); ?>