Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created

SiteReviewsSummaryWidget::widget()   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
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Widgets;
4
5
use GeminiLabs\SiteReviews\Database;
6
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode;
7
8
class SiteReviewsSummaryWidget extends Widget
9
{
10
    /**
11
     * @param array $instance
12
     * @return void
13
     */
14
    public function form($instance)
15
    {
16
        $this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
        $terms = glsr(Database::class)->getTerms();
18
        $this->renderField('text', [
19
            'class' => 'widefat',
20
            'label' => __('Title', 'site-reviews'),
21
            'name' => 'title',
22
        ]);
23
        if (count(glsr()->reviewTypes) > 1) {
24
            $this->renderField('select', [
25
                'class' => 'widefat',
26
                'label' => __('Which type of review would you like to use?', 'site-reviews'),
27
                'name' => 'type',
28
                'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes,
29
            ]);
30
        }
31
        if (!empty($terms)) {
32
            $this->renderField('select', [
33
                'class' => 'widefat',
34
                'label' => __('Limit summary to this category', 'site-reviews'),
35
                'name' => 'category',
36
                'options' => ['' => __('All Categories', 'site-reviews')] + $terms,
37
            ]);
38
        }
39
        $this->renderField('text', [
40
            'class' => 'widefat',
41
            'default' => '',
42
            'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'),
43
            'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'),
44
            'name' => 'assigned_to',
45
        ]);
46
        $this->renderField('text', [
47
            'class' => 'widefat',
48
            'label' => __('Enter any custom CSS classes here', 'site-reviews'),
49
            'name' => 'class',
50
        ]);
51
        $this->renderField('checkbox', [
52
            'name' => 'hide',
53
            'options' => $this->shortcode()->getHideOptions(),
54
        ]);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    protected function shortcode()
61
    {
62
        return glsr(SiteReviewsSummaryShortcode::class);
63
    }
64
}
65