topposters::get_template_acp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
*
4
* @package Board3 Portal v2.1
5
* @copyright (c) 2013 Board3 Group ( www.board3.de )
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
namespace board3\portal\modules;
11
12
/**
13
* @package Topposters
14
*/
15
class topposters extends module_base
16
{
17
	/**
18
	* Allowed columns: Just sum up your options (Exp: left + right = 10)
19
	* top		1
20
	* left		2
21
	* center	4
22
	* right		8
23
	* bottom	16
24
	*/
25
	public $columns = 10;
26
27
	/**
28
	* Default modulename
29
	*/
30
	public $name = 'TOPPOSTERS';
31
32
	/**
33
	* Default module-image:
34
	* file must be in "{T_THEME_PATH}/images/portal/"
35
	*/
36
	public $image_src = 'portal_top_poster.png';
37
38
	/**
39
	* module-language file
40
	* file must be in "language/{$user->lang}/mods/portal/"
41
	*/
42
	public $language = 'portal_topposters_module';
43
44
	/** @var \phpbb\config\config */
45
	protected $config;
46
47
	/** @var \phpbb\db\driver\driver_interface */
48
	protected $db;
49
50
	/** @var \phpbb\template\template */
51
	protected $template;
52
53
	/** @var string PHP file extension */
54
	protected $php_ext;
55
56
	/** @var string phpBB root path */
57
	protected $phpbb_root_path;
58
59
	/**
60
	* Construct a topposers object
61
	*
62
	* @param \phpbb\config\config $config phpBB config
63
	* @param \phpbb\db\driver\driver_interface $db phpBB db driver
64
	* @param \phpbb\template\template $template phpBB template
65
	* @param string $phpbb_root_path phpBB root path
66
	* @param string $phpEx php file extension
67
	*/
68
	public function __construct($config, $db, $template, $phpbb_root_path, $phpEx)
69
	{
70
		$this->config = $config;
71
		$this->db = $db;
72
		$this->template = $template;
73
		$this->phpbb_root_path = $phpbb_root_path;
74
		$this->php_ext = $phpEx;
75
	}
76
77
	/**
78
	* {@inheritdoc}
79
	*/
80
	public function get_template_side($module_id)
81
	{
82
		$sql = 'SELECT user_id, username, user_posts, user_colour
83
			FROM ' . USERS_TABLE . '
84
			WHERE user_type <> ' . USER_IGNORE . "
85
				AND user_posts <> 0
86
				AND username <> ''
87
			ORDER BY user_posts DESC";
88
		$result = $this->db->sql_query_limit($sql, $this->config['board3_topposters_' . $module_id], 0, 600);
89
90
		while (($row = $this->db->sql_fetchrow($result)))
91
		{
92
			$this->template->assign_block_vars('topposters', array(
93
				'S_SEARCH_ACTION'	=> append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", 'author_id=' . $row['user_id'] . '&amp;sr=posts'),
94
				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
95
				'POSTER_POSTS'		=> $row['user_posts'],
96
			));
97
		}
98
		$this->db->sql_freeresult($result);
99
100
		return 'topposters_side.html';
101
	}
102
103
	/**
104
	* {@inheritdoc}
105
	*/
106
	public function get_template_acp($module_id)
107
	{
108
		return array(
109
			'title'	=> 'TOPPOSTERS_CONFIG',
110
			'vars'	=> array(
111
				'legend1'							=> 'TOPPOSTERS',
112
				'board3_topposters_' . $module_id	=> array('lang' => 'NUM_TOPPOSTERS',		'validate' => 'int',	'type' => 'text:3:3',		'explain' => true),
113
			),
114
		);
115
	}
116
117
	/**
118
	* {@inheritdoc}
119
	*/
120
	public function install($module_id)
121
	{
122
		$this->config->set('board3_topposters_' . $module_id, 5);
123
		return true;
124
	}
125
126
	/**
127
	* {@inheritdoc}
128
	*/
129 View Code Duplication
	public function uninstall($module_id, $db)
130
	{
131
		$del_config = array(
132
			'board3_topposters_' . $module_id,
133
		);
134
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
135
			WHERE ' . $db->sql_in_set('config_name', $del_config);
136
		return $db->sql_query($sql);
137
	}
138
}
139