<?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/ExtraGateway.php
*/
abstract class Plugg_User_Model_Base_ExtraGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'extra';
    }

    public function getFields()
    {
        return array('extra_id' => Sabai_Model::KEY_TYPE_INT, 'extra_created' => Sabai_Model::KEY_TYPE_INT, 'extra_updated' => Sabai_Model::KEY_TYPE_INT, 'extra_data' => Sabai_Model::KEY_TYPE_TEXT, 'extra_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['extra_created'] = time();
        $values['extra_updated'] = 0;
        return sprintf("INSERT INTO %sextra(extra_created, extra_updated, extra_data, extra_userid) VALUES(%d, %d, %s, %s)", $this->_db->getResourcePrefix(), $values['extra_created'], $values['extra_updated'], $this->_db->escapeString($values['extra_data']), $this->_db->escapeString($values['extra_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['extra_updated'];
        $values['extra_updated'] = time();
        return sprintf("UPDATE %sextra SET extra_updated = %d, extra_data = %s, extra_userid = %s WHERE extra_id = %d AND extra_updated = %d", $this->_db->getResourcePrefix(), $values['extra_updated'], $this->_db->escapeString($values['extra_data']), $this->_db->escapeString($values['extra_userid']), $id, $last_update);
    }

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

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

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

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