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

    public function getFields()
    {
        return array('field_id' => Sabai_Model::KEY_TYPE_INT, 'field_created' => Sabai_Model::KEY_TYPE_INT, 'field_updated' => Sabai_Model::KEY_TYPE_INT, 'field_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'field_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'field_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'field_order' => Sabai_Model::KEY_TYPE_INT, 'field_active' => Sabai_Model::KEY_TYPE_INT, 'field_type' => Sabai_Model::KEY_TYPE_INT, 'field_registerable' => Sabai_Model::KEY_TYPE_INT, 'field_editable' => Sabai_Model::KEY_TYPE_INT, 'field_viewable' => Sabai_Model::KEY_TYPE_INT, 'field_configurable' => Sabai_Model::KEY_TYPE_INT);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['field_created'] = time();
        $values['field_updated'] = 0;
        return sprintf("INSERT INTO %sfield(field_created, field_updated, field_name, field_title, field_plugin, field_order, field_active, field_type, field_registerable, field_editable, field_viewable, field_configurable) VALUES(%d, %d, %s, %s, %s, %d, %d, %d, %d, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['field_created'], $values['field_updated'], $this->_db->escapeString($values['field_name']), $this->_db->escapeString($values['field_title']), $this->_db->escapeString($values['field_plugin']), $values['field_order'], $values['field_active'], $values['field_type'], $values['field_registerable'], $values['field_editable'], $values['field_viewable'], $values['field_configurable']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['field_updated'];
        $values['field_updated'] = time();
        return sprintf("UPDATE %sfield SET field_updated = %d, field_name = %s, field_title = %s, field_plugin = %s, field_order = %d, field_active = %d, field_type = %d, field_registerable = %d, field_editable = %d, field_viewable = %d, field_configurable = %d WHERE field_id = %d AND field_updated = %d", $this->_db->getResourcePrefix(), $values['field_updated'], $this->_db->escapeString($values['field_name']), $this->_db->escapeString($values['field_title']), $this->_db->escapeString($values['field_plugin']), $values['field_order'], $values['field_active'], $values['field_type'], $values['field_registerable'], $values['field_editable'], $values['field_viewable'], $values['field_configurable'], $id, $last_update);
    }

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

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

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

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