SetEnableAll.php 1.79 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<?php
/*------------------------------------------------------------------------
# SM Mega Menu - Version 3.2.0
# Copyright (c) 2015 YouTech Company. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: YouTech Company
# Websites: http://www.magentech.com
-------------------------------------------------------------------------*/
namespace Sm\MegaMenu\Controller\Adminhtml\MenuItems;

use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class SetEnableAll extends \Magento\Backend\App\Action
{
	protected $resultPageFactory;

	public function __construct(
		Context $context,
		PageFactory $resultPageFactory
	)
	{
		$this->resultPageFactory = $resultPageFactory;
		parent::__construct($context);
	}

	public function createMenuItemsResource()
	{
		return $this->_objectManager->create('Sm\MegaMenu\Model\ResourceModel\MenuItems');
	}

	public function createMenuItemsCollection()
	{
		return $this->_objectManager->create('Sm\MegaMenu\Model\ResourceModel\MenuItems\Collection');
	}

	public function execute()
	{
		$groupId = $this->getRequest()->getParam('gid');
		if ($groupId)
		{
			$mainTable = $this->createMenuItemsResource()->getMainTable();
			$resultRedirect = $this->resultRedirectFactory->create();
			try{
				$this->createMenuItemsCollection()->setEnableAll($mainTable, $groupId);
				$this->messageManager->addSuccess(__('You enable all items was successfully.'));
				return $resultRedirect->setPath('*/*/newaction', [
					'gid' => $groupId,
					'activeTab' => 'menuitems'
				]);
			} catch (\Exception $e) {
				$this->messageManager->addError($e->getMessage());
				return $resultRedirect->setPath('*/*/newaction', [
					'gid' => $groupId,
					'activeTab' => 'menuitems'
				]);
			}
		}
	}
}