Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Enhancement: Add inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 18, 2015
1 parent 17303a9 commit 54167b9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions module/ZfModule/src/ZfModule/Mapper/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ZfModule\Mapper;

use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Stdlib\Hydrator\HydratorInterface;
Expand Down Expand Up @@ -32,10 +32,12 @@ public function pagination($page, $limit, $query = null, $orderBy = null, $sort

if (null !== $query) {
$spec = function ($where) use ($query) {
/* @var Sql\Where $where */
$where->like('name', '%' . $query . '%')->or->like('description', '%' . $query . '%');
};
$select->where($spec);
}

$resultSet = new HydratingResultSet($this->getHydrator(), $this->getEntityPrototype());

$adapter = new DbSelect($select, $this->getSql(), $resultSet);
Expand All @@ -60,6 +62,7 @@ public function findAll($limit = null, $orderBy = null, $sort = 'ASC')
}

$entity = $this->select($select);

$this->getEventManager()->trigger('find', $this, ['entity' => $entity]);

return $entity;
Expand All @@ -78,11 +81,13 @@ public function findByLike($query, $limit = null, $orderBy = null, $sort = 'ASC'
}

$spec = function ($where) use ($query) {
/* @var Sql\Where $where */
$where->like('name', '%' . $query . '%')->or->like('description', '%' . $query . '%');
};
$select->where($spec);

$entity = $this->select($select);

$this->getEventManager()->trigger('find', $this, ['entity' => $entity]);

return $entity;
Expand All @@ -101,6 +106,7 @@ public function findByOwner($owner, $limit = null, $orderBy = null, $sort = 'ASC
}

$entity = $this->select($select);

$this->getEventManager()->trigger('find', $this, ['entity' => $entity]);

return $entity;
Expand All @@ -126,14 +132,17 @@ public function findBy($key, $value)
$select->where([$key => $value]);

$entity = $this->select($select)->current();

$this->getEventManager()->trigger('find', $this, ['entity' => $entity]);

return $entity;
}

public function insert($entity, $tableName = null, HydratorInterface $hydrator = null)
{
/* @var Entity\Module $entity */
$result = parent::insert($entity, $tableName, $hydrator);

$entity->setId($result->getGeneratedValue());

return $result;
Expand All @@ -142,6 +151,7 @@ public function insert($entity, $tableName = null, HydratorInterface $hydrator =
public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
{
if (!$where) {
/* @var Entity\Module $entity */
$where = ['module_id' => $entity->getId()];
}

Expand All @@ -151,6 +161,7 @@ public function update($entity, $where = null, $tableName = null, HydratorInterf
public function delete($entity, $where = null, $tableName = null)
{
if (!$where) {
/* @var Entity\Module $entity */
$where = ['module_id' => $entity->getId()];
}

Expand All @@ -160,7 +171,7 @@ public function delete($entity, $where = null, $tableName = null)
public function getTotal()
{
$select = $this->getSelect();
$select->columns(['num' => new Expression('COUNT(*)')]);
$select->columns(['num' => new Sql\Expression('COUNT(*)')]);

$stmt = $this->getSlaveSql()->prepareStatementForSqlObject($select);
$row = $stmt->execute()->current();
Expand Down

0 comments on commit 54167b9

Please sign in to comment.