Completed
Push — master ( cbbc79...7e8448 )
by Daniel
08:03
created

member_menu   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 6
c 4
b 1
f 2
lcom 1
cbo 3
dl 0
loc 89
ccs 40
cts 40
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B display() 0 29 4
A get_new_posts_count() 0 17 1
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\blocks;
11
12
use blitze\sitemaker\services\blocks\driver\block;
13
14
/**
15
 * Featured Member Block
16
 */
17
class member_menu extends block
18
{
19
	/** @var \phpbb\auth\auth */
20
	protected $auth;
21
22
	/** @var \phpbb\user */
23
	protected $user;
24
25
	/** @var \blitze\sitemaker\services\forum\data */
26
	protected $forum_data;
27
28
	/** @var string */
29
	protected $phpbb_root_path;
30
31
	/** @var string */
32
	protected $php_ext;
33
34
	/**
35
	 * Constructor
36
	 *
37
	 * @param \phpbb\auth\auth							$auth				Permission object
38
	 * @param \phpbb\user								$user				User object
39
	 * @param \blitze\sitemaker\services\forum\data		$forum_data			Forum Data object
40
	 * @param string									$phpbb_root_path	Path to the phpbb includes directory.
41
	 * @param string									$php_ext			php file extension
42
	 */
43 3
	public function __construct(\phpbb\auth\auth $auth, \phpbb\user $user, \blitze\sitemaker\services\forum\data $forum_data, $phpbb_root_path, $php_ext)
44
	{
45 3
		$this->auth = $auth;
46 3
		$this->user = $user;
47 3
		$this->forum_data = $forum_data;
48 3
		$this->phpbb_root_path = $phpbb_root_path;
49 3
		$this->php_ext = $php_ext;
50 3
	}
51
52
	/**
53
	 * {@inheritdoc}
54
	 */
55 2
	public function display(array $bdata, $edit_mode = false)
56
	{
57 2
		$content = '';
58 2
		if ($this->user->data['is_registered'])
59 2
		{
60 1
			$this->ptemplate->assign_vars(array(
61 1
				'USER_AVATAR'	=> phpbb_get_user_avatar($this->user->data),
62 1
				'USERNAME'		=> get_username_string('no_profile', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']),
63 1
				'USERNAME_FULL' => get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']),
64 1
				'USER_POSTS'	=> $this->user->data['user_posts'],
65 1
				'NEW_POSTS'		=> $this->get_new_posts_count(),
66
67 1
				'U_PROFILE'		=> append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, 'mode=viewprofile&amp;u=' . $this->user->data['user_id']),
68 1
				'U_SEARCH_NEW'	=> append_sid($this->phpbb_root_path . 'search.' . $this->php_ext, 'search_id=newposts'),
69 1
				'U_SEARCH_SELF'	=> append_sid($this->phpbb_root_path . 'search.' . $this->php_ext, 'search_id=egosearch'),
70 1
				'U_PRIVATE_MSG'	=> append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, 'i=pm&amp;folder=inbox'),
71 1
				'U_LOGOUT'		=> append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, 'mode=logout', true, $this->user->session_id),
72 1
				'U_MCP' 		=> ($this->auth->acl_get('m_')) ? append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, false, true, $this->user->session_id) : '',
73 1
				'U_ACP'			=> ($this->auth->acl_get('a_')) ? append_sid($this->phpbb_root_path . 'adm/index.' . $this->php_ext, 'i=-blitze-sitemaker-acp-menu_module', true, $this->user->session_id) : '')
74 1
			);
75
76 1
			$content = $this->ptemplate->render_view('blitze/sitemaker', 'blocks/member_menu.html', 'member_menu_block');
77 1
		}
78
79
		return array(
80 2
			'title'		=> 'WELCOME',
81 2
			'content'	=> $content,
82 2
		);
83
	}
84
85
	/**
86
	 * @return int
87
	 */
88 1
	protected function get_new_posts_count()
89
	{
90
		$sql_array = array(
91
			'FROM'		=> array(
92 1
				POSTS_TABLE		=> 'p',
93 1
			),
94
			'WHERE'		=> array(
95 1
				't.topic_id = p.topic_id AND p.post_time > ' . $this->user->data['user_lastvisit'],
96 1
			),
97 1
		);
98
99 1
		$this->forum_data->query(false)
100 1
			->fetch_custom($sql_array)
101 1
			->build(true, false);
102
103 1
		return (int) $this->forum_data->get_topics_count();
104
	}
105
}
106