|
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\DataStorage\User; |
|
13
|
|
|
|
|
14
|
|
|
use WebHemi\DataEntity\DataEntityInterface; |
|
15
|
|
|
use WebHemi\DataEntity\User\UserMetaEntity; |
|
16
|
|
|
use WebHemi\DataStorage\AbstractDataStorage; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class UserMetaStorage. |
|
20
|
|
|
*/ |
|
21
|
|
|
class UserMetaStorage extends AbstractDataStorage |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
protected $dataGroup = 'webhemi_user_meta'; |
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
protected $idKey = 'id_user_meta'; |
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $userId = 'fk_user'; |
|
29
|
|
|
/** @var string */ |
|
30
|
|
|
private $metaKey = 'meta_key'; |
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
private $metaData = 'meta_data'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Populates an entity with storage data. |
|
36
|
|
|
* |
|
37
|
|
|
* @param DataEntityInterface $entity |
|
38
|
|
|
* @param array $data |
|
39
|
|
|
*/ |
|
40
|
2 |
|
protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
41
|
|
|
{ |
|
42
|
|
|
/* @var UserMetaEntity $entity */ |
|
43
|
2 |
|
$entity->setUserMetaId($data[$this->idKey]) |
|
44
|
2 |
|
->setUserId($data[$this->userId]) |
|
45
|
2 |
|
->setMetaKey($data[$this->metaKey]) |
|
46
|
2 |
|
->setMetaData($data[$this->metaData]); |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns a User entity identified by (unique) ID. |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $identifier |
|
53
|
|
|
* |
|
54
|
|
|
* @return bool|UserMetaEntity |
|
55
|
|
|
*/ |
|
56
|
1 |
View Code Duplication |
public function getUserMetaById($identifier) |
|
57
|
|
|
{ |
|
58
|
1 |
|
$entity = false; |
|
59
|
1 |
|
$data = $this->getDataAdapter()->getData($identifier); |
|
60
|
|
|
|
|
61
|
1 |
|
if (!empty($data)) { |
|
62
|
1 |
|
$entity = $this->createEntity(); |
|
63
|
1 |
|
$this->populateEntity($entity, $data); |
|
64
|
1 |
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
return $entity; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns a User entity identified by (unique) Email. |
|
71
|
|
|
* |
|
72
|
|
|
* @param mixed $userId |
|
73
|
|
|
* |
|
74
|
|
|
* @return UserMetaEntity[] |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function getUserMetaForUserId($userId) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$entityList = false; |
|
79
|
1 |
|
$dataList = $this->getDataAdapter()->getDataSet([$this->userId => $userId]); |
|
80
|
|
|
|
|
81
|
1 |
|
if (!empty($dataList)) { |
|
82
|
1 |
|
foreach ($dataList as $metaData) { |
|
83
|
|
|
/** @var UserMetaEntity $entity */ |
|
84
|
1 |
|
$entity = $this->createEntity(); |
|
85
|
1 |
|
$this->populateEntity($entity, $metaData); |
|
86
|
1 |
|
$entityList[] = $entity; |
|
87
|
1 |
|
} |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
return $entityList; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|