<?php
|
namespace JVBase\managers\SEO\render\Traits\_Properties;
|
|
use JVBase\base\SchemaHelper;
|
use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\OpeningHoursSpecification;
|
use JVBase\managers\SEO\render\Traits\_Helpers\arrayHelper;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
trait openingHoursSpecificationTrait {
|
use arrayHelper;
|
/**
|
* @var OpeningHoursSpecification|array The opening hours of a certain place.
|
*/
|
protected OpeningHoursSpecification|array $openingHoursSpecification;
|
|
public function getOpeningHoursSpecification():OpeningHoursSpecification|array|null
|
{
|
return $this->openingHoursSpecification??null;
|
}
|
public function setOpeningHoursSpecification(OpeningHoursSpecification|array $openingHoursSpecification):void
|
{
|
if (is_array($openingHoursSpecification)) {
|
if (array_key_exists('dayOfWeek', $openingHoursSpecification)) {
|
if (!array_key_exists('type', $openingHoursSpecification)) {
|
$openingHoursSpecification['type'] = 'JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\OpeningHoursSpecification';
|
}
|
$openingHoursSpecification = SchemaHelper::classFromConfig($openingHoursSpecification);
|
} else {
|
$out = [];
|
foreach ($openingHoursSpecification as $hours) {
|
if (!array_key_exists('type', $hours)){
|
$hours['type'] = 'JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\OpeningHoursSpecification';
|
}
|
$out[] = SchemaHelper::classFromConfig($hours);
|
}
|
$openingHoursSpecification = $out;
|
}
|
}
|
$this->openingHoursSpecification = $openingHoursSpecification;
|
}
|
|
public function getOpeningHoursSpecificationFieldConfig():array
|
{
|
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'
|
]
|
],
|
'opens' => [
|
'type' => 'time',
|
'label' => 'Opens At',
|
],
|
'closes' => [
|
'type' => 'time',
|
'label' => 'Closes At',
|
]
|
]
|
];
|
}
|
}
|