1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Html; |
4
|
|
|
|
5
|
|
|
use ArrayObject; |
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Partial; |
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
8
|
|
|
use GeminiLabs\SiteReviews\Reviews; |
9
|
|
|
|
10
|
|
|
class ReviewsHtml extends ArrayObject |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
public $args; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
public $navigation; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
public $reviews; |
26
|
|
|
|
27
|
|
|
public function __construct( array $reviews, $maxPageCount, array $args ) |
28
|
|
|
{ |
29
|
|
|
$this->args = $args; |
30
|
|
|
$this->reviews = $reviews; |
31
|
|
|
$this->navigation = glsr( Partial::class )->build( 'pagination', [ |
32
|
|
|
'total' => $maxPageCount, |
33
|
|
|
]); |
34
|
|
|
parent::__construct( $reviews, ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function __get( $key ) |
41
|
|
|
{ |
42
|
|
|
return array_key_exists( $key, $this->reviews ) |
43
|
|
|
? $this->reviews[$key] |
44
|
|
|
: ''; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function __toString() |
51
|
|
|
{ |
52
|
|
|
return glsr( Template::class )->build( 'templates/reviews', [ |
53
|
|
|
'context' => [ |
54
|
|
|
'assigned_to' => $this->args['assigned_to'], |
55
|
|
|
'class' => $this->getClass(), |
56
|
|
|
'id' => $this->args['id'], |
57
|
|
|
'navigation' => $this->getNavigation(), |
58
|
|
|
'reviews' => implode( PHP_EOL, $this->reviews ), |
59
|
|
|
], |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
protected function getClass() |
67
|
|
|
{ |
68
|
|
|
$defaults = [ |
69
|
|
|
'glsr-reviews', 'glsr-default', |
70
|
|
|
]; |
71
|
|
|
if( $this->args['pagination'] == 'ajax' ) { |
72
|
|
|
$defaults[] = 'glsr-ajax-pagination'; |
73
|
|
|
} |
74
|
|
|
$classes = explode( ' ', $this->args['class'] ); |
75
|
|
|
$classes = array_unique( array_merge( $defaults, $classes )); |
76
|
|
|
return implode( ' ', $classes ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function getNavigation() |
83
|
|
|
{ |
84
|
|
|
return wp_validate_boolean( $this->args['pagination'] ) |
85
|
|
|
? $this->navigation |
86
|
|
|
: ''; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|