Completed
Push — master ( 1f1439...c96b51 )
by Daniel
08:29
created

profilefields   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 93
ccs 36
cts 36
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A get_all_fields() 0 21 2
A get_template_data() 0 20 3
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\services;
11
12
class profilefields
13
{
14
	/** @var \phpbb\db\driver\driver_interface */
15
	protected $db;
16
17
	/** @var \phpbb\profilefields\manager */
18
	protected $manager;
19
20
	/** @var \phpbb\user */
21
	protected $user;
22
23
	/** @var string */
24
	protected $phpbb_root_path;
25
26
	/** @var string */
27
	protected $php_ext;
28
29
	/**
30
	 * Constructor
31
	 *
32
	 * @param \phpbb\db\driver\driver_interface		$db	 					Database connection
33
	 * @param \phpbb\profilefields\manager			$manager				Profile fields manager object
34
	 * @param \phpbb\user							$user					User object
35
	 * @param string								$phpbb_root_path		Path to the phpbb includes directory.
36
	 * @param string								$php_ext				php file extension
37
	 */
38 8
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\profilefields\manager $manager, \phpbb\user $user, $phpbb_root_path, $php_ext)
39
	{
40 8
		$this->db = $db;
41 8
		$this->manager = $manager;
42 8
		$this->user = $user;
43 8
		$this->phpbb_root_path = $phpbb_root_path;
44 8
		$this->php_ext = $php_ext;
45
46 8
		if (!function_exists('phpbb_show_profile'))
47 8
		{
48 1
			include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
49 1
		}
50 8
	}
51
52
	/**
53
	 * @return array
54
	 */
55 1
	public function get_all_fields()
56
	{
57
		$sql = 'SELECT l.lang_name, f.field_ident
58 1
			FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
59 1
			WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . '
60
				AND f.field_active = 1
61
				AND f.field_no_view = 0
62
				AND f.field_hide = 0
63
				AND l.field_id = f.field_id
64 1
			ORDER BY f.field_order';
65 1
		$result = $this->db->sql_query($sql);
66
67 1
		$cpf_options = false;
68 1
		while ($row = $this->db->sql_fetchrow($result))
69
		{
70 1
			$cpf_options[$row['field_ident']] = $row['lang_name'];
71 1
		}
72 1
		$this->db->sql_freeresult($result);
73
74 1
		return $cpf_options;
75
	}
76
77
	/**
78
	 * Get profile fields template data for specified user
79
	 *
80
	 * @param int $user_id
81
	 * @param array $custom_fields
82
	 * @return array
83
	 */
84 7
	public function get_template_data($user_id, array $custom_fields)
85
	{
86
		$data = array(
87 7
			'row'		=> array(),
88 7
			'blockrow'	=> array(),
89 7
		);
90
91 7
		if (sizeof($custom_fields))
92 7
		{
93 1
			$fields_data = $this->manager->grab_profile_fields_data($user_id);
94
95 1
			if (sizeof($fields_data))
96 1
			{
97 1
				$fields_data = array_intersect_key(array_shift($fields_data), array_flip($custom_fields));
98 1
				$data = $this->manager->generate_profile_fields_template_data($fields_data);
99 1
			}
100 1
		}
101
102 7
		return $data;
103
	}
104
}
105