|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.6 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace WebHemi\Data\Storage\User; |
|
13
|
|
|
|
|
14
|
|
|
use DateTime; |
|
15
|
|
|
use WebHemi\Data\Entity\DataEntityInterface; |
|
16
|
|
|
use WebHemi\Data\Entity\User\UserEntity; |
|
17
|
|
|
use WebHemi\Data\Storage\AbstractDataStorage; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class UserStorage. |
|
21
|
|
|
*/ |
|
22
|
|
|
class UserStorage extends AbstractDataStorage |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $dataGroup = 'webhemi_user'; |
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $idKey = 'id_user'; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
private $userName = 'username'; |
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
private $email = 'email'; |
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
private $password = 'password'; |
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
private $hash = 'hash'; |
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
private $isActive = 'is_active'; |
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
private $isEnabled = 'is_enabled'; |
|
40
|
|
|
/** @var string */ |
|
41
|
|
|
private $dateCreated = 'date_created'; |
|
42
|
|
|
/** @var string */ |
|
43
|
|
|
private $dateModified = 'date_modified'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Populates an entity with storage data. |
|
47
|
|
|
* |
|
48
|
|
|
* @param DataEntityInterface $entity |
|
49
|
|
|
* @param array $data |
|
50
|
|
|
*/ |
|
51
|
2 |
|
protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
52
|
|
|
{ |
|
53
|
|
|
/* @var UserEntity $entity */ |
|
54
|
2 |
|
$entity->setUserId($data[$this->idKey]) |
|
55
|
2 |
|
->setUserName($data[$this->userName]) |
|
56
|
2 |
|
->setEmail($data[$this->email]) |
|
57
|
2 |
|
->setPassword($data[$this->password]) |
|
58
|
2 |
|
->setHash($data[$this->hash]) |
|
59
|
2 |
|
->setActive($data[$this->isActive]) |
|
60
|
2 |
|
->setEnabled($data[$this->isEnabled]) |
|
61
|
2 |
|
->setDateCreated(new DateTime($data[$this->dateCreated])) |
|
62
|
2 |
|
->setDateModified(new DateTime($data[$this->dateModified])); |
|
63
|
2 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns a User entity identified by (unique) ID. |
|
67
|
|
|
* |
|
68
|
|
|
* @param int $identifier |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool|UserEntity |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function getUserById($identifier) |
|
73
|
|
|
{ |
|
74
|
1 |
|
$entity = false; |
|
75
|
1 |
|
$data = $this->getDataAdapter()->getData($identifier); |
|
76
|
|
|
|
|
77
|
1 |
|
if (!empty($data)) { |
|
78
|
1 |
|
$entity = $this->createEntity(); |
|
79
|
1 |
|
$this->populateEntity($entity, $data); |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
return $entity; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns a User entity identified by (unique) Email. |
|
87
|
|
|
* |
|
88
|
|
|
* @param $email |
|
89
|
|
|
* |
|
90
|
|
|
* @return bool|UserEntity |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function getUserByEmail($email) |
|
93
|
|
|
{ |
|
94
|
1 |
|
$entity = false; |
|
95
|
1 |
|
$dataList = $this->getDataAdapter()->getDataSet([$this->email => $email], 1); |
|
96
|
|
|
|
|
97
|
1 |
|
if (!empty($dataList)) { |
|
98
|
1 |
|
$entity = $this->createEntity(); |
|
99
|
1 |
|
$this->populateEntity($entity, $dataList[0]); |
|
100
|
1 |
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
return $entity; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|