Completed
Push — master ( de120c...f5f15c )
by
unknown
13s queued 11s
created

linkhelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get_idea_link() 0 8 3
A get_user_link() 0 5 1
1
<?php
2
/**
3
 *
4
 * Ideas extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ideas\factory;
12
13
use phpbb\controller\helper;
14
use phpbb\user_loader;
15
16
class linkhelper
17
{
18
	/* @var helper */
19
	protected $helper;
20
21
	/* @var user_loader */
22
	protected $user_loader;
23
24
	/**
25
	 * @param \phpbb\controller\helper $helper
26
	 * @param \phpbb\user_loader       $user_loader
27
	 */
28
	public function __construct(helper $helper, user_loader $user_loader)
29
	{
30
		$this->helper = $helper;
31
		$this->user_loader = $user_loader;
32
	}
33
34
	/**
35
	 * Shortcut method to get the link to a specified idea.
36
	 * Optionally add mode and hash URL arguments.
37
	 *
38
	 * @param int    $idea_id The ID of the idea
39
	 * @param string $mode    The mode argument (vote, delete, etc.)
40
	 * @param bool   $hash    Add a link hash
41
	 * @return string The route
42
	 */
43
	public function get_idea_link($idea_id, $mode = '', $hash = false)
44
	{
45
		$params = array('idea_id' => $idea_id);
46
		$params = $mode ? array_merge($params, array('mode' => $mode)) : $params;
47
		$params = $hash ? array_merge($params, array('hash' => generate_link_hash("{$mode}_{$idea_id}"))) : $params;
48
49
		return $this->helper->route('phpbb_ideas_idea_controller', $params);
50
	}
51
52
	/**
53
	 * Returns a link to the users profile, complete with colour.
54
	 *
55
	 * Is there a function that already does this? This seems fairly database heavy.
56
	 *
57
	 * @param int $id The ID of the user
58
	 * @return string An HTML link to the users profile
59
	 */
60
	public function get_user_link($id)
61
	{
62
		$this->user_loader->load_users(array($id));
63
		return $this->user_loader->get_username($id, 'full');
64
	}
65
}
66