abstract_module   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 67
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A show_ucp_complete() 0 21 3
A check_table_for_user() 0 11 2
1
<?php
2
/**
3
 *
4
 * 2FA extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015 Paul Sohier
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
12
namespace paul999\tfa\modules;
13
14
use phpbb\db\driver\driver_interface;
15
use phpbb\template\template;
16
use phpbb\user;
17
18
abstract class abstract_module implements module_interface
19
{
20
	/**
21
	 * @var driver_interface
22
	 */
23
	protected $db;
24
25
	/**
26
	 * @var user
27
	 */
28
	protected $user;
29
30
	/**
31
	 * @var template
32
	 */
33
	protected $template;
34
35
	/**
36
	 * This method is called to show the UCP page.
37
	 * You can assign template variables to the template, or do anything else here.
38
	 *
39
	 * @param string $table
40
	 * @param string $where Extra where clause. Please make sure to use AND as first.
41
	 */
42
	protected function show_ucp_complete($table, $where = '')
43
	{
44
		$sql = 'SELECT *
45
			FROM ' . $this->db->sql_escape($table) . '
46
			WHERE user_id = ' . (int) $this->user->data['user_id'] . ' ' . $where . '
47
			ORDER BY registration_id ASC';
48
49
		$result = $this->db->sql_query($sql);
50
51
		while ($row = $this->db->sql_fetchrow($result))
52
		{
53
			$this->template->assign_block_vars('keys', array(
54
				'CLASS'         => $this->get_name(),
55
				'ID'            => $row['registration_id'],
56
				'REGISTERED'    => $this->user->format_date($row['registered']),
57
				'LAST_USED'     => $row['last_used'] ? $this->user->format_date($row['last_used']) : false,
58
				'TYPE'			=> $this->user->lang($this->get_translatable_name()),
59
			));
60
		}
61
		$this->db->sql_freeresult($result);
62
	}
63
64
	/**
65
	 * Check if the provided user has a specific key in the table provided
66
	 *
67
	 * @param string $table   Table to check in
68
	 * @param int    $user_id The specific user
69
	 * @param string $where	  Extra where clause. Be sure to include AND
70
	 *
71
	 * @return bool
72
	 */
73
	protected function check_table_for_user($table, $user_id, $where = '')
74
	{
75
		$sql = 'SELECT COUNT(registration_id) as reg_id 
76
			FROM ' . $this->db->sql_escape($table) . '
77
			WHERE user_id = ' . (int) $user_id . ' ' . $where;
78
		$result = $this->db->sql_query($sql);
79
		$row = $this->db->sql_fetchrow($result);
80
		$this->db->sql_freeresult($result);
81
82
		return $row && $row['reg_id'] > 0;
83
	}
84
}
85