<?php
/**
 * Quotes\Collection.php
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */
namespace Magetop\Quotesystem\Model\ResourceModel\Quotes;

use \Magetop\Quotesystem\Model\ResourceModel\AbstractCollection;

class Collection extends AbstractCollection
{
     /**
      * @var string
      */
    protected $_idFieldName = 'entity_id';
    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(
            \Magetop\Quotesystem\Model\Quotes ::class,
            \Magetop\Quotesystem\Model\ResourceModel\Quotes ::class
        );
        $this->_map['fields']['entity_id'] = 'main_table.entity_id';
    }

    /**
     * Add Store Filter
     *
     * @param array $stores
     * @param bool $withAdminParam
     * @return void
     */
    public function addStoreFilter($stores, $withAdminParam = true)
    {
        if (!$this->getFlag('store_filter_added')) {
            $this->performAddStoreFilter($stores, $withAdminParam);
        }
        return $this;
    }

    /**
     * Set Table Records
     *
     * @param string $ids
     * @param array $columnsData
     * @return $this
     */
    public function setTableRecords($ids, $columnsData)
    {
        return $this->getConnection()->update(
            $this->getTable('mt_quotes'),
            $columnsData,
            $where = $ids
        );
    }
     /**
      * Retrieve all mageproduct_id for collection
      *
      * @param  int|string $limits
      * @param  int|string $offsets
      * @return array
      */
    public function getAllIds($limits = null, $offsets = null)
    {
        $idsSelect = $this->_getClearSelect();
        $idsSelect->columns('entity_id');
        $idsSelect->limit($limits, $offsets);
        $idsSelect->resetJoinLeft();

        return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams);
    }
    /**
     * Retrieve clear select
     *
     * @return \Magento\Framework\DB\Select
     */
    protected function _getClearSelect()
    {
        return $this->_buildClearSelect();
    }
     /**
      * Build clear select
      *
      * @param  \Magento\Framework\DB\Select $selectParam
      * @return \Magento\Framework\DB\Select
      */
    protected function _buildClearSelect($selectParam = null)
    {
        if (null === $selectParam) {
            $selectParam = clone $this->getSelect();
        }
        $selectParam->reset(\Magento\Framework\DB\Select::ORDER);
        $selectParam->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
        $selectParam->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
        $selectParam->reset(\Magento\Framework\DB\Select::COLUMNS);

        return $selectParam;
    }
}
