<?php
/*
This file has been generated by the Sabai scaffold script. Do not edit this file directly.
If you need to customize the class, use the following file:
pluginsy/Filter/Model/FilterGateway.php
*/
abstract class Plugg_Filter_Model_Base_FilterGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'filter';
    }

    public function getFields()
    {
        return array('filter_id' => Sabai_Model::KEY_TYPE_INT, 'filter_created' => Sabai_Model::KEY_TYPE_INT, 'filter_updated' => Sabai_Model::KEY_TYPE_INT, 'filter_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'filter_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'filter_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'filter_order' => Sabai_Model::KEY_TYPE_INT, 'filter_active' => Sabai_Model::KEY_TYPE_INT, 'filter_default' => Sabai_Model::KEY_TYPE_INT);
    }

    protected function _getSelectByIdQuery($id, array $fields)
    {
        $fields = empty($fields) ? '*' : implode(', t.', $fields);
        return sprintf('SELECT t.%s FROM %sfilter t WHERE filter_id = %d', $fields, $this->_db->getResourcePrefix(), $id);
    }

    protected function _getSelectByCriteriaQuery($criteriaStr, array $fields)
    {
        $fields = empty($fields) ? '*' : implode(', t.', $fields);
        return sprintf('SELECT t.%1$s FROM %2$sfilter t WHERE %3$s', $fields, $this->_db->getResourcePrefix(), $criteriaStr);
    }

    protected function _getInsertQuery(array $values)
    {
        $values['filter_created'] = time();
        $values['filter_updated'] = 0;
        return sprintf("INSERT INTO %sfilter(filter_created, filter_updated, filter_name, filter_plugin, filter_title, filter_order, filter_active, filter_default) VALUES(%d, %d, %s, %s, %s, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['filter_created'], $values['filter_updated'], $this->_db->escapeString($values['filter_name']), $this->_db->escapeString($values['filter_plugin']), $this->_db->escapeString($values['filter_title']), $values['filter_order'], $values['filter_active'], $values['filter_default']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['filter_updated'];
        $values['filter_updated'] = time();
        return sprintf("UPDATE %sfilter SET filter_updated = %d, filter_name = %s, filter_plugin = %s, filter_title = %s, filter_order = %d, filter_active = %d, filter_default = %d WHERE filter_id = %d AND filter_updated = %d", $this->_db->getResourcePrefix(), $values['filter_updated'], $this->_db->escapeString($values['filter_name']), $this->_db->escapeString($values['filter_plugin']), $this->_db->escapeString($values['filter_title']), $values['filter_order'], $values['filter_active'], $values['filter_default'], $id, $last_update);
    }

    protected function _getDeleteQuery($id)
    {
        return sprintf('DELETE FROM %1$sfilter WHERE filter_id = %2$d', $this->_db->getResourcePrefix(), $id);
    }

    protected function _getUpdateByCriteriaQuery($criteriaStr, array $sets)
    {
        $sets['filter_updated'] = 'filter_updated=' . time();
        return sprintf('UPDATE %sfilter SET %s WHERE %s', $this->_db->getResourcePrefix(), implode(',', $sets), $criteriaStr);
    }

    protected function _getDeleteByCriteriaQuery($criteriaStr)
    {
        return sprintf('DELETE FROM %1$sfilter WHERE %2$s', $this->_db->getResourcePrefix(), $criteriaStr);
    }

    protected function _getCountByCriteriaQuery($criteriaStr)
    {
        return sprintf('SELECT COUNT(*) FROM %1$sfilter WHERE %2$s', $this->_db->getResourcePrefix(), $criteriaStr);
    }
}