Jake Vanderwerf
2026-04-15 c4aa5cdb5e90ad4b420e22772797d16980232a2b
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
<?php
namespace JVBase\managers\SEO\render\Traits\_Properties;
 
use JVBase\base\SchemaHelper;
use JVBase\managers\SEO\render\Thing\Intangible\Rating\AggregateRating;
 
if (!defined('ABSPATH')) {
    exit;
}
trait aggregateRatingTrait {
    /**
     * @var AggregateRating The overall rating, based on a collection of reviews or ratings, of the item.
     */
    protected AggregateRating $aggregateRating;
 
    public function getAggregateRating():?AggregateRating
    {
        return $this->aggregateRating??null;
    }
 
    public function setAggregateRating(array|AggregateRating $aggregateRating):void
    {
        if (is_array($aggregateRating)){
            if (!array_key_exists('type', $aggregateRating)) {
                $aggregateRating['type'] = 'JVBase\managers\SEO\render\Thing\Intangible\Rating\AggregateRating';
            }
            $aggregateRating = SchemaHelper::classFromConfig($aggregateRating);
        }
        $this->aggregateRating = $aggregateRating;
    }
 
    public function getAggregateRatingFieldConfig():array
    {
        return [
            'type'  => 'group',
            'label' => 'Aggregate/Average Rating',
            'wrap'  => 'details',
            'fields'    => [
                'ratingCount'   => [
                    'type'  => 'number',
                    'label' => 'The total number of ratings (without text)',
                ],
                'reviewCount'   => [
                    'type'  => 'number',
                    'label' => 'The total number of reviews (with text)'
                ],
                'bestRating'    => [
                    'type'  => 'number',
                    'label' => 'The best rating',
                    'default'=> 5,
                ],
                'worstRating'   => [
                    'type'  => 'number',
                    'label' => 'The worst rating',
                    'default'=> 1,
                ]
            ]
        ];
    }
}