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

    public function getFields()
    {
        return array('status_id' => Sabai_Model::KEY_TYPE_INT, 'status_created' => Sabai_Model::KEY_TYPE_INT, 'status_updated' => Sabai_Model::KEY_TYPE_INT, 'status_text' => Sabai_Model::KEY_TYPE_TEXT, 'status_text_filtered' => Sabai_Model::KEY_TYPE_TEXT, 'status_text_filter_id' => Sabai_Model::KEY_TYPE_INT, 'status_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['status_created'] = time();
        $values['status_updated'] = 0;
        return sprintf("INSERT INTO %sstatus(status_created, status_updated, status_text, status_text_filtered, status_text_filter_id, status_userid) VALUES(%d, %d, %s, %s, %d, %s)", $this->_db->getResourcePrefix(), $values['status_created'], $values['status_updated'], $this->_db->escapeString($values['status_text']), $this->_db->escapeString($values['status_text_filtered']), $values['status_text_filter_id'], $this->_db->escapeString($values['status_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['status_updated'];
        $values['status_updated'] = time();
        return sprintf("UPDATE %sstatus SET status_updated = %d, status_text = %s, status_text_filtered = %s, status_text_filter_id = %d, status_userid = %s WHERE status_id = %d AND status_updated = %d", $this->_db->getResourcePrefix(), $values['status_updated'], $this->_db->escapeString($values['status_text']), $this->_db->escapeString($values['status_text_filtered']), $values['status_text_filter_id'], $this->_db->escapeString($values['status_userid']), $id, $last_update);
    }

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

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

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

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