<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_Agorae
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
namespace Webkul\Agorae\Controller\Adminhtml\Sliderimages;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Backend\App\Action;
use Magento\TestFramework\ErrorLog\Logger;

/**
 * Agorae Adminhtml Sliderimages massDisable Controller
 */
class MassDisable extends \Magento\Backend\App\Action
{
    /**
     * @var \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
     */
    protected $_fileUploaderFactory;

    /**
     * @var \Webkul\Agorae\Model\Sliderimages
     */
    protected $sliderImages;

    /**
     * @var \Magento\Ui\Component\MassAction\Filter
     */
    protected $uiFilter;

    /**
     * @param Action\Context $context
     * @param \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
     * @param \Webkul\Agorae\Model\Sliderimages $sliderImages
     * @param \Magento\Ui\Component\MassAction\Filter $uiFilter
     */
    public function __construct(
        Action\Context $context,
        \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
        \Webkul\Agorae\Model\Sliderimages $sliderImages,
        \Magento\Ui\Component\MassAction\Filter $uiFilter
    ) {
        $this->_fileUploaderFactory = $fileUploaderFactory;
        $this->sliderImages = $sliderImages;
        $this->uiFilter = $uiFilter;
        parent::__construct($context);
    }

    /**
     * {@inheritdoc}
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Webkul_Agorae::sliderimages');
    }

    /**
     * MassDisable Action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $sliderimagesModel = $this->sliderImages;
        $model = $this->uiFilter;
        $collection = $model->getCollection($sliderimagesModel->getCollection());
        foreach ($collection as $image) {
            $image->setStatus(0);
            $image->save();
        }
        $this->messageManager->addSuccess(__('Status set to "disabled" successfully.'));
        $resultRedirect = $this->resultRedirectFactory->create();
        return $resultRedirect->setPath('*/*/');
    }
}
