<?php
namespace Moto\Application\Fonts; use Moto; use Zend\Db\Sql\Select; use Moto\Application\Model\AbstractTable; use Zend\Db\ResultSet\ResultSet; use ArrayObject; class FontsTable extends AbstractTable { protected $table = 'fonts'; protected $_resultModel = 'Moto\Application\Fonts\FontModel'; protected $_primaryKey = 'id'; public function getList($where = null) { $select = $this->_select($where, array( 'count' => new \Zend\Db\Sql\Expression("COUNT(*)") )); $objectPrototype = $this->resultSetPrototype->getArrayObjectPrototype(); if ($this->_usedResultModel) { $this->resultSetPrototype->setArrayObjectPrototype(new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS)); } $result = $this->executeSelect($select); $total = $result->current()->count; if ($this->_usedResultModel) { $this->resultSetPrototype->setArrayObjectPrototype($objectPrototype); } $select = $this->_select($where); $select->order(array('name' => 'ASC')); $records = $this->fetchFromResultSet($this->executeSelect($select)); $result = array( 'meta' => array( 'total' => $total, 'limit' => 0, 'page' => 0, ), 'records' => $records ); return $result; } public function getByName($name) { return $this->select(array('name' => $name))->current(); } protected function _select($where = null, $columns = null) { $select = new Select($this->table); if (!empty($columns)) { $select->columns($columns); } if (!empty($where)) { $select->where($where); } return $select; } }