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

    public function getFields()
    {
        return array('auth_id' => Sabai_Model::KEY_TYPE_INT, 'auth_created' => Sabai_Model::KEY_TYPE_INT, 'auth_updated' => Sabai_Model::KEY_TYPE_INT, 'auth_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'auth_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'auth_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'auth_order' => Sabai_Model::KEY_TYPE_INT, 'auth_active' => Sabai_Model::KEY_TYPE_INT, 'auth_authdata_count' => Sabai_Model::KEY_TYPE_INT, 'auth_authdata_last' => Sabai_Model::KEY_TYPE_INT, 'auth_authdata_lasttime' => Sabai_Model::KEY_TYPE_INT);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['auth_created'] = time();
        $values['auth_updated'] = 0;
        $values['auth_authdata_lasttime'] = $values['auth_created'];
        return sprintf("INSERT INTO %sauth(auth_created, auth_updated, auth_name, auth_title, auth_plugin, auth_order, auth_active, auth_authdata_count, auth_authdata_last, auth_authdata_lasttime) VALUES(%d, %d, %s, %s, %s, %d, %d, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['auth_created'], $values['auth_updated'], $this->_db->escapeString($values['auth_name']), $this->_db->escapeString($values['auth_title']), $this->_db->escapeString($values['auth_plugin']), $values['auth_order'], $values['auth_active'], $values['auth_authdata_count'], $values['auth_authdata_last'], $values['auth_authdata_lasttime']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['auth_updated'];
        $values['auth_updated'] = time();
        return sprintf("UPDATE %sauth SET auth_updated = %d, auth_name = %s, auth_title = %s, auth_plugin = %s, auth_order = %d, auth_active = %d, auth_authdata_count = %d, auth_authdata_last = %d, auth_authdata_lasttime = %d WHERE auth_id = %d AND auth_updated = %d", $this->_db->getResourcePrefix(), $values['auth_updated'], $this->_db->escapeString($values['auth_name']), $this->_db->escapeString($values['auth_title']), $this->_db->escapeString($values['auth_plugin']), $values['auth_order'], $values['auth_active'], $values['auth_authdata_count'], $values['auth_authdata_last'], $values['auth_authdata_lasttime'], $id, $last_update);
    }

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

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

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

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

    protected function _beforeDeleteTrigger1($id, array $old)
    {
        return $this->_db->exec(sprintf('DELETE FROM %1$sauthdata WHERE %1$sauthdata.authdata_auth_id = %2$d', $this->_db->getResourcePrefix(), $id), false);
    }

    protected function _beforeDeleteTrigger($id, array $old)
    {
        if (!$this->_beforeDeleteTrigger1($id, $old)) return false;
        return true;
    }
}