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

    public function getFields()
    {
        return array('friend_id' => Sabai_Model::KEY_TYPE_INT, 'friend_created' => Sabai_Model::KEY_TYPE_INT, 'friend_updated' => Sabai_Model::KEY_TYPE_INT, 'friend_with' => Sabai_Model::KEY_TYPE_INT, 'friend_relationships' => Sabai_Model::KEY_TYPE_VARCHAR, 'friend_userid' => Sabai_Model::KEY_TYPE_VARCHAR);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['friend_created'] = time();
        $values['friend_updated'] = 0;
        return sprintf("INSERT INTO %sfriend(friend_created, friend_updated, friend_with, friend_relationships, friend_userid) VALUES(%d, %d, %d, %s, %s)", $this->_db->getResourcePrefix(), $values['friend_created'], $values['friend_updated'], $values['friend_with'], $this->_db->escapeString($values['friend_relationships']), $this->_db->escapeString($values['friend_userid']));
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['friend_updated'];
        $values['friend_updated'] = time();
        return sprintf("UPDATE %sfriend SET friend_updated = %d, friend_with = %d, friend_relationships = %s, friend_userid = %s WHERE friend_id = %d AND friend_updated = %d", $this->_db->getResourcePrefix(), $values['friend_updated'], $values['friend_with'], $this->_db->escapeString($values['friend_relationships']), $this->_db->escapeString($values['friend_userid']), $id, $last_update);
    }

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

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

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

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