@@ -115,17 +115,17 @@ public function __construct(auth $auth, config $config, driver_interface $db, la
115115 public function get_ideas ($ number = 10 , $ sort = 'date ' , $ direction = 'DESC ' , $ status = [], $ start = 0 )
116116 {
117117 // Initialize a query to request ideas
118- $ this ->query_ideas ()
118+ $ sql = $ this ->query_ideas ()
119119 ->query_sort ($ sort , $ direction )
120120 ->query_status ($ status );
121121
122122 // For pagination, get a count of the total ideas being requested
123123 if ($ number >= $ this ->config ['posts_per_page ' ])
124124 {
125- $ this ->idea_count = $ this ->query_count ();
125+ $ this ->idea_count = $ sql ->query_count ();
126126 }
127127
128- $ ideas = $ this ->query_get ($ number , $ start );
128+ $ ideas = $ sql ->query_get ($ number , $ start );
129129
130130 if (count ($ ideas ))
131131 {
@@ -172,10 +172,11 @@ protected function query_ideas()
172172 /**
173173 * Update the $sql property with ORDER BY statements to obtain
174174 * the requested collection of Ideas. Some instances may add
175- * additional WHERE or SELECT statements.
175+ * additional WHERE or SELECT statements to refine the collection .
176176 *
177177 * @param string $sort A sorting option/collection
178178 * @param string $direction Will either be ASC or DESC
179+ *
179180 * @return \phpbb\ideas\factory\ideas $this For chaining calls
180181 */
181182 protected function query_sort ($ sort , $ direction )
@@ -184,7 +185,7 @@ protected function query_sort($sort, $direction)
184185 $ direction = $ direction === 'DESC ' ? 'DESC ' : 'ASC ' ;
185186
186187 // Most sorting relies on simple ORDER BY statements, but some may use a WHERE statement
187- $ sorting = [
188+ $ statements = [
188189 self ::SORT_DATE => ['ORDER_BY ' => 'i.idea_date ' ],
189190 self ::SORT_TITLE => ['ORDER_BY ' => 'i.idea_title ' ],
190191 self ::SORT_AUTHOR => ['ORDER_BY ' => 'i.idea_author ' ],
@@ -194,17 +195,17 @@ protected function query_sort($sort, $direction)
194195 self ::SORT_MYIDEAS => ['ORDER_BY ' => 'i.idea_date ' , 'WHERE ' => 'i.idea_author = ' . (int ) $ this ->user ->data ['user_id ' ]],
195196 ];
196197
197- // Append the new WHERE statement if the sort has one
198- if (isset ($ sorting [$ sort ]['WHERE ' ]))
198+ // Append a new WHERE statement if the sort has one
199+ if (isset ($ statements [$ sort ]['WHERE ' ]))
199200 {
200- $ this ->sql ['WHERE ' ][] = $ sorting [$ sort ]['WHERE ' ];
201+ $ this ->sql ['WHERE ' ][] = $ statements [$ sort ]['WHERE ' ];
201202 }
202203
203- // If we have an ORDER BY that is our sort mode . The absence of an ORDER BY
204- // means we will by default sort ideas based on their calculated score.
205- if (isset ($ sorting [$ sort ]['ORDER_BY ' ]))
204+ // If we have an ORDER BY we use that . The absence of an ORDER BY
205+ // means we will default to sorting ideas by their calculated score.
206+ if (isset ($ statements [$ sort ]['ORDER_BY ' ]))
206207 {
207- $ this ->sql ['ORDER_BY ' ] = "{$ sorting [$ sort ]['ORDER_BY ' ]} $ direction " ;
208+ $ this ->sql ['ORDER_BY ' ] = "{$ statements [$ sort ]['ORDER_BY ' ]} $ direction " ;
208209 }
209210 else
210211 {
@@ -214,7 +215,7 @@ protected function query_sort($sort, $direction)
214215 (i.idea_votes_up + i.idea_votes_down)) / (1 + 3.8416 / (i.idea_votes_up + i.idea_votes_down))
215216 AS ci_lower_bound ' ;
216217
217- $ this ->sql ['ORDER_BY ' ] = ' ci_lower_bound ' . $ direction ;
218+ $ this ->sql ['ORDER_BY ' ] = " ci_lower_bound $ direction" ;
218219 }
219220
220221 return $ this ;
@@ -225,6 +226,7 @@ protected function query_sort($sort, $direction)
225226 * the query to get ideas within or without certain statuses.
226227 *
227228 * @param array|int $status The id of the status(es) to load
229+ *
228230 * @return \phpbb\ideas\factory\ideas $this For chaining calls
229231 */
230232 protected function query_status ($ status = [])
@@ -243,10 +245,11 @@ protected function query_status($status = [])
243245 *
244246 * @param int $number The number of ideas to return
245247 * @param int $start Start value for pagination
248+ *
246249 * @return mixed Nested array if the query had rows, false otherwise
247250 * @throws \phpbb\exception\runtime_exception
248251 */
249- protected function query_get ($ number = 10 , $ start = 0 )
252+ protected function query_get ($ number , $ start )
250253 {
251254 if (empty ($ this ->sql ))
252255 {
@@ -257,7 +260,7 @@ protected function query_get($number = 10, $start = 0)
257260 FROM ' . $ this ->sql ['FROM ' ] . '
258261 INNER JOIN ' . $ this ->sql ['JOIN ' ] . '
259262 WHERE ' . implode (' AND ' , $ this ->sql ['WHERE ' ]) . '
260- ORDER BY ' . $ this ->db -> sql_escape ( $ this -> sql ['ORDER_BY ' ]) ;
263+ ORDER BY ' . $ this ->sql ['ORDER_BY ' ];
261264
262265 $ result = $ this ->db ->sql_query_limit ($ sql , $ number , $ start );
263266 $ rows = $ this ->db ->sql_fetchrowset ($ result );
@@ -283,6 +286,7 @@ protected function query_count()
283286 FROM ' . $ this ->sql ['FROM ' ] . '
284287 INNER JOIN ' . $ this ->sql ['JOIN ' ] . '
285288 WHERE ' . implode (' AND ' , $ this ->sql ['WHERE ' ]);
289+
286290 $ result = $ this ->db ->sql_query ($ sql );
287291 $ count = (int ) $ this ->db ->sql_fetchfield ('count ' );
288292 $ this ->db ->sql_freeresult ($ result );
0 commit comments