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

    public function getFields()
    {
        return array('stat_id' => Sabai_Model::KEY_TYPE_INT, 'stat_created' => Sabai_Model::KEY_TYPE_INT, 'stat_updated' => Sabai_Model::KEY_TYPE_INT, 'stat_last_login' => Sabai_Model::KEY_TYPE_INT, 'stat_last_edit' => Sabai_Model::KEY_TYPE_INT, 'stat_last_edit_email' => Sabai_Model::KEY_TYPE_INT, 'stat_last_edit_password' => Sabai_Model::KEY_TYPE_INT, 'stat_last_edit_image' => Sabai_Model::KEY_TYPE_INT, 'stat_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['stat_created'] = time();
        $values['stat_updated'] = 0;
        return sprintf("INSERT INTO %sstat(stat_created, stat_updated, stat_last_login, stat_last_edit, stat_last_edit_email, stat_last_edit_password, stat_last_edit_image, stat_userid) VALUES(%d, %d, %d, %d, %d, %d, %d, %s)", $this->_db->getResourcePrefix(), $values['stat_created'], $values['stat_updated'], $values['stat_last_login'], $values['stat_last_edit'], $values['stat_last_edit_email'], $values['stat_last_edit_password'], $values['stat_last_edit_image'], $this->_db->escapeString($values['stat_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['stat_updated'];
        $values['stat_updated'] = time();
        return sprintf("UPDATE %sstat SET stat_updated = %d, stat_last_login = %d, stat_last_edit = %d, stat_last_edit_email = %d, stat_last_edit_password = %d, stat_last_edit_image = %d, stat_userid = %s WHERE stat_id = %d AND stat_updated = %d", $this->_db->getResourcePrefix(), $values['stat_updated'], $values['stat_last_login'], $values['stat_last_edit'], $values['stat_last_edit_email'], $values['stat_last_edit_password'], $values['stat_last_edit_image'], $this->_db->escapeString($values['stat_userid']), $id, $last_update);
    }

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

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

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

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