From f16cb88a3218ac7bb32e43f0e0a2542d35c7a01b Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 17 Jun 2026 00:28:16 +0000
Subject: [PATCH] =Working on the Options Meta still. Group fields also needed some changes
---
inc/managers/SEO/render/Traits/_Properties/openingHoursSpecificationTrait.php | 107 ++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 81 insertions(+), 26 deletions(-)
diff --git a/inc/managers/SEO/render/Traits/_Properties/openingHoursSpecificationTrait.php b/inc/managers/SEO/render/Traits/_Properties/openingHoursSpecificationTrait.php
index f9aba4a..a717b7c 100644
--- a/inc/managers/SEO/render/Traits/_Properties/openingHoursSpecificationTrait.php
+++ b/inc/managers/SEO/render/Traits/_Properties/openingHoursSpecificationTrait.php
@@ -4,6 +4,8 @@
use JVBase\base\SchemaHelper;
use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\OpeningHoursSpecification;
use JVBase\managers\SEO\render\Traits\_Helpers\arrayHelper;
+use JVBase\meta\Meta;
+use JVBase\registrar\Fields;
if (!defined('ABSPATH')) {
exit;
@@ -41,34 +43,87 @@
$this->openingHoursSpecification = $openingHoursSpecification;
}
- public function getOpeningHoursSpecificationFieldConfig():array
+ public function setOpeningHoursSpecificationField(Fields $fields):void
{
- return [
- 'type' => 'repeater',
- 'label' => 'Opening Hours',
- 'fields' => [
- 'dayOfWeek' => [
- 'type' => 'radio',
- 'label' => 'Day(s) of Week',
- 'options' => [
- 'Mo' => 'Monday',
- 'Tu' => 'Tuesday',
- 'We' => 'Wednesday',
- 'Th' => 'Thursday',
- 'Fr' => 'Friday',
- 'Sa' => 'Saturday',
- 'Su' => 'Sunday'
+ $days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
+ $dayFields = [];
+ foreach ($days as $day) {
+ $slug = strtolower($day);
+
+ $dayFields[$slug] = [
+ 'type' => 'group',
+ 'label' => $day,
+ 'fields' => [
+ 'isOpen' => [
+ 'type' => 'true_false',
+ 'label' => 'Open',
+ ],
+ 'opens' => [
+ 'type' => 'time',
+ 'label' => 'Opens at',
+ 'required' => true
+ ],
+ 'closes' => [
+ 'type' => 'time',
+ 'label' => 'Closes at',
+ 'required' => true
]
],
- 'opens' => [
- 'type' => 'time',
- 'label' => 'Opens At',
- ],
- 'closes' => [
- 'type' => 'time',
- 'label' => 'Closes At',
- ]
- ]
- ];
+ 'section' => 'hours',
+ ];
+ }
+ $fields->addField('openingHours', [
+ 'type' => 'group',
+ 'label' => 'Opening Hours',
+ 'fields' => $dayFields,
+ 'section' => 'hours',
+ ]);
+ $fields->addField('by_appointment', [
+ 'type' => 'true_false',
+ 'label' => 'By Appointment Only',
+ 'section' => 'hours',
+ ]);
+ $fields->addField('allow_walkins', [
+ 'type' => 'true_false',
+ 'label' => 'Walk Ins Welcome',
+ 'section' => 'hours',
+ ]);
+ }
+ public function formatOpeningHoursSpecificationField(Meta $meta):void
+ {
+ $openingHours = $meta->get('openingHours');
+
+ if (!empty($openingHours)) {
+ $used = [
+ 'Mo' => false,
+ 'Tu' => false,
+ 'We' => false,
+ 'Th' => false,
+ 'Fr' => false,
+ 'Sa' => false,
+ 'Su' => false,
+ ];
+ $hours = [];
+ foreach ($openingHours as $row) {
+ $days = array_filter(explode(',', $row['dayOfWeek']),
+ function ($d) use ($used) {
+ if ($used[$d] === false) {
+ $used[$d] = true;
+ return true;
+ }
+ return false;
+ });
+ if (empty($days)) {
+ continue;
+ }
+ $opens = new OpeningHoursSpecification();
+ $opens->setDayOfWeek($days);
+ $opens->setOpens($row['opens']);
+ $opens->setCloses($row['closes']);
+ }
+ if (!empty($hours)){
+ $this->setOpeningHoursSpecification($hours);
+ }
+ }
}
}
--
Gitblit v1.10.0