1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: willi |
5
|
|
|
* Date: 11.03.18 |
6
|
|
|
* Time: 12:51 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Firegento\DevDashboard\Controller\Adminhtml\Ajax; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Firegento\DevDashboard\Model\Config; |
13
|
|
|
|
14
|
|
|
class Getconfig extends \Magento\Backend\App\Action |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Magento\Framework\Controller\Result\JsonFactory |
18
|
|
|
*/ |
19
|
|
|
protected $_resultJsonFactory; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Magento\Backend\Model\Auth\Session |
23
|
|
|
*/ |
24
|
|
|
protected $_authSession; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Firegento\DevDashboard\Api\ConfigRepositoryInterface |
28
|
|
|
*/ |
29
|
|
|
protected $_configRepository; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
const ADMIN_RESOURCE = 'Firegento_DevDashboard::devdashboard'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \Magento\Backend\App\Action\Context $context |
36
|
|
|
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory |
37
|
|
|
* @param \Magento\Backend\Model\Auth\Session $authSession, |
38
|
|
|
* @param \Firegento\DevDashboard\Api\ConfigRepositoryInterface $configRepository |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
\Magento\Backend\App\Action\Context $context, |
42
|
|
|
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, |
43
|
|
|
\Magento\Backend\Model\Auth\Session $authSession, |
44
|
|
|
\Firegento\DevDashboard\Api\ConfigRepositoryInterface $configRepository |
45
|
|
|
) { |
46
|
|
|
|
47
|
|
|
$this->_resultJsonFactory = $resultJsonFactory; |
48
|
|
|
$this->_authSession = $authSession; |
49
|
|
|
$this->_configRepository = $configRepository; |
50
|
|
|
parent::__construct($context); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return \Magento\Framework\Controller\Result\Json |
56
|
|
|
*/ |
57
|
|
|
public function execute() |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
$message = null; |
61
|
|
|
|
62
|
|
|
$userId = $this->_authSession->getUser()->getId(); |
63
|
|
|
|
64
|
|
|
try { |
65
|
|
|
/** @var Config $config */ |
66
|
|
|
$config = $this->_configRepository->getByUserId($userId); |
67
|
|
|
if($config->getId()){ |
68
|
|
|
$message = [ |
69
|
|
|
'success' => true, |
70
|
|
|
'user_id' => $config->getData('user_id'), |
71
|
|
|
'use_devdashboard' => $config->getData('use_devdashboard'), |
72
|
|
|
'configuration' => $config->getData('configuration') |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
catch (\Exception $e) { |
77
|
|
|
$message = [ |
78
|
|
|
'success' => false, |
79
|
|
|
'mesage' => $e->getMessage() |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** @var \Magento\Framework\Controller\Result\Json $result */ |
84
|
|
|
$result = $this->_resultJsonFactory->create(); |
85
|
|
|
return $result->setData($message); |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |