1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ZfcUser\Mapper; |
4
|
|
|
|
5
|
|
|
use ZfcBase\Mapper\AbstractDbMapper; |
6
|
|
|
use Zend\Stdlib\Hydrator\HydratorInterface as Hydrator; |
7
|
|
|
|
8
|
|
|
class User extends AbstractDbMapper implements UserInterface |
9
|
|
|
{ |
10
|
|
|
protected $tableName = 'user'; |
11
|
|
|
|
12
|
|
|
public function findByEmail($email) |
13
|
|
|
{ |
14
|
|
|
$select = $this->getSelect() |
15
|
|
|
->where(array('email' => $email)); |
16
|
|
|
|
17
|
|
|
$entity = $this->select($select)->current(); |
18
|
|
|
$this->getEventManager()->trigger('find', $this, array('entity' => $entity)); |
19
|
|
|
return $entity; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function findByUsername($username) |
23
|
|
|
{ |
24
|
|
|
$select = $this->getSelect() |
25
|
|
|
->where(array('username' => $username)); |
26
|
|
|
|
27
|
|
|
$entity = $this->select($select)->current(); |
28
|
|
|
$this->getEventManager()->trigger('find', $this, array('entity' => $entity)); |
29
|
|
|
return $entity; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function findById($id) |
33
|
|
|
{ |
34
|
|
|
$select = $this->getSelect() |
35
|
|
|
->where(array('id' => $id)); |
36
|
|
|
|
37
|
|
|
$entity = $this->select($select)->current(); |
38
|
|
|
$this->getEventManager()->trigger('find', $this, array('entity' => $entity)); |
39
|
|
|
return $entity; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getTableName() |
43
|
|
|
{ |
44
|
|
|
return $this->tableName; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setTableName($tableName) |
48
|
|
|
{ |
49
|
|
|
$this->tableName = $tableName; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function insert($entity, $tableName = null, Hydrator $hydrator = null) |
53
|
|
|
{ |
54
|
|
|
$hydrator = $hydrator ?: $this->getHydrator(); |
55
|
|
|
$result = parent::insert($entity, $tableName, $hydrator); |
56
|
|
|
$entity->setId($result->getGeneratedValue()); |
57
|
|
|
return $result; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function update($entity, $where = null, $tableName = null, Hydrator $hydrator = null) |
61
|
|
|
{ |
62
|
|
|
if (!$where) { |
63
|
|
|
$where = array('id' => $entity->getId()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return parent::update($entity, $where, $tableName, $hydrator); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|