From 972ad7ae5d5e8021dc6c88afafe40e49616235f4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 16 Nov 2013 10:42:30 +0100 Subject: [PATCH] [feature/module_services] Move latest_bots to module services --- config/services.yml | 10 +++ migrations/v210_beta1.php | 2 +- .../latest_bots.php | 64 +++++++++++++------ 3 files changed, 57 insertions(+), 19 deletions(-) rename portal/modules/portal_latest_bots.php => modules/latest_bots.php (63%) mode change 100755 => 100644 diff --git a/config/services.yml b/config/services.yml index e6ce6fc5..495d6c82 100644 --- a/config/services.yml +++ b/config/services.yml @@ -125,6 +125,16 @@ services: tags: - { name: board3.module } + board3.module.latest_bots: + class: \board3\portal\modules\latest_bots + arguments: + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + board3.module.stylechanger: class: \board3\portal\modules\stylechanger arguments: diff --git a/migrations/v210_beta1.php b/migrations/v210_beta1.php index 595c2fdd..d59d5fd0 100644 --- a/migrations/v210_beta1.php +++ b/migrations/v210_beta1.php @@ -512,7 +512,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'latest_bots', + 'module_classname' => '\board3\portal\modules\latest_bots', 'module_column' => 3, 'module_order' => 5, 'module_name' => 'LATEST_BOTS', diff --git a/portal/modules/portal_latest_bots.php b/modules/latest_bots.php old mode 100755 new mode 100644 similarity index 63% rename from portal/modules/portal_latest_bots.php rename to modules/latest_bots.php index 00879c16..72fc4d61 --- a/portal/modules/portal_latest_bots.php +++ b/modules/latest_bots.php @@ -1,24 +1,18 @@ config = $config; + $this->db = $db; + $this->template = $template; + $this->user = $user; + } + + /** + * @inheritdoc + */ public function get_template_side($module_id) { - global $config, $template, $db, $user; - // Last x visited bots $sql = 'SELECT username, user_colour, user_lastvisit FROM ' . USERS_TABLE . ' WHERE user_type = ' . USER_IGNORE . ' AND user_lastvisit > 0 ORDER BY user_lastvisit DESC'; - $result = $db->sql_query_limit($sql, $config['board3_last_visited_bots_number_' . $module_id]); + $result = $this->db->sql_query_limit($sql, $this->config['board3_last_visited_bots_number_' . $module_id]); $show_module = false; - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - $template->assign_block_vars('last_visited_bots', array( + $this->template->assign_block_vars('last_visited_bots', array( 'BOT_NAME' => get_username_string('full', '', $row['username'], $row['user_colour']), - 'LAST_VISIT_DATE' => $user->format_date($row['user_lastvisit']), + 'LAST_VISIT_DATE' => $this->user->format_date($row['user_lastvisit']), )); $show_module = true; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - if($show_module) + if ($show_module) { return 'latest_bots_side.html'; } } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -95,7 +120,7 @@ class portal_latest_bots_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { @@ -103,6 +128,9 @@ class portal_latest_bots_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id, $db) { $del_config = array(