<?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/System/Model/PluginGateway.php
*/
abstract class Plugg_System_Model_Base_PluginGateway extends Sabai_Model_Gateway
{
    public function getName()
    {
        return 'plugin';
    }

    public function getFields()
    {
        return array('plugin_id' => Sabai_Model::KEY_TYPE_INT, 'plugin_created' => Sabai_Model::KEY_TYPE_INT, 'plugin_updated' => Sabai_Model::KEY_TYPE_INT, 'plugin_name' => Sabai_Model::KEY_TYPE_VARCHAR, 'plugin_nicename' => Sabai_Model::KEY_TYPE_VARCHAR, 'plugin_version' => Sabai_Model::KEY_TYPE_VARCHAR, 'plugin_library' => Sabai_Model::KEY_TYPE_VARCHAR, 'plugin_params' => Sabai_Model::KEY_TYPE_TEXT, 'plugin_priority' => Sabai_Model::KEY_TYPE_INT, 'plugin_active' => Sabai_Model::KEY_TYPE_INT, 'plugin_locked' => Sabai_Model::KEY_TYPE_INT);
    }

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

    protected function _getInsertQuery(array $values)
    {
        $values['plugin_created'] = time();
        $values['plugin_updated'] = 0;
        return sprintf("INSERT INTO %splugin(plugin_created, plugin_updated, plugin_name, plugin_nicename, plugin_version, plugin_library, plugin_params, plugin_priority, plugin_active, plugin_locked) VALUES(%d, %d, %s, %s, %s, %s, %s, %d, %d, %d)", $this->_db->getResourcePrefix(), $values['plugin_created'], $values['plugin_updated'], $this->_db->escapeString($values['plugin_name']), $this->_db->escapeString($values['plugin_nicename']), $this->_db->escapeString($values['plugin_version']), $this->_db->escapeString($values['plugin_library']), $this->_db->escapeString($values['plugin_params']), $values['plugin_priority'], $values['plugin_active'], $values['plugin_locked']);
    }

    protected function _getUpdateQuery($id, array $values)
    {
        $last_update = $values['plugin_updated'];
        $values['plugin_updated'] = time();
        return sprintf("UPDATE %splugin SET plugin_updated = %d, plugin_name = %s, plugin_nicename = %s, plugin_version = %s, plugin_library = %s, plugin_params = %s, plugin_priority = %d, plugin_active = %d, plugin_locked = %d WHERE plugin_id = %d AND plugin_updated = %d", $this->_db->getResourcePrefix(), $values['plugin_updated'], $this->_db->escapeString($values['plugin_name']), $this->_db->escapeString($values['plugin_nicename']), $this->_db->escapeString($values['plugin_version']), $this->_db->escapeString($values['plugin_library']), $this->_db->escapeString($values['plugin_params']), $values['plugin_priority'], $values['plugin_active'], $values['plugin_locked'], $id, $last_update);
    }

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

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

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

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