@@ -10,184 +10,184 @@ |
||
10 | 10 | |
11 | 11 | class Columns |
12 | 12 | { |
13 | - /** |
|
14 | - * @param int $postId |
|
15 | - * @return void|string |
|
16 | - */ |
|
17 | - public function buildColumnAssignedTo($postId) |
|
18 | - { |
|
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
24 | - } |
|
25 | - } |
|
13 | + /** |
|
14 | + * @param int $postId |
|
15 | + * @return void|string |
|
16 | + */ |
|
17 | + public function buildColumnAssignedTo($postId) |
|
18 | + { |
|
19 | + $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | + if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | + return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | + 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | + ]); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $postId |
|
29 | - * @return void|string |
|
30 | - */ |
|
31 | - public function buildColumnEmail($postId) |
|
32 | - { |
|
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | - return $email; |
|
35 | - } |
|
36 | - } |
|
27 | + /** |
|
28 | + * @param int $postId |
|
29 | + * @return void|string |
|
30 | + */ |
|
31 | + public function buildColumnEmail($postId) |
|
32 | + { |
|
33 | + if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | + return $email; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $postId |
|
40 | - * @return void|string |
|
41 | - */ |
|
42 | - public function buildColumnIpAddress($postId) |
|
43 | - { |
|
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | - return $ipAddress; |
|
46 | - } |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param int $postId |
|
40 | + * @return void|string |
|
41 | + */ |
|
42 | + public function buildColumnIpAddress($postId) |
|
43 | + { |
|
44 | + if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | + return $ipAddress; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $postId |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function buildColumnPinned($postId) |
|
54 | - { |
|
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | - ? 'pinned ' |
|
57 | - : ''; |
|
58 | - if (glsr()->can('edit_others_posts')) { |
|
59 | - $pinned.= 'pin-review '; |
|
60 | - } |
|
61 | - return glsr(Builder::class)->i([ |
|
62 | - 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | - 'data-id' => $postId, |
|
64 | - ]); |
|
65 | - } |
|
49 | + /** |
|
50 | + * @param int $postId |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function buildColumnPinned($postId) |
|
54 | + { |
|
55 | + $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | + ? 'pinned ' |
|
57 | + : ''; |
|
58 | + if (glsr()->can('edit_others_posts')) { |
|
59 | + $pinned.= 'pin-review '; |
|
60 | + } |
|
61 | + return glsr(Builder::class)->i([ |
|
62 | + 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | + 'data-id' => $postId, |
|
64 | + ]); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param int $postId |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function buildColumnResponse($postId) |
|
72 | - { |
|
73 | - return glsr(Database::class)->get($postId, 'response') |
|
74 | - ? __('Yes', 'site-reviews') |
|
75 | - : __('No', 'site-reviews'); |
|
76 | - } |
|
67 | + /** |
|
68 | + * @param int $postId |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function buildColumnResponse($postId) |
|
72 | + { |
|
73 | + return glsr(Database::class)->get($postId, 'response') |
|
74 | + ? __('Yes', 'site-reviews') |
|
75 | + : __('No', 'site-reviews'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param int $postId |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function buildColumnReviewer($postId) |
|
83 | - { |
|
84 | - $author = strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | - $userId = Helper::castToInt(get_post($postId)->post_author); |
|
86 | - return !empty($userId) |
|
87 | - ? glsr(Builder::class)->a($author, ['href' => get_author_posts_url($userId)]) |
|
88 | - : $author; |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param int $postId |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function buildColumnReviewer($postId) |
|
83 | + { |
|
84 | + $author = strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | + $userId = Helper::castToInt(get_post($postId)->post_author); |
|
86 | + return !empty($userId) |
|
87 | + ? glsr(Builder::class)->a($author, ['href' => get_author_posts_url($userId)]) |
|
88 | + : $author; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param int $postId |
|
93 | - * @param int|null $rating |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function buildColumnRating($postId) |
|
97 | - { |
|
98 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
99 | - } |
|
91 | + /** |
|
92 | + * @param int $postId |
|
93 | + * @param int|null $rating |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function buildColumnRating($postId) |
|
97 | + { |
|
98 | + return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param int $postId |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function buildColumnReviewType($postId) |
|
106 | - { |
|
107 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
108 | - return array_key_exists($type, glsr()->reviewTypes) |
|
109 | - ? glsr()->reviewTypes[$type] |
|
110 | - : __('Unsupported Type', 'site-reviews'); |
|
111 | - } |
|
101 | + /** |
|
102 | + * @param int $postId |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function buildColumnReviewType($postId) |
|
106 | + { |
|
107 | + $type = glsr(Database::class)->get($postId, 'review_type'); |
|
108 | + return array_key_exists($type, glsr()->reviewTypes) |
|
109 | + ? glsr()->reviewTypes[$type] |
|
110 | + : __('Unsupported Type', 'site-reviews'); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $postType |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public function renderFilters($postType) |
|
118 | - { |
|
119 | - if (Application::POST_TYPE !== $postType) { |
|
120 | - return; |
|
121 | - } |
|
122 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
123 | - $status = 'publish'; |
|
124 | - } |
|
125 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
126 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
127 | - $this->renderFilterRatings($ratings); |
|
128 | - $this->renderFilterTypes($types); |
|
129 | - } |
|
113 | + /** |
|
114 | + * @param string $postType |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public function renderFilters($postType) |
|
118 | + { |
|
119 | + if (Application::POST_TYPE !== $postType) { |
|
120 | + return; |
|
121 | + } |
|
122 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
123 | + $status = 'publish'; |
|
124 | + } |
|
125 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
126 | + $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
127 | + $this->renderFilterRatings($ratings); |
|
128 | + $this->renderFilterTypes($types); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param string $column |
|
133 | - * @param int $postId |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function renderValues($column, $postId) |
|
137 | - { |
|
138 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
139 | - $value = method_exists($this, $method) |
|
140 | - ? call_user_func([$this, $method], $postId) |
|
141 | - : ''; |
|
142 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
143 | - if (0 !== $value && empty($value)) { |
|
144 | - $value = '—'; |
|
145 | - } |
|
146 | - echo $value; |
|
147 | - } |
|
131 | + /** |
|
132 | + * @param string $column |
|
133 | + * @param int $postId |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function renderValues($column, $postId) |
|
137 | + { |
|
138 | + $method = Helper::buildMethodName($column, 'buildColumn'); |
|
139 | + $value = method_exists($this, $method) |
|
140 | + ? call_user_func([$this, $method], $postId) |
|
141 | + : ''; |
|
142 | + $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
143 | + if (0 !== $value && empty($value)) { |
|
144 | + $value = '—'; |
|
145 | + } |
|
146 | + echo $value; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param array $ratings |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - protected function renderFilterRatings($ratings) |
|
154 | - { |
|
155 | - if (empty($ratings)) { |
|
156 | - return; |
|
157 | - } |
|
158 | - $ratings = array_flip(array_reverse($ratings)); |
|
159 | - array_walk($ratings, function (&$value, $key) { |
|
160 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
161 | - $value = sprintf($label, $key); |
|
162 | - }); |
|
163 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
164 | - 'class' => 'screen-reader-text', |
|
165 | - 'for' => 'rating', |
|
166 | - ]); |
|
167 | - echo glsr(Builder::class)->select([ |
|
168 | - 'name' => 'rating', |
|
169 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
170 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
171 | - ]); |
|
172 | - } |
|
149 | + /** |
|
150 | + * @param array $ratings |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + protected function renderFilterRatings($ratings) |
|
154 | + { |
|
155 | + if (empty($ratings)) { |
|
156 | + return; |
|
157 | + } |
|
158 | + $ratings = array_flip(array_reverse($ratings)); |
|
159 | + array_walk($ratings, function (&$value, $key) { |
|
160 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
161 | + $value = sprintf($label, $key); |
|
162 | + }); |
|
163 | + echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
164 | + 'class' => 'screen-reader-text', |
|
165 | + 'for' => 'rating', |
|
166 | + ]); |
|
167 | + echo glsr(Builder::class)->select([ |
|
168 | + 'name' => 'rating', |
|
169 | + 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
170 | + 'value' => filter_input(INPUT_GET, 'rating'), |
|
171 | + ]); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @param array $types |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - protected function renderFilterTypes($types) |
|
179 | - { |
|
180 | - if (count(glsr()->reviewTypes) < 2) { |
|
181 | - return; |
|
182 | - } |
|
183 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
184 | - 'class' => 'screen-reader-text', |
|
185 | - 'for' => 'review_type', |
|
186 | - ]); |
|
187 | - echo glsr(Builder::class)->select([ |
|
188 | - 'name' => 'review_type', |
|
189 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
190 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
191 | - ]); |
|
192 | - } |
|
174 | + /** |
|
175 | + * @param array $types |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + protected function renderFilterTypes($types) |
|
179 | + { |
|
180 | + if (count(glsr()->reviewTypes) < 2) { |
|
181 | + return; |
|
182 | + } |
|
183 | + echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
184 | + 'class' => 'screen-reader-text', |
|
185 | + 'for' => 'review_type', |
|
186 | + ]); |
|
187 | + echo glsr(Builder::class)->select([ |
|
188 | + 'name' => 'review_type', |
|
189 | + 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
190 | + 'value' => filter_input(INPUT_GET, 'review_type'), |
|
191 | + ]); |
|
192 | + } |
|
193 | 193 | } |