Test Failed
Push — develop ( c07ba6...801573 )
by Paul
08:42
created

ElementorSummaryWidget::shortcodeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Elementor;
4
5
use Elementor\Controls_Manager;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
use GeminiLabs\SiteReviews\Modules\Rating;
8
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode;
9
10
class ElementorSummaryWidget extends ElementorWidget
11
{
12
    /**
13
     * @return string
14
     */
15
    public function get_icon()
16
    {
17
        return 'eicon-glsr-summary';
18
    }
19
20
    public static function shortcodeClass(): string
21
    {
22
        return SiteReviewsSummaryShortcode::class;
23
    }
24
25
    protected function hide_if_all_fields_hidden(): bool
26
    {
27
        return true;
28
    }
29
30
    protected function settings_advanced(): array
31
    {
32
        $settings = parent::settings_advanced();
33
        $settings = Arr::insertAfter('shortcode_id', $settings, [
34
            'rating_field' => [
35
                'description' => _x('Use the Review Forms addon to add custom rating fields.', 'admin-text', 'site-reviews'),
36
                'label_block' => true,
37
                'label' => _x('Custom Rating Field Name', 'admin-text', 'site-reviews'),
38
                'type' => Controls_Manager::TEXT,
39
            ],
40
        ]);
41
        return $settings;
42
    }
43
44
    protected function settings_basic(): array
45
    {
46
        $options = [
47
            'assigned_posts' => [
48
                'default' => '',
49
                'label' => _x('Limit Reviews to an Assigned Page', 'admin-text', 'site-reviews'),
50
                'label_block' => true,
51
                'options' => $this->assigned_posts_options(),
52
                'type' => Controls_Manager::SELECT2,
53
            ],
54
            'assigned_posts_custom' => [
55
                'condition' => ['assigned_posts' => 'custom'],
56
                'description' => _x('Separate values with a comma.', 'admin-text', 'site-reviews'),
57
                'label_block' => true,
58
                'placeholder' => _x('Enter the Post IDs', 'admin-text', 'site-reviews'),
59
                'show_label' => false,
60
                'type' => Controls_Manager::TEXT,
61
            ],
62
            'assigned_terms' => [
63
                'default' => '',
64
                'label' => _x('Limit Reviews to an Assigned Category', 'admin-text', 'site-reviews'),
65
                'label_block' => true,
66
                'multiple' => true,
67
                'options' => $this->assigned_terms_options(),
68
                'type' => Controls_Manager::SELECT2,
69
            ],
70
            'assigned_users' => [
71
                'default' => '',
72
                'label' => _x('Limit Reviews to an Assigned User', 'admin-text', 'site-reviews'),
73
                'label_block' => true,
74
                'options' => $this->assigned_users_options(),
75
                'type' => Controls_Manager::SELECT2,
76
            ],
77
            'assigned_users_custom' => [
78
                'condition' => ['assigned_users' => 'custom'],
79
                'description' => _x('Separate values with a comma.', 'admin-text', 'site-reviews'),
80
                'label_block' => true,
81
                'placeholder' => _x('Enter the User IDs', 'admin-text', 'site-reviews'),
82
                'show_label' => false,
83
                'type' => Controls_Manager::TEXT,
84
            ],
85
            'terms' => [
86
                'default' => '',
87
                'label' => _x('Limit Reviews to terms', 'admin-text', 'site-reviews'),
88
                'label_block' => true,
89
                'options' => $this->shortcodeInstance()->options('terms'),
90
                'type' => Controls_Manager::SELECT2,
91
            ],
92
            'type' => $this->get_type_control(),
93
            'rating' => [
94
                'default' => max(1, Rating::min()),
95
                'label' => _x('Minimum Rating', 'admin-text', 'site-reviews'),
96
                'max' => Rating::max(),
97
                'min' => max(1, Rating::min()),
98
                'separator' => 'before',
99
                'type' => Controls_Manager::NUMBER,
100
            ],
101
            'schema' => [
102
                'description' => _x('The schema should only be enabled once per page.', 'admin-text', 'site-reviews'),
103
                'label' => _x('Enable the schema?', 'admin-text', 'site-reviews'),
104
                'return_value' => 'true',
105
                'separator' => 'before',
106
                'type' => Controls_Manager::SWITCHER,
107
            ],
108
        ];
109
        $options = $this->insert_hide_controls($options);
110
        return $options;
111
    }
112
113
    protected function settings_layout(): array
114
    {
115
        return [
116
            'alignment' => [
117
                'default' => 'start',
118
                'is_responsive' => true,
119
                'label' => esc_html_x('Alignment', 'admin-text', 'site-reviews'),
120
                'options' => [
121
                    'start' => [
122
                        'title' => esc_html_x('Start', 'admin-text', 'site-reviews'),
123
                        'icon' => 'eicon-flex eicon-align-start-h',
124
                    ],
125
                    'center' => [
126
                        'title' => esc_html_x('Center', 'admin-text', 'site-reviews'),
127
                        'icon' => 'eicon-flex eicon-align-center-h',
128
                    ],
129
                    'end' => [
130
                        'title' => esc_html_x('End', 'admin-text', 'site-reviews'),
131
                        'icon' => 'eicon-flex eicon-align-end-h',
132
                    ],
133
                ],
134
                'selectors' => [
135
                    '{{WRAPPER}} .glsr-summary' => 'justify-content: {{VALUE}};',
136
                    '{{WRAPPER}} .glsr-summary-text' => 'display: flex; justify-content: {{VALUE}};',
137
                ],
138
                'type' => Controls_Manager::CHOOSE,
139
            ],
140
            'max_width' => [
141
                'default' => [
142
                    'unit' => 'px',
143
                    'size' => 450,
144
                ],
145
                'is_responsive' => true,
146
                'label' => esc_html_x('Max Width', 'admin-text', 'site-reviews'),
147
                'range' => [
148
                    '%' => [
149
                        'min' => 50,
150
                        'max' => 100,
151
                    ],
152
                    'px' => [
153
                        'min' => 50,
154
                        'max' => 1000,
155
                    ],
156
                ],
157
                'selectors' => [
158
                    '{{WRAPPER}} .glsr-summary' => '--glsr-max-w: {{SIZE}}{{UNIT}};',
159
                ],
160
                'size_units' => $this->set_custom_size_unit(['px', '%']),
161
                'type' => Controls_Manager::SLIDER,
162
            ],
163
            'percentage_bar_height' => [
164
                'default' => [
165
                    'unit' => 'em',
166
                    'size' => 1,
167
                ],
168
                'is_responsive' => true,
169
                'label' => esc_html_x('Percentage Bar Height', 'admin-text', 'site-reviews'),
170
                'range' => [
171
                    'em' => [
172
                        'max' => 1.5,
173
                        'min' => 0.1,
174
                        'step' => 0.1,
175
                    ],
176
                ],
177
                'selectors' => [
178
                    '{{WRAPPER}} .glsr-summary .glsr-bar-background' => '--glsr-text-md: {{SIZE}}{{UNIT}};',
179
                ],
180
                'size_units' => ['em'],
181
                'type' => Controls_Manager::SLIDER,
182
            ],
183
            'percentage_bar_spacing' => [
184
                'default' => [
185
                    'size' => 1.5,
186
                    'unit' => 'em',
187
                ],
188
                'is_responsive' => true,
189
                'label' => esc_html_x('Percentage Bar Spacing', 'admin-text', 'site-reviews'),
190
                'range' => [
191
                    'em' => [
192
                        'max' => 2,
193
                        'min' => 1,
194
                        'step' => 0.1,
195
                    ],
196
                ],
197
                'selectors' => [
198
                    '{{WRAPPER}} .glsr-summary .glsr-bar' => '--glsr-bar-leading: {{SIZE}}{{UNIT}};',
199
                ],
200
                'size_units' => ['em'],
201
                'type' => Controls_Manager::SLIDER,
202
            ],
203
        ];
204
    }
205
206
    protected function settings_rating(): array
207
    {
208
        return [
209
            'rating_color' => [
210
                'global' => [
211
                    'default' => '',
212
                ],
213
                'label' => esc_html_x('Color', 'admin-text', 'site-reviews'),
214
                'selectors' => [
215
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-bar-background-percent' => '--glsr-bar-bg: {{VALUE}} !important',
216
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-star-empty' => 'background: {{VALUE}} !important;',
217
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-star-full' => 'background: {{VALUE}} !important;',
218
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-star-half' => 'background: {{VALUE}} !important;',
219
                ],
220
                'type' => Controls_Manager::COLOR,
221
            ],
222
            'rating_size' => [
223
                'default' => [
224
                    'unit' => 'em',
225
                    'size' => 1.5,
226
                ],
227
                'is_responsive' => true,
228
                'label' => esc_html_x('Star Size', 'admin-text', 'site-reviews'),
229
                'range' => [
230
                    'em' => [
231
                        'min' => 0.25,
232
                        'max' => 2.25,
233
                        'step' => 0.125,
234
                    ],
235
                ],
236
                'selectors' => [
237
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-star' => '--glsr-summary-star: {{SIZE}}{{UNIT}};',
238
                ],
239
                'size_units' => $this->set_custom_size_unit(['em']),
240
                'type' => Controls_Manager::SLIDER,
241
            ],
242
        ];
243
    }
244
}
245