@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function decrease( array $reviewCounts, $type, $rating ) |
48 | 48 | { |
49 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
49 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
50 | 50 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
51 | 51 | } |
52 | 52 | return $reviewCounts; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | public function flatten( array $reviewCounts ) |
59 | 59 | { |
60 | 60 | $counts = []; |
61 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
62 | - $counts[$index] = isset( $counts[$index] ) |
|
61 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
62 | + $counts[$index] = isset($counts[$index]) |
|
63 | 63 | ? $num + $counts[$index] |
64 | 64 | : $num; |
65 | 65 | }); |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function increase( array $reviewCounts, $type, $rating ) |
101 | 101 | { |
102 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
102 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
103 | 103 | return $reviewCounts; |
104 | 104 | } |
105 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
105 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
106 | 106 | $reviewCounts[$type] = []; |
107 | 107 | } |
108 | 108 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | { |
145 | 145 | $counts = []; |
146 | 146 | $lastPostId = 0; |
147 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
148 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
147 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
148 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
149 | 149 | foreach( $types as $type ) { |
150 | - if( isset( $counts[$type] ))continue; |
|
150 | + if( isset($counts[$type]) )continue; |
|
151 | 151 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
152 | 152 | } |
153 | 153 | foreach( $reviews as $review ) { |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | { |
166 | 166 | foreach( $reviewCounts as &$counts ) { |
167 | 167 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
168 | - if( isset( $counts[$index] ))continue; |
|
168 | + if( isset($counts[$index]) )continue; |
|
169 | 169 | $counts[$index] = 0; |
170 | 170 | } |
171 | 171 | ksort( $counts ); |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
182 | 182 | { |
183 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
184 | - if( empty( array_filter( $args ))) { |
|
183 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
184 | + if( empty(array_filter( $args )) ) { |
|
185 | 185 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
186 | 186 | } |
187 | - if( !empty( $args['post_id'] )) { |
|
187 | + if( !empty($args['post_id']) ) { |
|
188 | 188 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
189 | 189 | } |
190 | - if( !empty( $args['term_id'] )) { |
|
190 | + if( !empty($args['term_id']) ) { |
|
191 | 191 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
192 | 192 | } |
193 | 193 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function deleteAllSessions( $sessionCookiePrefix ) |
25 | 25 | { |
26 | - return $this->db->query(" |
|
26 | + return $this->db->query( " |
|
27 | 27 | DELETE |
28 | 28 | FROM {$this->db->options} |
29 | 29 | WHERE option_name LIKE '{$sessionCookiePrefix}_%' |
30 | - "); |
|
30 | + " ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function deleteExpiredSessions( $expiredSessions ) |
38 | 38 | { |
39 | - return $this->db->query(" |
|
39 | + return $this->db->query( " |
|
40 | 40 | DELETE |
41 | 41 | FROM {$this->db->options} |
42 | 42 | WHERE option_name IN ('{$expiredSessions}') |
43 | - "); |
|
43 | + " ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function getReviewCountsFor( $metaKey ) |
51 | 51 | { |
52 | - return (array) $this->db->get_results(" |
|
52 | + return (array)$this->db->get_results( " |
|
53 | 53 | SELECT m.meta_value AS name, COUNT(*) num_posts |
54 | 54 | FROM {$this->db->posts} AS p |
55 | 55 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
56 | 56 | WHERE p.post_type = '{$this->postType}' |
57 | 57 | AND m.meta_key = '{$metaKey}' |
58 | 58 | GROUP BY name |
59 | - "); |
|
59 | + " ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getExpiredSessions( $sessionCookiePrefix, $limit ) |
68 | 68 | { |
69 | - return $this->db->get_results(" |
|
69 | + return $this->db->get_results( " |
|
70 | 70 | SELECT option_name AS name, option_value AS expiration |
71 | 71 | FROM {$this->db->options} |
72 | 72 | WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%' |
73 | 73 | ORDER BY option_value ASC |
74 | 74 | LIMIT 0, {$limit} |
75 | - "); |
|
75 | + " ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getReviewCounts( $lastPostId = 0, $limit = 500 ) |
84 | 84 | { |
85 | - return $this->db->get_results(" |
|
85 | + return $this->db->get_results( " |
|
86 | 86 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
87 | 87 | FROM {$this->db->posts} AS p |
88 | 88 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getReviewPostId( $metaReviewId ) |
105 | 105 | { |
106 | - $postId = $this->db->get_var(" |
|
106 | + $postId = $this->db->get_var( " |
|
107 | 107 | SELECT p.ID |
108 | 108 | FROM {$this->db->posts} AS p |
109 | 109 | INNER JOIN {$this->db->postmeta} AS pm ON p.ID = pm.post_id |
110 | 110 | WHERE p.post_type = '{$this->postType}' |
111 | 111 | AND pm.meta_key = 'review_id' |
112 | 112 | AND pm.meta_value = '{$metaReviewId}' |
113 | - "); |
|
113 | + " ); |
|
114 | 114 | return intval( $postId ); |
115 | 115 | } |
116 | 116 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getReviewIdsByType( $reviewType ) |
122 | 122 | { |
123 | - $query = $this->db->get_col(" |
|
123 | + $query = $this->db->get_col( " |
|
124 | 124 | SELECT m1.meta_value AS review_id |
125 | 125 | FROM {$this->db->posts} AS p |
126 | 126 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | AND m1.meta_key = 'review_id' |
130 | 130 | AND m2.meta_key = 'review_type' |
131 | 131 | AND m2.meta_value = '{$reviewType}' |
132 | - "); |
|
133 | - return array_keys( array_flip( $query )); |
|
132 | + " ); |
|
133 | + return array_keys( array_flip( $query ) ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function getReviewPostCounts( $postId, $lastPostId = 0, $limit = 500 ) |
143 | 143 | { |
144 | - return $this->db->get_results(" |
|
144 | + return $this->db->get_results( " |
|
145 | 145 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
146 | 146 | FROM {$this->db->posts} AS p |
147 | 147 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
168 | 168 | { |
169 | 169 | sort( $postIds ); |
170 | - $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds )), $limit ); |
|
170 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
171 | 171 | $postIds = implode( ',', $postIds ); |
172 | - return $this->db->get_results(" |
|
172 | + return $this->db->get_results( " |
|
173 | 173 | SELECT p.ID, m.meta_value AS rating |
174 | 174 | FROM {$this->db->posts} AS p |
175 | 175 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $queryBuilder = glsr( QueryBuilder::class ); |
194 | 194 | $key = $queryBuilder->buildSqlOr( $key, "m.meta_key = '%s'" ); |
195 | 195 | $status = $queryBuilder->buildSqlOr( $status, "p.post_status = '%s'" ); |
196 | - return $this->db->get_col(" |
|
196 | + return $this->db->get_col( " |
|
197 | 197 | SELECT DISTINCT m.meta_value |
198 | 198 | FROM {$this->db->postmeta} m |
199 | 199 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | AND ({$key}) |
202 | 202 | AND ({$status}) |
203 | 203 | ORDER BY m.meta_value |
204 | - "); |
|
204 | + " ); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function getReviewTermCounts( $termId, $lastPostId = 0, $limit = 500 ) |
214 | 214 | { |
215 | - return $this->db->get_results(" |
|
215 | + return $this->db->get_results( " |
|
216 | 216 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
217 | 217 | FROM {$this->db->posts} AS p |
218 | 218 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |