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

    public function getFields()
    {
        return array('widget_id' => Sabai_Model::KEY_TYPE_INT, 'widget_created' => Sabai_Model::KEY_TYPE_INT, 'widget_updated' => Sabai_Model::KEY_TYPE_INT, 'widget_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'widget_title' => Sabai_Model::KEY_TYPE_VARCHAR, 'widget_plugin' => Sabai_Model::KEY_TYPE_VARCHAR, 'widget_order' => Sabai_Model::KEY_TYPE_INT, 'widget_active' => Sabai_Model::KEY_TYPE_INT, 'widget_type' => Sabai_Model::KEY_TYPE_INT, 'widget_private' => Sabai_Model::KEY_TYPE_INT, 'widget_mini' => Sabai_Model::KEY_TYPE_INT);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['widget_created'] = time();
        $values['widget_updated'] = 0;
        return sprintf("INSERT INTO %swidget(widget_created, widget_updated, widget_name, widget_title, widget_plugin, widget_order, widget_active, widget_type, widget_private, widget_mini) VALUES(%d, %d, %s, %s, %s, %d, %d, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['widget_created'], $values['widget_updated'], $this->_db->escapeString($values['widget_name']), $this->_db->escapeString($values['widget_title']), $this->_db->escapeString($values['widget_plugin']), $values['widget_order'], $values['widget_active'], $values['widget_type'], $values['widget_private'], $values['widget_mini']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['widget_updated'];
        $values['widget_updated'] = time();
        return sprintf("UPDATE %swidget SET widget_updated = %d, widget_name = %s, widget_title = %s, widget_plugin = %s, widget_order = %d, widget_active = %d, widget_type = %d, widget_private = %d, widget_mini = %d WHERE widget_id = %d AND widget_updated = %d", $this->_db->getResourcePrefix(), $values['widget_updated'], $this->_db->escapeString($values['widget_name']), $this->_db->escapeString($values['widget_title']), $this->_db->escapeString($values['widget_plugin']), $values['widget_order'], $values['widget_active'], $values['widget_type'], $values['widget_private'], $values['widget_mini'], $id, $last_update);
    }

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

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

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

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