<?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/XOOPSCube/Model/SearchGateway.php
*/
abstract class Plugg_XOOPSCube_Model_Base_SearchGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'search';
    }

    public function getFields()
    {
        return array('search_id' => Sabai_Model::KEY_TYPE_INT, 'search_created' => Sabai_Model::KEY_TYPE_INT, 'search_updated' => Sabai_Model::KEY_TYPE_INT, 'search_module' => Sabai_Model::KEY_TYPE_VARCHAR, 'search_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'search_url_format' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['search_created'] = time();
        $values['search_updated'] = 0;
        return sprintf("INSERT INTO %ssearch(search_created, search_updated, search_module, search_name, search_url_format) VALUES(%d, %d, %s, %s, %s)", $this->_db->getResourcePrefix(), $values['search_created'], $values['search_updated'], $this->_db->escapeString($values['search_module']), $this->_db->escapeString($values['search_name']), $this->_db->escapeString($values['search_url_format']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['search_updated'];
        $values['search_updated'] = time();
        return sprintf("UPDATE %ssearch SET search_updated = %d, search_module = %s, search_name = %s, search_url_format = %s WHERE search_id = %d AND search_updated = %d", $this->_db->getResourcePrefix(), $values['search_updated'], $this->_db->escapeString($values['search_module']), $this->_db->escapeString($values['search_name']), $this->_db->escapeString($values['search_url_format']), $id, $last_update);
    }

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

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

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

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