-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
125 lines (114 loc) · 2.24 KB
/
User.php
File metadata and controls
125 lines (114 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @author : Jakiboy
* @package : FloatPHP
* @subpackage : Helpers Connection Component
* @version : 1.5.x
* @copyright : (c) 2018 - 2025 Jihad Sinnaour <me@jihadsinnaour.com>
* @link : https://floatphp.com
* @license : MIT
*
* This file is a part of FloatPHP Framework.
*/
declare(strict_types=1);
namespace FloatPHP\Helpers\Connection;
use FloatPHP\Kernel\Model;
class User extends Model
{
/**
* @access protected
* @var string $table
* @var string $key
*/
protected $table = 'user';
protected $key = 'userId';
/**
* Get user by username or email.
*
* @access public
* @param string $user
* @return array
*/
public function getUser(string $user) : array
{
$this->bind(['username' => $user, 'email' => $user]);
$sql = "SELECT * FROM `{$this->table}` ";
$sql .= "WHERE `username` = :username OR `email` = :email;";
return $this->getRow($sql);
}
/**
* Check user secret.
*
* @access public
* @param string $user
* @return bool
*/
public function hasSecret(string $user) : bool
{
$this->bind(['username' => $user, 'email' => $user]);
$sql = "SELECT `secret` FROM `{$this->table}` ";
$sql .= "WHERE `username` = :username OR `email` = :email;";
return ($this->getSingle($sql)) ? true : false;
}
/**
* Get user table key.
*
* @access public
* @return string
*/
public function getKey() : string
{
return (string)$this->key;
}
/**
* Get user.
*
* @access public
* @param int $id
* @param bool $secured
* @return array
*/
public function getById(?int $id, bool $secured = true) : array
{
$user = (array)$this->get((int)$id);
if ( $secured ) {
unset($user['password']);
}
return $user;
}
/**
* Get user name.
*
* @access public
* @param int $id
* @return array
*/
public function getName(?int $id) : string
{
$this->get((int)$id);
return (string)$this->name;
}
/**
* Get user role.
*
* @access public
* @param int $id
* @return int
*/
public function getRoleId(?int $id) : int
{
$this->get((int)$id);
return (int)$this->roleId;
}
/**
* Update user.
*
* @access public
* @param array $data
* @return bool
*/
public function updateUser(array $data) : bool
{
return $this->save($data);
}
}