ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax BannerSlider
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_BannerSlider
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\BannerSlider\Model\Group;
|
||||
|
||||
class Delete extends \Olegnax\BannerSlider\Controller\Adminhtml\Group {
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_BannerSlider::Group_Delete';
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute() {
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
// check if we know what should be deleted
|
||||
$id = $this->getRequest()->getParam('id');
|
||||
if ($id) {
|
||||
try {
|
||||
// init model and delete
|
||||
$model = $this->_objectManager->create( Group::class);
|
||||
$model->load($id);
|
||||
$model->delete();
|
||||
// display success message
|
||||
$this->messageManager->addSuccessMessage(__('Banner group has been deleted.'));
|
||||
$this->messageManager->addWarningMessage(__('Banner group has beed changed. Please go to Cache Management and Flush Magento Cache.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch ( Exception $e) {
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
// go back to edit form
|
||||
return $resultRedirect->setPath('*/*/edit', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage(__('We can\'t find a Group to delete.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax BannerSlider
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_BannerSlider
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Olegnax\BannerSlider\Model\Group;
|
||||
|
||||
class Edit extends \Olegnax\BannerSlider\Controller\Adminhtml\Group {
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_BannerSlider::Group_Edit';
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context, Registry $coreRegistry, PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute() {
|
||||
$id = $this->getRequest()->getParam('id');
|
||||
$model = $this->_objectManager->create( Group::class);
|
||||
|
||||
if ($id) {
|
||||
$model->load($id);
|
||||
if (!$model->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('This Group no longer exists.'));
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_coreRegistry->register('olegnax_bannerslider_group', $model);
|
||||
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$this->initPage($resultPage)->addBreadcrumb(
|
||||
$id ? __('Edit Group') : __('New Group'),
|
||||
$id ? __('Edit Group') : __('New Group')
|
||||
);
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Group'));
|
||||
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Group %1',
|
||||
$model->getId()) : __('New Group') );
|
||||
return $resultPage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax BannerSlider
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_BannerSlider
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action {
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_BannerSlider::Group_Index';
|
||||
|
||||
protected $_pageFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context, PageFactory $pageFactory) {
|
||||
$this->_pageFactory = $pageFactory;
|
||||
return parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$resultPage = $this->_pageFactory->create();
|
||||
$resultPage->getConfig()->getTitle()->prepend((__('Banner Group Manager')));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax BannerSlider
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_BannerSlider
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Forward;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
class NewAction extends Group {
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_BannerSlider::Group_New';
|
||||
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context, Registry $coreRegistry, ForwardFactory $resultForwardFactory
|
||||
) {
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* New action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute() {
|
||||
/** @var Forward $resultForward */
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
return $resultForward->forward('edit');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax BannerSlider
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_BannerSlider
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\BannerSlider\Controller\Adminhtml\Group;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Olegnax\BannerSlider\Model\Group;
|
||||
|
||||
class Save extends Action {
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context, PageFactory $resultPageFactory
|
||||
) {
|
||||
parent::__construct( $context );
|
||||
}
|
||||
|
||||
protected function _isAllowed() {
|
||||
return $this->_authorization->isAllowed('Olegnax_BannerSlider::Group_New') || $this->_authorization->isAllowed('Olegnax_BannerSlider::Group_Edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute() {
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$id = $this->getRequest()->getParam( 'group_id' );
|
||||
$model = $this->_objectManager->create( Group::class );
|
||||
$identifier = (string)$data[ 'identifier' ];
|
||||
if ( empty( $identifier ) ) {
|
||||
$identifier = $data[ 'group_name' ];
|
||||
}
|
||||
$_identifier = $identifier = str_replace( ' ', '-', strtolower( trim( $identifier ) ) );
|
||||
$suffix = '';
|
||||
$index = 0;
|
||||
do {
|
||||
$identifier = $_identifier . $suffix;
|
||||
$index++;
|
||||
$suffix = '-' . $index;
|
||||
} while ( !$this->isUniqueIdentifier( $identifier, $id ) );
|
||||
$data[ 'identifier' ] = $identifier;
|
||||
|
||||
$model->setData( $data );
|
||||
|
||||
try {
|
||||
$model->save();
|
||||
|
||||
$this->messageManager->addSuccess( __( 'Banner group has been saved.' ) );
|
||||
$this->messageManager->addWarningMessage( __( 'Banner group has been changed. Please go to Cache Management and Flush Magento Cache.' ) );
|
||||
if ( $this->getRequest()->getParam( 'back' ) ) {
|
||||
return $resultRedirect->setPath( '*/*/edit', [
|
||||
'id' => $model->getId(),
|
||||
'_current' => true ] );
|
||||
}
|
||||
$this->_objectManager->get( 'Magento\Backend\Model\Session' )->setFormData( false );
|
||||
return $resultRedirect->setPath( '*/*/' );
|
||||
} catch ( Exception $e ) {
|
||||
throw new \Magento\Framework\Exception\LocalizedException( __( '%1', $e->getMessage() ) );
|
||||
$this->messageManager->addException( $e, __( 'Something went wrong.' ) );
|
||||
}
|
||||
$this->_getSession()->setFormData( $data );
|
||||
return $resultRedirect->setPath( '*/*/edit', [
|
||||
'id' => $id ] );
|
||||
}
|
||||
|
||||
protected function isUniqueIdentifier( $identifier, $id = 0 ) {
|
||||
if ( empty( $identifier ) ) {
|
||||
return false;
|
||||
}
|
||||
$itemCollection = ObjectManager::getInstance()->get( '\Olegnax\BannerSlider\Model\ResourceModel\Group\CollectionFactory' )->create()
|
||||
->addFieldToFilter( 'identifier', $identifier )
|
||||
->addFieldToFilter( 'group_id', [ 'neq' => $id ] );
|
||||
return count( $itemCollection ) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user