ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\GoogleMap\Model\Location;
|
||||
|
||||
class Delete extends \Olegnax\GoogleMap\Controller\Adminhtml\Location
|
||||
{
|
||||
|
||||
/**
|
||||
* 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('location_id');
|
||||
if ($id) {
|
||||
try {
|
||||
// init model and delete
|
||||
$model = $this->_objectManager->create(Location::class);
|
||||
$model->load($id);
|
||||
$model->delete();
|
||||
// display success message
|
||||
$this->messageManager->addSuccessMessage(__('You deleted the Location.'));
|
||||
// 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', ['location_id' => $id]);
|
||||
}
|
||||
}
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage(__('We can\'t find a Location to delete.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Olegnax\GoogleMap\Model\Location;
|
||||
|
||||
class Edit extends \Olegnax\GoogleMap\Controller\Adminhtml\Location
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
// 1. Get ID and create model
|
||||
$id = $this->getRequest()->getParam('location_id');
|
||||
$model = $this->_objectManager->create(Location::class);
|
||||
|
||||
// 2. Initial checking
|
||||
if ($id) {
|
||||
$model->load($id);
|
||||
if (!$model->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('This Location no longer exists.'));
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
$this->_coreRegistry->register('olegnax_googlemap_location', $model);
|
||||
|
||||
// 3. Build edit form
|
||||
/** @var Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$this->initPage($resultPage)->addBreadcrumb(
|
||||
$id ? __('Edit Location') : __('New Location'),
|
||||
$id ? __('Edit Location') : __('New Location')
|
||||
);
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Locations'));
|
||||
$resultPage->getConfig()->getTitle()->prepend(
|
||||
$model->getId()
|
||||
? __(
|
||||
'Edit Location %1',
|
||||
$model->getId()
|
||||
)
|
||||
: __('New Location')
|
||||
);
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->getConfig()->getTitle()->prepend(__("Location"));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\Result\Json;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\GoogleMap\Model\Location;
|
||||
|
||||
class InlineEdit extends Action
|
||||
{
|
||||
|
||||
protected $jsonFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param JsonFactory $jsonFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
JsonFactory $jsonFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->jsonFactory = $jsonFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Json $resultJson */
|
||||
$resultJson = $this->jsonFactory->create();
|
||||
$error = false;
|
||||
$messages = [];
|
||||
|
||||
if ($this->getRequest()->getParam('isAjax')) {
|
||||
$postItems = $this->getRequest()->getParam('items', []);
|
||||
if (!count($postItems)) {
|
||||
$messages[] = __('Please correct the data sent.');
|
||||
$error = true;
|
||||
} else {
|
||||
foreach (array_keys($postItems) as $modelId) {
|
||||
/** @var Location $model */
|
||||
$model = $this->_objectManager->create(Location::class)->load($modelId);
|
||||
try {
|
||||
$model->setData(array_replace($model->getData(), $postItems[$modelId]));
|
||||
$model->save();
|
||||
} catch (Exception $e) {
|
||||
$messages[] = "[Location ID: {$modelId}] {$e->getMessage()}";
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resultJson->setData([
|
||||
'messages' => $messages,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
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\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
class NewAction extends Location
|
||||
{
|
||||
|
||||
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,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_GoogleMap
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\App\Request\DataPersistorInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Olegnax\GoogleMap\Model\Location;
|
||||
|
||||
class Save extends Action
|
||||
{
|
||||
|
||||
protected $dataPersistor;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param DataPersistorInterface $dataPersistor
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
DataPersistorInterface $dataPersistor
|
||||
) {
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @noinspection PhpRedundantCatchClauseInspection
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
if ($data) {
|
||||
$id = $this->getRequest()->getParam('location_id');
|
||||
|
||||
$model = $this->_objectManager->create(Location::class)->load($id);
|
||||
if (!$model->getId() && $id) {
|
||||
$this->messageManager->addErrorMessage(__('This Location no longer exists.'));
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
$model->setData($data);
|
||||
|
||||
try {
|
||||
$model->save();
|
||||
$this->messageManager->addSuccessMessage(__('You saved the Location.'));
|
||||
$this->dataPersistor->clear('olegnax_googlemap_location');
|
||||
|
||||
if ($this->getRequest()->getParam('back')) {
|
||||
return $resultRedirect->setPath('*/*/edit', ['location_id' => $model->getId()]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Location.'));
|
||||
}
|
||||
|
||||
$this->dataPersistor->set('olegnax_googlemap_location', $data);
|
||||
return $resultRedirect->setPath(
|
||||
'*/*/edit',
|
||||
[
|
||||
'location_id' => $this->getRequest()->getParam('location_id'),
|
||||
]
|
||||
);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user