<?php
namespace Moto\Application\MediaLibrary; use Moto; use Zend\Db\Sql\Select; use Moto\Application\Model\AbstractTable; use Zend\Db\ResultSet\ResultSet; class MediaFoldersTable extends AbstractTable { protected $table = 'media_folders'; protected $_resultModel = 'Moto\Application\MediaLibrary\MediaFolderModel'; 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', 'parent_id', 'order', 'is_favorite', 'modified', 'created', 'del')); $select->order(array('created' => '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 ); return parent::delete($where); } }