From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
inc/helpers/time.php | 84 +++++++++++++++++++++++-------------------
1 files changed, 46 insertions(+), 38 deletions(-)
diff --git a/inc/helpers/time.php b/inc/helpers/time.php
index 126f52a..88ee1df 100644
--- a/inc/helpers/time.php
+++ b/inc/helpers/time.php
@@ -1,6 +1,8 @@
<?php
-use JVBase\managers\CacheManager;
+use JVBase\base\Options;
+use JVBase\managers\Cache;
+use JVBase\meta\Meta;
if (!defined('ABSPATH')) {
exit;
@@ -135,34 +137,39 @@
/**
* @param int $ID
- * @param JVBase\Meta\MetaManager $meta
+ * @param string $type
*
* @return string
*/
-function jvbRenderHours(int $ID, JVBase\Meta\MetaManager $meta):string
+function jvbRenderHours(int $ID, string $type = ''):string
{
- $cache = CacheManager::for('hours-'.$ID, WEEK_IN_SECONDS);
- $key = 'hours_display';
- $cached = $cache->get($key);
+ if (!$type) {
+ return '';
+ }
+ $cache = Cache::for('hours_display_'.$type, $type, WEEK_IN_SECONDS);
+
+ $cached = $cache->get($ID);
if ($cached !== false) {
return $cached;
}
+ $meta = match($type){
+ 'post' => Meta::forPost($ID),
+ 'term' => Meta::forTerm($ID),
+ 'user' => Meta::forUser($ID),
+ default => false
+ };
if (!$meta) {
- if (term_exists((int)$ID)) {
- $type = 'term';
- } elseif (get_post_status((int)$ID)) {
- $type = 'post';
- } else {
- $type = 'user';
- }
- $meta = new JVBase\meta\MetaManager($ID, $type);
+ $meta = jvbGetMeta($ID);
+ }
+ if (!$meta) {
+ return '';
}
- $hours = $meta->getValue('hours');
- $byAppt = $meta->getValue('by_appointment');
- $walkins = $meta->getValue('walkins');
+ $hours = $meta->get('openingHours');
+ $byAppt = $meta->get('by_appointment');
+ $walkins = $meta->get('walkins');
$out = '';
@@ -185,7 +192,7 @@
$out .= '<p class="hours-notes"><small>' . implode(' • ', $notes) . '</small></p>';
}
- $cache->set($key, $out);
+ $cache->set($ID, $out);
return $out;
}
@@ -308,10 +315,11 @@
* @param string $timezone Timezone string (default: 'America/Edmonton')
* @return bool True if currently open, false if closed
*/
-function jvbIsCurrentlyOpen($hours_data = null, $timezone = 'America/Edmonton') {
+function jvbIsCurrentlyOpen(?array $hours_data = null, string $timezone = 'America/Edmonton'):bool
+{
// Get hours data if not provided
if ($hours_data === null) {
- $hours_data = get_option(BASE.'hours', []);
+ $hours_data = Options::get('openingHours');
}
// Return false if no hours data
@@ -328,12 +336,12 @@
$today_hours = $hours_data[$current_day] ?? [];
// Return false if closed today
- if (empty($today_hours) || !($today_hours['open'] ?? false)) {
+ if (empty($today_hours) || !($today_hours['isOpen'] ?? false)) {
return false;
}
- $open_time = $today_hours['time_opens'] ?? '';
- $close_time = $today_hours['time_closes'] ?? '';
+ $open_time = $today_hours['opens'] ?? '';
+ $close_time = $today_hours['closes'] ?? '';
if (!$open_time || !$close_time) {
return false;
@@ -356,14 +364,14 @@
/**
* Check if current time is between two specified times
*
- * @param string $start_time Start time in H:i format (e.g., '10:00')
- * @param string $end_time End time in H:i format (e.g., '15:15')
+ * @param ?string $start_time Start time in H:i format (e.g., '10:00')
+ * @param ?string $end_time End time in H:i format (e.g., '15:15')
* @param string $timezone Timezone string (default: 'America/Edmonton')
* @return bool True if current time is within range, false otherwise
*/
-function jvbIsTimeBetween($start_time=null, $end_time=null, $timezone = 'America/Edmonton') {
+function jvbIsTimeBetween(?string $start_time = null, ?string $end_time = null, string $timezone = 'America/Edmonton'):bool {
if (!$start_time && !$end_time) {
- $hours = get_option(BASE.'today_hours');
+ $hours = Options::get('today_hours');
$start_time = $hours['time_start'];
$end_time = $hours['time_end'];
}
@@ -391,15 +399,15 @@
*
* @param array $hours_data Day-based hours data
* @param string $timezone Timezone string
- * @return string|null Next opening time description or null if never opens
+ * @return string Next opening time description or empty string if never opens
+ * @throws DateInvalidTimeZoneException
*/
-function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'): ?string {
+function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'):string {
if (!jvbHasOperatingHours($hours_data)) {
- return null;
+ return '';
}
$current_time = new DateTime('now', new DateTimeZone($timezone));
- $weekdays = jvbFullWeekdays();
// Check next 7 days
for ($i = 0; $i < 7; $i++) {
@@ -408,11 +416,11 @@
$day_name = strtolower($check_date->format('l'));
$day_data = $hours_data[$day_name] ?? [];
- if (empty($day_data) || !($day_data['open'] ?? false)) {
+ if (empty($day_data) || !($day_data['isOpen'] ?? false)) {
continue;
}
- $open_time = $day_data['time_opens'] ?? '';
+ $open_time = $day_data['opens'] ?? '';
if (!$open_time) {
continue;
}
@@ -433,16 +441,16 @@
// Format the result
if ($i === 0) {
- return 'Opens today at ' . jvbFormat12HourTime($open_time);
+ return ' Opens today at ' . jvbFormat12HourTime($open_time);
} elseif ($i === 1) {
- return 'Opens tomorrow at ' . jvbFormat12HourTime($open_time);
+ return ' Opens tomorrow at ' . jvbFormat12HourTime($open_time);
} else {
$day_formatted = ucfirst($day_name);
- return "Opens {$day_formatted} at " . jvbFormat12HourTime($open_time);
+ return " Opens {$day_formatted} at " . jvbFormat12HourTime($open_time);
}
}
- return null;
+ return '';
}
@@ -454,7 +462,7 @@
*/
function jvbHasOperatingHours(array $hours_data): bool {
foreach ($hours_data as $day_data) {
- if (!empty($day_data) && ($day_data['open'] ?? false)) {
+ if (!empty($day_data) && ($day_data['isOpen'] ?? false)) {
return true;
}
}
--
Gitblit v1.10.0