|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Auth\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Drone\Db\TableGateway\TableGateway; |
|
6
|
|
|
|
|
7
|
|
|
class UserTbl extends TableGateway |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Returns the next primary key in the table |
|
11
|
|
|
* |
|
12
|
|
|
* @return string |
|
13
|
|
|
*/ |
|
14
|
|
|
public function getNextId() |
|
15
|
|
|
{ |
|
16
|
|
|
$table = $this->getEntity()->getTableName(); |
|
17
|
|
|
|
|
18
|
|
|
$config = include 'module/Auth/config/user.config.php'; |
|
19
|
|
|
$id_field = $config["authentication"]["gateway"]["table_info"]["columns"]["id_field"]; |
|
20
|
|
|
|
|
21
|
|
|
$sql = "SELECT CASE WHEN MAX($id_field) IS NULL THEN 1 ELSE MAX($id_field) + 1 END AS USER_ID FROM $table"; |
|
22
|
|
|
|
|
23
|
|
|
$this->getDriver()->getDb()->execute($sql); |
|
24
|
|
|
$rowset = $this->getDriver()->getDb()->getArrayResult(); |
|
25
|
|
|
$row = array_shift($rowset); |
|
26
|
|
|
|
|
27
|
|
|
return $row["USER_ID"]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns the user by the id |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $id |
|
34
|
|
|
* |
|
35
|
|
|
* @return User |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getUserById($id) |
|
38
|
|
|
{ |
|
39
|
|
|
$config = include 'module/Auth/config/user.config.php'; |
|
40
|
|
|
$id_field = $config["authentication"]["gateway"]["table_info"]["columns"]["id_field"]; |
|
41
|
|
|
|
|
42
|
|
|
$rowset = $this->select([ |
|
43
|
|
|
$id_field => $id |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
$row = array_shift($rowset); |
|
47
|
|
|
|
|
48
|
|
|
$filtered_array = array(); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($row as $key => $value) |
|
51
|
|
|
{ |
|
52
|
|
|
if (is_string($key)) |
|
53
|
|
|
$filtered_array[$key] = $value; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$user = new User(); |
|
57
|
|
|
$user->exchangeArray($filtered_array); |
|
58
|
|
|
|
|
59
|
|
|
return $user; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the user by the username credential |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $username |
|
66
|
|
|
* |
|
67
|
|
|
* @return User |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getUserByUsernameCredential($username) |
|
70
|
|
|
{ |
|
71
|
|
|
$config = include 'module/Auth/config/user.config.php'; |
|
72
|
|
|
$username_credential = $config["authentication"]["gateway"]["credentials"]["username"]; |
|
73
|
|
|
|
|
74
|
|
|
$rowset = $this->select([ |
|
75
|
|
|
$username_credential => $username |
|
76
|
|
|
]); |
|
77
|
|
|
|
|
78
|
|
|
$row = array_shift($rowset); |
|
79
|
|
|
|
|
80
|
|
|
$filtered_array = array(); |
|
81
|
|
|
|
|
82
|
|
|
foreach ($row as $key => $value) |
|
83
|
|
|
{ |
|
84
|
|
|
if (is_string($key)) |
|
85
|
|
|
$filtered_array[$key] = $value; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$user = new User(); |
|
89
|
|
|
$user->exchangeArray($filtered_array); |
|
90
|
|
|
|
|
91
|
|
|
return $user; |
|
92
|
|
|
} |
|
93
|
|
|
} |