Passed
Push — renovate/configure ( c923d4...2c70da )
by
unknown
20:13
created

member_menu   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 121
rs 10
c 0
b 0
f 0
wmc 11

7 Methods

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