Passed
Push — master ( 6b8ca8...3384db )
by Paul
04:57
created

SiteReviewsSummaryWidget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 63
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A widget() 0 3 1
B form() 0 45 3
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Widgets;
4
5
use GeminiLabs\SiteReviews\Database;
6
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode;
7
use GeminiLabs\SiteReviews\Widgets\Widget;
8
9
class SiteReviewsSummaryWidget extends Widget
10
{
11
	/**
12
	 * @param array $instance
13
	 * @return void
14
	 */
15
	public function form( $instance )
16
	{
17
		$this->widgetArgs = glsr( SiteReviewsSummaryShortcode::class )->normalize( $instance );
18
		$terms = glsr( Database::class )->getTerms();
19
		$this->renderField( 'text', [
20
			'class' => 'widefat',
21
			'label' => __( 'Title', 'site-reviews' ),
22
			'name' => 'title',
23
		]);
24
		if( count( glsr()->reviewTypes ) > 1 ) {
25
			$this->renderField( 'select', [
26
				'class' => 'widefat',
27
				'label' => __( 'Which type of review would you like to use?', 'site-reviews' ),
28
				'name' => 'type',
29
				'options' => ['' => __( 'All review types', 'site-reviews' )] + glsr()->reviewTypes,
30
			]);
31
		}
32
		if( !empty( $terms )) {
33
			$this->renderField( 'select', [
34
				'class' => 'widefat',
35
				'label' => __( 'Limit summary to this category', 'site-reviews' ),
36
				'name' => 'category',
37
				'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms,
38
			]);
39
		}
40
		$this->renderField( 'text', [
41
			'class' => 'widefat',
42
			'default' => '',
43
			'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>' ),
44
			'label' => __( 'Limit summary to reviews assigned to a page/post ID', 'site-reviews' ),
45
			'name' => 'assigned_to',
46
		]);
47
		$this->renderField( 'text', [
48
			'class' => 'widefat',
49
			'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ),
50
			'name' => 'class',
51
		]);
52
		$this->renderField( 'checkbox', [
53
			'name' => 'hide',
54
			'options' => [
55
				'bars' => __( 'Hide the percentage bars?', 'site-reviews' ),
56
				'rating' => __( 'Hide the rating?', 'site-reviews' ),
57
				'stars' => __( 'Hide the stars?', 'site-reviews' ),
58
				'summary' => __( 'Hide the summary text?', 'site-reviews' ),
59
				'if_empty' => __( 'Hide the summary if no reviews are found?', 'site-reviews' ),
60
			],
61
		]);
62
	}
63
64
	/**
65
	 * @param array $args
66
	 * @param array $instance
67
	 * @return void
68
	 */
69
	public function widget( $args, $instance )
70
	{
71
		echo glsr( SiteReviewsSummaryShortcode::class )->build( $instance, $args );
72
	}
73
}
74