Jake Vanderwerf
2026-05-03 9bbeea742424837fb58207d88e10dbca0b2cae04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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);
            }
        }
    }
}