<?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/SimpleSearch/Model/TextGateway.php
*/
abstract class Plugg_SimpleSearch_Model_Base_TextGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'text';
    }

    public function getFields()
    {
        return array('text_id' => Sabai_Model::KEY_TYPE_INT, 'text_created' => Sabai_Model::KEY_TYPE_INT, 'text_updated' => Sabai_Model::KEY_TYPE_INT, 'text_content_id' => Sabai_Model::KEY_TYPE_INT, 'text_ctime' => Sabai_Model::KEY_TYPE_INT, 'text_mtime' => Sabai_Model::KEY_TYPE_INT, 'text_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'text_body' => Sabai_Model::KEY_TYPE_TEXT, 'text_author_id' => Sabai_Model::KEY_TYPE_INT, 'text_searchable_id' => Sabai_Model::KEY_TYPE_INT, 'text_content_group' => Sabai_Model::KEY_TYPE_VARCHAR, 'text_plugin' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['text_created'] = time();
        $values['text_updated'] = 0;
        return sprintf("INSERT INTO %stext(text_created, text_updated, text_content_id, text_ctime, text_mtime, text_title, text_body, text_author_id, text_searchable_id, text_content_group, text_plugin) VALUES(%d, %d, %d, %d, %d, %s, %s, %d, %d, %s, %s)", $this->_db->getResourcePrefix(), $values['text_created'], $values['text_updated'], $values['text_content_id'], $values['text_ctime'], $values['text_mtime'], $this->_db->escapeString($values['text_title']), $this->_db->escapeString($values['text_body']), $values['text_author_id'], $values['text_searchable_id'], $this->_db->escapeString($values['text_content_group']), $this->_db->escapeString($values['text_plugin']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['text_updated'];
        $values['text_updated'] = time();
        return sprintf("UPDATE %stext SET text_updated = %d, text_content_id = %d, text_ctime = %d, text_mtime = %d, text_title = %s, text_body = %s, text_author_id = %d, text_searchable_id = %d, text_content_group = %s, text_plugin = %s WHERE text_id = %d AND text_updated = %d", $this->_db->getResourcePrefix(), $values['text_updated'], $values['text_content_id'], $values['text_ctime'], $values['text_mtime'], $this->_db->escapeString($values['text_title']), $this->_db->escapeString($values['text_body']), $values['text_author_id'], $values['text_searchable_id'], $this->_db->escapeString($values['text_content_group']), $this->_db->escapeString($values['text_plugin']), $id, $last_update);
    }

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

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

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

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