-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathUserManager.class.php
57 lines (52 loc) · 1.61 KB
/
UserManager.class.php
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
<?php
require_once('util4p/util.php');
require_once('util4p/CRObject.class.php');
require_once('util4p/SQLBuilder.class.php');
require_once('util4p/MysqlPDO.class.php');
require_once('util4p/Validator.class.php');
class UserManager
{
/**/
public static function add(CRObject $user)
{
$open_id = $user->get('open_id');
$email = $user->get('email');
$role = $user->get('role');
$level = $user->getInt('level', 0);
if ($email !== null && !Validator::isEmail($email)) {
return false;
}
$key_values = array('open_id' => '?', 'email' => '?', 'role' => '?', 'time' => '?', 'level' => '?');
$builder = new SQLBuilder();
$builder->insert('ls_user', $key_values);
$sql = $builder->build();
$params = array($open_id, $email, $role, time(), $level);
return (new MysqlPDO())->execute($sql, $params);
}
/**/
public static function getByUID($uid)
{
$selected_rows = array();
$where_arr = array('uid' => '?');
$builder = new SQLBuilder();
$builder->select('ls_user', $selected_rows);
$builder->where($where_arr);
$sql = $builder->build();
$params = array($uid);
$users = (new MysqlPDO())->executeQuery($sql, $params);
return $users !== null && count($users) === 1 ? $users[0] : null;
}
/**/
public static function getByOpenID($open_id)
{
$selected_rows = array();
$where_arr = array('open_id' => '?');
$builder = new SQLBuilder();
$builder->select('ls_user', $selected_rows);
$builder->where($where_arr);
$sql = $builder->build();
$params = array($open_id);
$users = (new MysqlPDO())->executeQuery($sql, $params);
return $users !== null && count($users) === 1 ? $users[0] : null;
}
}