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

    public function getFields()
    {
        return array('autologin_id' => Sabai_Model::KEY_TYPE_INT, 'autologin_created' => Sabai_Model::KEY_TYPE_INT, 'autologin_updated' => Sabai_Model::KEY_TYPE_INT, 'autologin_salt' => Sabai_Model::KEY_TYPE_VARCHAR, 'autologin_expires' => Sabai_Model::KEY_TYPE_INT, 'autologin_last_ip' => Sabai_Model::KEY_TYPE_VARCHAR, 'autologin_last_ua' => Sabai_Model::KEY_TYPE_VARCHAR, 'autologin_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['autologin_created'] = time();
        $values['autologin_updated'] = 0;
        return sprintf("INSERT INTO %sautologin(autologin_created, autologin_updated, autologin_salt, autologin_expires, autologin_last_ip, autologin_last_ua, autologin_userid) VALUES(%d, %d, %s, %d, %s, %s, %s)", $this->_db->getResourcePrefix(), $values['autologin_created'], $values['autologin_updated'], $this->_db->escapeString($values['autologin_salt']), $values['autologin_expires'], $this->_db->escapeString($values['autologin_last_ip']), $this->_db->escapeString($values['autologin_last_ua']), $this->_db->escapeString($values['autologin_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['autologin_updated'];
        $values['autologin_updated'] = time();
        return sprintf("UPDATE %sautologin SET autologin_updated = %d, autologin_salt = %s, autologin_expires = %d, autologin_last_ip = %s, autologin_last_ua = %s, autologin_userid = %s WHERE autologin_id = %d AND autologin_updated = %d", $this->_db->getResourcePrefix(), $values['autologin_updated'], $this->_db->escapeString($values['autologin_salt']), $values['autologin_expires'], $this->_db->escapeString($values['autologin_last_ip']), $this->_db->escapeString($values['autologin_last_ua']), $this->_db->escapeString($values['autologin_userid']), $id, $last_update);
    }

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

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

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

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