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

    public function getFields()
    {
        return array('friendrequest_id' => Sabai_Model::KEY_TYPE_INT, 'friendrequest_created' => Sabai_Model::KEY_TYPE_INT, 'friendrequest_updated' => Sabai_Model::KEY_TYPE_INT, 'friendrequest_to' => Sabai_Model::KEY_TYPE_INT, 'friendrequest_message' => Sabai_Model::KEY_TYPE_TEXT, 'friendrequest_status' => Sabai_Model::KEY_TYPE_INT, 'friendrequest_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['friendrequest_created'] = time();
        $values['friendrequest_updated'] = 0;
        return sprintf("INSERT INTO %sfriendrequest(friendrequest_created, friendrequest_updated, friendrequest_to, friendrequest_message, friendrequest_status, friendrequest_userid) VALUES(%d, %d, %d, %s, %d, %s)", $this->_db->getResourcePrefix(), $values['friendrequest_created'], $values['friendrequest_updated'], $values['friendrequest_to'], $this->_db->escapeString($values['friendrequest_message']), $values['friendrequest_status'], $this->_db->escapeString($values['friendrequest_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['friendrequest_updated'];
        $values['friendrequest_updated'] = time();
        return sprintf("UPDATE %sfriendrequest SET friendrequest_updated = %d, friendrequest_to = %d, friendrequest_message = %s, friendrequest_status = %d, friendrequest_userid = %s WHERE friendrequest_id = %d AND friendrequest_updated = %d", $this->_db->getResourcePrefix(), $values['friendrequest_updated'], $values['friendrequest_to'], $this->_db->escapeString($values['friendrequest_message']), $values['friendrequest_status'], $this->_db->escapeString($values['friendrequest_userid']), $id, $last_update);
    }

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

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

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

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