<?php
namespace Moto\Application\Presets; use Moto; use Zend\Db\Sql\Select; use Moto\Application\Model\AbstractTable; use Zend\Db\ResultSet\ResultSet; class PresetsTable extends AbstractTable { protected $table = 'presets'; protected $_resultModel = 'Moto\Application\Presets\PresetModel'; 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(*)") )); $statement = $this->sql->prepareStatementForSqlObject($select); $result = $statement->execute()->current(); $total = $result['count']; $select->columns(array('id', 'name', 'widget_name', 'class_name', 'is_system', 'is_responsive', 'properties', 'template', 'created', 'modified')); if (!empty($request['widget_name'])) { $select->where(array( 'widget_name' => $request['widget_name'] )); } $select->order(array('id' => '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 = null; if (is_numeric($id)) { $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); } public function getWidgetPreset($widget, $preset) { $row = null; if (is_string($widget) && is_string($preset)) { $select = new Select($this->table); $select->where(array( 'widget_name' => $widget, 'class_name' => $preset, 'is_system' => 1 )); $resultSet = $this->executeSelect($select); $row = $resultSet->current(); } return $row; } protected function _postInsert($model) { if (is_array($model)) { if (empty($model['class_name'])) { $model['class_name'] = 'moto-preset-' . $model['id']; } } elseif (is_object($model)) { if (empty($model->class_name)) { $model->class_name = 'moto-preset-' . $model->id; } } $this->save($model); } }