-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUsers.php
More file actions
executable file
·79 lines (66 loc) · 1.93 KB
/
Users.php
File metadata and controls
executable file
·79 lines (66 loc) · 1.93 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
<?php
namespace Foolz\FoolFrame\Model;
class UsersWrongIdException extends \Exception {}
class Users extends Model
{
/**
* @var DoctrineConnection
*/
protected $dc;
/**
* @var Config
*/
protected $config;
/**
* @param Context $context
*/
public function __construct(Context $context)
{
parent::__construct($context);
$this->dc = $context->getService('doctrine');
$this->config = $context->getService('config');
}
/**
* Gets single user database row by selected row
*
* @param int $id
* @return object
*/
public function getUserBy($field, $id)
{
$result = $this->dc->qb()
->select('*')
->from($this->dc->p($this->config->get('foolz/foolframe', 'foolauth', 'table_name')), 't')
->where($field.' = '.$this->dc->getConnection()->quote($id))
->execute()
->fetch();
if (!$result) {
throw new UsersWrongIdException;
}
return User::forge($this->getContext(), $result);
}
/**
* Gets all user limited with page and limit
*
* @param int $page
* @param into $limit
* @return object
*/
public function getAll($page = 1, $limit = 40)
{
$users = $this->dc->qb()
->select('*')
->from($this->dc->p($this->config->get('foolz/foolframe', 'foolauth', 'table_name')), 't')
->setMaxResults($limit)
->setFirstResult(($page * $limit) - $limit)
->execute()
->fetchAll();
$users = User::forge($this->getContext(), $users);
$count = $this->dc->qb()
->select('COUNT(*) as count')
->from($this->dc->p($this->config->get('foolz/foolframe', 'foolauth', 'table_name')), 't')
->execute()
->fetch();
return ['result' => $users, 'count' => $count['count']];
}
}