Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
69 lines (54 sloc) 1.949 kB
<?php
namespace ZfcUser\Mapper;
use ZfcBase\Mapper\AbstractDbMapper;
use Zend\Stdlib\Hydrator\HydratorInterface as Hydrator;
class User extends AbstractDbMapper implements UserInterface
{
protected $tableName = 'user';
public function findByEmail($email)
{
$select = $this->getSelect()
->where(array('email' => $email));
$entity = $this->select($select)->current();
$this->getEventManager()->trigger('find', $this, array('entity' => $entity));
return $entity;
}
public function findByUsername($username)
{
$select = $this->getSelect()
->where(array('username' => $username));
$entity = $this->select($select)->current();
$this->getEventManager()->trigger('find', $this, array('entity' => $entity));
return $entity;
}
public function findById($id)
{
$select = $this->getSelect()
->where(array('user_id' => $id));
$entity = $this->select($select)->current();
$this->getEventManager()->trigger('find', $this, array('entity' => $entity));
return $entity;
}
public function getTableName()
{
return $this->tableName;
}
public function setTableName($tableName)
{
$this->tableName = $tableName;
}
public function insert($entity, $tableName = null, Hydrator $hydrator = null)
{
$hydrator = $hydrator ?: $this->getHydrator();
$result = parent::insert($entity, $tableName, $hydrator);
$hydrator->hydrate(array('user_id' => $result->getGeneratedValue()), $entity);
return $result;
}
public function update($entity, $where = null, $tableName = null, Hydrator $hydrator = null)
{
if (!$where) {
$where = array('user_id' => $entity->getId());
}
return parent::update($entity, $where, $tableName, $hydrator);
}
}
Jump to Line
Something went wrong with that request. Please try again.