<?php
namespace Moto\Application\Menus; use Moto; use Zend\Db\Sql\Select; use Moto\Application\Model\AbstractTable; use Moto\Application\Model\AbstractModel; use Zend\Db\ResultSet\ResultSet; class MenusTable extends AbstractTable { protected $table = 'menus'; protected $_resultModel = 'Moto\Application\Menus\MenuModel'; protected $_primaryKey = 'id'; public function fetchAll() { $resultSet = $this->select(); return $resultSet; } public function getList($request = null) { $select = new Select($this->table); $select->columns(array( 'count' => new \Zend\Db\Sql\Expression("COUNT(*)") )); $result = $this->executeSelect($select); $total = $result->current()->count; $select->columns(array('id', 'name', 'is_system', 'modified', 'created')); $select->order(array('id' => 'ASC')); $records = $this->executeSelect($select); $result = array( 'meta' => array( 'total' => $total, 'limit' => 0, 'page' => 0, ), 'records' => $records->toArray() ); 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 ); $result = parent::delete($where); if ($result) { $itemsTable = new MenuItemsTable(); $itemsTable->delete(array( 'menu_id' => $id )); } return $result; } }