From 48f526716a5144c4182969a5daba4c8f2cae6d98 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Jan 2015 18:37:48 +0100 Subject: [PATCH] [ticket/432] Add method for selecting correct string in news constraints B3P-432 --- portal/fetch_posts.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/portal/fetch_posts.php b/portal/fetch_posts.php index 59d48903..2f3c8dd1 100644 --- a/portal/fetch_posts.php +++ b/portal/fetch_posts.php @@ -398,9 +398,9 @@ class fetch_posts { $this->topic_type = 't.topic_type = ' . POST_NORMAL; $this->where_string = (strlen($this->where_string) > 0) ? 'AND (' . trim(substr($this->where_string, 0, -4)) . ')' : ''; - $this->user_link = ($this->config['board3_news_style_' . $this->module_id]) ? 't.topic_poster = u.user_id' : (($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_poster_id = u.user_id' : 't.topic_poster = u.user_id' ) ; - $this->post_link = ($this->config['board3_news_style_' . $this->module_id]) ? 't.topic_first_post_id = p.post_id' : (($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_post_id = p.post_id' : 't.topic_first_post_id = p.post_id' ) ; - $this->topic_order = ($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_post_time DESC' : 't.topic_time DESC' ; + $this->user_link = $this->get_setting_based_string($this->config['board3_news_style_' . $this->module_id], 't.topic_poster = u.user_id', $this->get_setting_based_string($this->config['board3_news_show_last_' . $this->module_id], 't.topic_last_poster_id = u.user_id', 't.topic_poster = u.user_id')) ; + $this->post_link = $this->get_setting_based_string($this->config['board3_news_style_' . $this->module_id], 't.topic_first_post_id = p.post_id', $this->get_setting_based_string($this->config['board3_news_show_last_' . $this->module_id], 't.topic_last_post_id = p.post_id', 't.topic_first_post_id = p.post_id')); + $this->topic_order = $this->get_setting_based_string($this->config['board3_news_show_last_' . $this->module_id], 't.topic_last_post_time DESC', 't.topic_time DESC'); } /** @@ -545,4 +545,18 @@ class fetch_posts { $this->where_string = ''; } + + /** + * Get valid string based on setting + * + * @param string $setting Setting to check + * @param string $string_on String if setting is on + * @param string $string_off String if setting is off + * + * @return string Valid string based on setting + */ + protected function get_setting_based_string($setting, $string_on, $string_off) + { + return (!empty($setting)) ? $string_on : $string_off; + } }