<?php
/* This file has been auto-generated. Do not edit this file directly. */
namespace SabaiApps\Directories\Component\Voting\Model\Base;

use SabaiApps\Framework\Model\Model;

abstract class VoteGateway extends \SabaiApps\Framework\Model\AbstractGateway
{
    public function getName()
    {
        return 'voting_vote';
    }

    public function getFields()
    {
        return ['vote_bundle_name' => Model::KEY_TYPE_VARCHAR, 'vote_entity_id' => Model::KEY_TYPE_INT, 'vote_value' => Model::KEY_TYPE_DECIMAL, 'vote_field_name' => Model::KEY_TYPE_VARCHAR, 'vote_name' => Model::KEY_TYPE_VARCHAR, 'vote_comment' => Model::KEY_TYPE_VARCHAR, 'vote_reference_id' => Model::KEY_TYPE_INT, 'vote_hash' => Model::KEY_TYPE_VARCHAR, 'vote_level' => Model::KEY_TYPE_INT, 'vote_id' => Model::KEY_TYPE_INT, 'vote_created' => Model::KEY_TYPE_INT, 'vote_updated' => Model::KEY_TYPE_INT, 'vote_user_id' => Model::KEY_TYPE_INT];
    }

    protected function _getIdFieldName()
    {
        return 'vote_id';
    }

    protected function _getSelectByIdQuery($id, $fields)
    {
        return sprintf(
            'SELECT %s FROM %svoting_vote WHERE vote_id = %d',
            empty($fields) ? '*' : implode(', ', $fields),
            $this->_db->getResourcePrefix(),
            $id
        );
    }

    protected function _getSelectByIdsQuery($ids, $fields)
    {
        return sprintf(
            'SELECT %s FROM %svoting_vote WHERE vote_id IN (%s)',
            empty($fields) ? '*' : implode(', ', $fields),
            $this->_db->getResourcePrefix(),
            implode(', ', array_map('intval', $ids))
        );
    }

    protected function _getSelectByCriteriaQuery($criteriaStr, $fields)
    {
        return sprintf(
            'SELECT %1$s FROM %2$svoting_vote voting_vote WHERE %3$s',
            empty($fields) ? '*' : implode(', ', $fields),
            $this->_db->getResourcePrefix(),
            $criteriaStr
        );
    }

    protected function _getInsertQuery(&$values)
    {
        $values['vote_created'] = time();
        $values['vote_updated'] = 0;
        return sprintf('INSERT INTO %svoting_vote(vote_bundle_name, vote_entity_id, vote_value, vote_field_name, vote_name, vote_comment, vote_reference_id, vote_hash, vote_level, vote_id, vote_created, vote_updated, vote_user_id) VALUES(%s, %d, %F, %s, %s, %s, %d, %s, %d, %s, %d, %d, %d)', $this->_db->getResourcePrefix(), $this->_db->escapeString($values['vote_bundle_name']), $values['vote_entity_id'], $values['vote_value'], $this->_db->escapeString($values['vote_field_name']), $this->_db->escapeString($values['vote_name']), $this->_db->escapeString($values['vote_comment']), $values['vote_reference_id'], $this->_db->escapeString($values['vote_hash']), $values['vote_level'], empty($values['vote_id']) ? 'NULL' : intval($values['vote_id']), $values['vote_created'], $values['vote_updated'], $values['vote_user_id']);
    }

    protected function _getUpdateQuery($id, $values)
    {
        $last_update = $values['vote_updated'];
        $values['vote_updated'] = time();
        return sprintf('UPDATE %svoting_vote SET vote_bundle_name = %s, vote_entity_id = %d, vote_value = %F, vote_field_name = %s, vote_name = %s, vote_comment = %s, vote_reference_id = %d, vote_hash = %s, vote_level = %d, vote_updated = %d, vote_user_id = %d WHERE vote_id = %d AND vote_updated = %d', $this->_db->getResourcePrefix(), $this->_db->escapeString($values['vote_bundle_name']), $values['vote_entity_id'], $values['vote_value'], $this->_db->escapeString($values['vote_field_name']), $this->_db->escapeString($values['vote_name']), $this->_db->escapeString($values['vote_comment']), $values['vote_reference_id'], $this->_db->escapeString($values['vote_hash']), $values['vote_level'], $values['vote_updated'], $values['vote_user_id'], $id, $last_update);
    }

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

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

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

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