<?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/Search/Model/SearchableGateway.php
*/
abstract class Plugg_Search_Model_Base_SearchableGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'searchable';
    }

    public function getFields()
    {
        return array('searchable_id' => Sabai_Model::KEY_TYPE_INT, 'searchable_created' => Sabai_Model::KEY_TYPE_INT, 'searchable_updated' => Sabai_Model::KEY_TYPE_INT, 'searchable_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'searchable_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'searchable_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'searchable_order' => Sabai_Model::KEY_TYPE_INT, 'searchable_default' => Sabai_Model::KEY_TYPE_INT);
    }

    protected function _getSelectByIdQuery($id, array $fields)
    {
        $fields = empty($fields) ? '*' : implode(', t.', $fields);
        return sprintf('SELECT t.%s FROM %ssearchable t WHERE searchable_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$ssearchable t WHERE %3$s', $fields, $this->_db->getResourcePrefix(), $criteriaStr);
    }

    protected function _getInsertQuery(array $values)
    {
        $values['searchable_created'] = time();
        $values['searchable_updated'] = 0;
        return sprintf("INSERT INTO %ssearchable(searchable_created, searchable_updated, searchable_name, searchable_title, searchable_plugin, searchable_order, searchable_default) VALUES(%d, %d, %s, %s, %s, %d, %d)", $this->_db->getResourcePrefix(), $values['searchable_created'], $values['searchable_updated'], $this->_db->escapeString($values['searchable_name']), $this->_db->escapeString($values['searchable_title']), $this->_db->escapeString($values['searchable_plugin']), $values['searchable_order'], $values['searchable_default']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['searchable_updated'];
        $values['searchable_updated'] = time();
        return sprintf("UPDATE %ssearchable SET searchable_updated = %d, searchable_name = %s, searchable_title = %s, searchable_plugin = %s, searchable_order = %d, searchable_default = %d WHERE searchable_id = %d AND searchable_updated = %d", $this->_db->getResourcePrefix(), $values['searchable_updated'], $this->_db->escapeString($values['searchable_name']), $this->_db->escapeString($values['searchable_title']), $this->_db->escapeString($values['searchable_plugin']), $values['searchable_order'], $values['searchable_default'], $id, $last_update);
    }

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

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

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

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