<?php
namespace Moto\Application\Menus; use Moto; use Zend\Db\Sql\Select; use Moto\Application\Model\AbstractTable; use Zend\Db\ResultSet\ResultSet; class MenuItemsTable extends AbstractTable { protected $table = 'menu_items'; protected $_resultModel = 'Moto\Application\Menus\MenuItem'; protected $_primaryKey = 'id'; public function fetchAll() { $resultSet = $this->select(); return $resultSet; } public function getList($where = null) { $select = new Select($this->table); $select->columns(array( 'count' => new \Zend\Db\Sql\Expression("COUNT(*)") )); if (!empty($where) && is_array($where)) { $select->where($where); } $statement = $this->sql->prepareStatementForSqlObject($select); $result = $statement->execute()->current(); $total = $result['count']; $select->columns(array('id', 'menu_id', 'parent_id', 'label', 'action', 'properties', 'order', 'status', 'modified', 'created')); $select->order(array('parent_id' => 'ASC', 'order' => 'ASC')); $records = $this->fetchFromResultSet($this->executeSelect($select)); $result = array( 'meta' => array( 'total' => $total, 'limit' => 0, 'page' => 0, ), 'records' => $records ); return $result; } public function getById($id) { $row = is_numeric($id); if ($row) { $select = new Select($this->table); $select->where(array( 'id' => $id )); $resultSet = $this->executeSelect($select); $row = $resultSet->current(); } return $row; } public function deleteById($id) { $where = array( $this->_primaryKey => $id ); return parent::delete($where); } }