<?php
|
namespace JVBase\managers\SEO\render\Traits\_Properties;
|
|
use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\LocationFeatureSpecification;
|
use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\PropertyValue;
|
use JVBase\managers\SEO\render\Traits\_Helpers\arrayHelper;
|
use JVBase\meta\Meta;
|
use JVBase\registrar\Fields;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
trait amenityFeatureTrait {
|
use arrayHelper;
|
/**
|
* @var LocationFeatureSpecification|array An amenity feature (e.g. a characteristic or service) of the Accommodation. This generic property does not make a statement about whether the feature is included in an offer for the main accommodation or available at extra costs.
|
*/
|
protected LocationFeatureSpecification|array $amenityFeature;
|
|
public function getAmenityFeature():LocationFeatureSpecification|array|null
|
{
|
return $this->amenityFeature??null;
|
}
|
public function setAmenityFeature(LocationFeatureSpecification|array $amenityFeature):void
|
{
|
if (is_array($amenityFeature)) {
|
$amenityFeature = $this->classArray('amenityFeature',$amenityFeature, 'JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\LocationFeatureSpecification');
|
}
|
$this->amenityFeature = $amenityFeature;
|
}
|
|
public function setAmenityFeatureField(Fields $fields):void
|
{
|
$fields->addField('amenityFeature', [
|
'type' => 'set',
|
'label' => __('Amenities', 'jvb'),
|
'options' => [
|
'Wheelchair Accessible' => 'Wheelchair Accessible',
|
'Free Parking' => 'Free Parking',
|
'Private Rooms' => 'Private Rooms',
|
'Air Conditioning' => 'Air Conditioning',
|
'WiFi' => 'WiFi',
|
'Gender Neutral Restroom' => 'Gender Neutral Restroom',
|
'LGBTQ+ Friendly' => 'LGBTQ+ Friendly',
|
'Sterilization Room' => 'Sterilization Room',
|
'Refreshments Available' => 'Refreshments Available',
|
'Street Level Access' => 'Street Level Access',
|
'Single Use Needles' => 'Single Use Needles',
|
'Consultation Room' => 'Consultation Room',
|
'Aftercare Products Available' => 'Aftercare Products Available',
|
'Walk-Ins Welcome' => 'Walk-Ins Welcome',
|
]
|
]);
|
}
|
|
public function formatAmenityFeatureField(Meta $meta):void
|
{
|
$amenities = $meta->get('amenityFeature');
|
|
$properties = [
|
'Walk-Ins Welcome',
|
'LGBTQ+ Friendly',
|
];
|
|
if (!empty($amenities)) {
|
$out = [];
|
$prop = [];
|
foreach ($amenities as $amenity) {
|
if (in_array($amenity, $properties)) {
|
$pr = new PropertyValue();
|
$pr->setName($amenity);
|
$pr->setValue(true);
|
$prop[] = $pr;
|
} else {
|
$am = new LocationFeatureSpecification();
|
$am->setName($amenity);
|
$am->setValue(true);
|
$out[] = $am;
|
}
|
}
|
if (!empty($out)) {
|
$this->setAmenityFeature($out);
|
}
|
if (!empty($prop)) {
|
$this->setAdditionalProperty($prop);
|
}
|
}
|
}
|
}
|