<?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/User/Model/TabGateway.php
*/
abstract class Plugg_User_Model_Base_TabGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'tab';
    }

    public function getFields()
    {
        return array('tab_id' => Sabai_Model::KEY_TYPE_INT, 'tab_created' => Sabai_Model::KEY_TYPE_INT, 'tab_updated' => Sabai_Model::KEY_TYPE_INT, 'tab_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'tab_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'tab_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'tab_order' => Sabai_Model::KEY_TYPE_INT, 'tab_active' => Sabai_Model::KEY_TYPE_INT, 'tab_type' => Sabai_Model::KEY_TYPE_INT, 'tab_private' => Sabai_Model::KEY_TYPE_INT);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['tab_created'] = time();
        $values['tab_updated'] = 0;
        return sprintf("INSERT INTO %stab(tab_created, tab_updated, tab_name, tab_title, tab_plugin, tab_order, tab_active, tab_type, tab_private) VALUES(%d, %d, %s, %s, %s, %d, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['tab_created'], $values['tab_updated'], $this->_db->escapeString($values['tab_name']), $this->_db->escapeString($values['tab_title']), $this->_db->escapeString($values['tab_plugin']), $values['tab_order'], $values['tab_active'], $values['tab_type'], $values['tab_private']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['tab_updated'];
        $values['tab_updated'] = time();
        return sprintf("UPDATE %stab SET tab_updated = %d, tab_name = %s, tab_title = %s, tab_plugin = %s, tab_order = %d, tab_active = %d, tab_type = %d, tab_private = %d WHERE tab_id = %d AND tab_updated = %d", $this->_db->getResourcePrefix(), $values['tab_updated'], $this->_db->escapeString($values['tab_name']), $this->_db->escapeString($values['tab_title']), $this->_db->escapeString($values['tab_plugin']), $values['tab_order'], $values['tab_active'], $values['tab_type'], $values['tab_private'], $id, $last_update);
    }

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

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

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

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