| | |
| | | <?php |
| | | |
| | | use JVBase\managers\Cache; |
| | | use JVBase\meta\Meta; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | |
| | | |
| | | /** |
| | | * @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 = new JVBase\managers\CacheManager('hours-'.$ID, WEEK_IN_SECONDS); |
| | | $key = 'hours_display'; |
| | | $cached = $cache->get($key); |
| | | $cache = Cache::for('hours_display', WEEK_IN_SECONDS)->connect('taxonomy')->connect('post')->connect('user'); |
| | | |
| | | $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('hours'); |
| | | $byAppt = $meta->get('by_appointment'); |
| | | $walkins = $meta->get('walkins'); |
| | | |
| | | $out = ''; |
| | | |
| | |
| | | $out .= '<p class="hours-notes"><small>' . implode(' • ', $notes) . '</small></p>'; |
| | | } |
| | | |
| | | $cache->set($key, $out); |
| | | $cache->set($ID, $out); |
| | | return $out; |
| | | } |
| | | |
| | |
| | | * @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 |
| | | * @throws DateInvalidTimeZoneException |
| | | */ |
| | | function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'): ?string { |
| | | if (!jvbHasOperatingHours($hours_data)) { |