Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 54c144c

Browse files
committed
Initial commit
1 parent 61edece commit 54c144c

36 files changed

+2825
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.zip
2+
debug.log
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Api;
3+
4+
use PCAPredict\Addressy\Model\SettingsDataInterface;
5+
use Magento\Framework\Api\SearchCriteriaInterface;
6+
7+
interface SettingsDataRepositoryInterface
8+
{
9+
public function save(SettingsDataInterface $page);
10+
11+
public function getById($id);
12+
13+
public function getList(SearchCriteriaInterface $criteria);
14+
15+
public function delete(SettingsDataInterface $page);
16+
17+
public function deleteById($id);
18+
}

Block/Adminhtml/Main.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Block\Adminhtml;
3+
4+
class Main extends \Magento\Framework\View\Element\Template
5+
{
6+
protected $settingsDataFactory;
7+
protected $settingsData;
8+
protected $resultJsonFactory;
9+
protected $urlInterface;
10+
11+
public function __construct(
12+
\Magento\Framework\View\Element\Template\Context $context,
13+
\PCAPredict\Addressy\Model\SettingsDataFactory $settingsDataFactory,
14+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
15+
)
16+
{
17+
$this->settingsDataFactory = $settingsDataFactory;
18+
$this->resultJsonFactory = $resultJsonFactory;
19+
$this->urlInterface = $context->getUrlBuilder();
20+
parent::__construct($context);
21+
}
22+
23+
function _prepareLayout()
24+
{
25+
$settings = $this->settingsDataFactory->create();
26+
$this->settingsData = $settings->load(1);
27+
}
28+
29+
function execute()
30+
{
31+
32+
}
33+
34+
function getAjaxUrl()
35+
{
36+
return $this->urlInterface->getUrl();
37+
}
38+
39+
function getAccountCode()
40+
{
41+
if ($this->settingsData)
42+
return $this->settingsData->getAccountCode();
43+
else
44+
return null;
45+
}
46+
47+
function getEmailAddress()
48+
{
49+
if ($this->settingsData)
50+
return $this->settingsData->getEmailAddress();
51+
else
52+
return null;
53+
}
54+
55+
function isLoggedIn()
56+
{
57+
return getAccountCode() != null;
58+
}
59+
60+
}

Controller/Adminhtml/Login/Index.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Controller\Adminhtml\Login;
3+
class Index extends \Magento\Backend\App\AbstractAction {
4+
5+
protected $settingsDataFactory;
6+
7+
/**
8+
* @param \Magento\Backend\App\Action\Context $context
9+
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
10+
*/
11+
public function __construct(
12+
\Magento\Backend\App\Action\Context $context,
13+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
14+
\PCAPredict\Addressy\Model\SettingsDataFactory $settingsDataFactory
15+
) {
16+
$this->resultJsonFactory = $resultJsonFactory;
17+
$this->settingsDataFactory = $settingsDataFactory;
18+
return parent::__construct($context);
19+
}
20+
21+
/**
22+
* @return \Magento\Framework\Controller\Result\Json
23+
*/
24+
public function execute() {
25+
/** @var \Magento\Framework\Controller\Result\Json $result */
26+
$result = $this->resultJsonFactory->create();
27+
28+
$email = $this->getRequest()->getParam('email_address');
29+
$accCode = $this->getRequest()->getParam('account_code');
30+
$accTok = $this->getRequest()->getParam('account_token');
31+
$settings = $this->settingsDataFactory->create();
32+
try
33+
{
34+
$settingsData = $settings->load(1);
35+
$settingsData->setEmailAddress($email);
36+
$settingsData->setAccountCode($accCode);
37+
$settingsData->setAccountToken($accTok);
38+
$settingsData->save();
39+
}
40+
catch(\Exception $ex)
41+
{
42+
return $result->setData(['success' => false]);
43+
}
44+
45+
return $result->setData(['success' => true]);
46+
}
47+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Controller\Adminhtml\Settings;
3+
class Index extends \Magento\Backend\App\Action{
4+
5+
protected $resultPageFactory;
6+
protected $settingsDataFactory;
7+
8+
/**
9+
* @var \Magento\Framework\HTTP\ZendClientFactory
10+
*/
11+
protected $httpClientFactory;
12+
13+
/**
14+
* @var \Magento\Framework\Message\ManagerInterface
15+
*/
16+
protected $messageManager;
17+
18+
public function __construct(
19+
\Magento\Backend\App\Action\Context $context,
20+
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
21+
\PCAPredict\Addressy\Model\SettingsDataFactory $settingsDataFactory,
22+
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory
23+
)
24+
{
25+
$this->resultPageFactory = $resultPageFactory;
26+
$this->settingsDataFactory = $settingsDataFactory;
27+
$this->httpClientFactory = $httpClientFactory;
28+
return parent::__construct($context);
29+
}
30+
31+
public function execute(){
32+
33+
if ($this->getRequest()->isAjax())
34+
{
35+
$action = $this->getRequest()->getParam('action');
36+
switch($action)
37+
{
38+
case 'logout':
39+
try
40+
{
41+
$settings = $this->settingsDataFactory->create();
42+
$collection = $settings->getCollection();
43+
$data = $collection->getData();
44+
if ($data)
45+
{
46+
$settingsData = $settings->load(1);
47+
$settingsData->setAccountCode('');
48+
$settingsData->setEmailAddress('');
49+
$settingsData->setAccountToken('');
50+
51+
$settingsData->save();
52+
}
53+
$this->messageManager->addSuccess( __('You have successfully logged out from Addressy!') );
54+
}
55+
catch(\Exception $e)
56+
{
57+
$this->messageManager->addError( __('There was a problem logging out of Addressy!') );
58+
}
59+
break;
60+
61+
case 'save':
62+
$email = $this->getRequest()->getParam('email_address');
63+
$accCode = $this->getRequest()->getParam('account_code');
64+
$accTok = $this->getRequest()->getParam('account_token');
65+
$customjavascriptfront = $this->getRequest()->getParam('custom_javascript_front');
66+
$customjavascriptback = $this->getRequest()->getParam('custom_javascript_back');
67+
68+
$settings = $this->settingsDataFactory->create();
69+
70+
try
71+
{
72+
$settingsData = $settings->load(1);
73+
$settingsData->setEmailAddress($email);
74+
$settingsData->setAccountCode($accCode);
75+
$settingsData->setAccountToken($accTok);
76+
$settingsData->setCustomJavascriptFront($customjavascriptfront);
77+
$settingsData->setCustomJavascriptBack($customjavascriptback);
78+
79+
$settingsData->save();
80+
}
81+
catch(\Exception $ex)
82+
{
83+
var_dump($ex.getMessage);
84+
}
85+
break;
86+
default:
87+
throw new \Exception("Invalid action: " . $action);
88+
}
89+
}
90+
91+
$page = $this->resultPageFactory->create();
92+
$page->setActiveMenu('PCAPredict_Addressy::Settings');
93+
$page->getConfig()->getTitle()->prepend(__('Addressy Settings'));
94+
return $page;
95+
}
96+
97+
protected function _isAllowed()
98+
{
99+
return $this->_authorization->isAllowed('PCAPredict_Addressy::settings');
100+
}
101+
}

Helper/SettingsData.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Helper;
3+
4+
class SettingsData extends \Magento\Framework\App\Helper\AbstractHelper
5+
{
6+
7+
/**
8+
* @var \Magento\Framework\Escaper
9+
*/
10+
protected $escaper;
11+
12+
/**
13+
* @var \PCAPredict\Addressy\Model\SettingsDataFactory
14+
*/
15+
protected $settingsDataFactory;
16+
17+
/**
18+
* @param \Magento\Framework\App\Helper\Context $context
19+
* @param \Magento\Framework\Escaper $escaper
20+
* @param \PCAPredict\Addressy\Model\SettingsDataFactory $settingsDataFactory
21+
*/
22+
public function __construct(
23+
\Magento\Framework\App\Helper\Context $context,
24+
\Magento\Framework\Escaper $escaper,
25+
\PCAPredict\Addressy\Model\SettingsDataFactory $settingsDataFactory
26+
) {
27+
$this->escaper = $escaper;
28+
$this->settingsDataFactory = $settingsDataFactory;
29+
parent::__construct($context);
30+
}
31+
32+
public function getEmailAddress()
33+
{
34+
$settings = $this->settingsDataFactory->create();
35+
$this->settingsData = $settings->load(1);
36+
return $this->escaper->escapeHtml(
37+
$this->settingsData->getEmailAddress()
38+
);
39+
}
40+
41+
public function getAccountCode()
42+
{
43+
$settings = $this->settingsDataFactory->create();
44+
$this->settingsData = $settings->load(1);
45+
return $this->escaper->escapeHtml(
46+
$this->settingsData->getAccountCode()
47+
);
48+
}
49+
50+
public function getAccountToken()
51+
{
52+
$settings = $this->settingsDataFactory->create();
53+
$this->settingsData = $settings->load(1);
54+
return $this->settingsData->getAccountToken();
55+
}
56+
57+
public function getCustomJavaScriptFront()
58+
{
59+
$settings = $this->settingsDataFactory->create();
60+
$this->settingsData = $settings->load(1);
61+
return $this->settingsData->getCustomJavascriptFront();
62+
}
63+
64+
public function getCustomJavaScriptBack()
65+
{
66+
$settings = $this->settingsDataFactory->create();
67+
$this->settingsData = $settings->load(1);
68+
return $this->settingsData->getCustomJavascriptBack();
69+
}
70+
}

LICENSE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://www.gnu.org/licenses/gpl-3.0.en.html

Model/ResourceModel/SettingsData.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Model\ResourceModel;
3+
class SettingsData extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4+
{
5+
protected function _construct()
6+
{
7+
$this->_init('pcapredict_addressy_settingsdata','pcapredict_addressy_settingsdata_id');
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Model\ResourceModel\SettingsData;
3+
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
4+
{
5+
protected function _construct()
6+
{
7+
$this->_init('PCAPredict\Addressy\Model\SettingsData','PCAPredict\Addressy\Model\ResourceModel\SettingsData');
8+
}
9+
}

Model/SettingsData.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace PCAPredict\Addressy\Model;
3+
class SettingsData extends \Magento\Framework\Model\AbstractModel implements SettingsDataInterface, \Magento\Framework\DataObject\IdentityInterface
4+
{
5+
const CACHE_TAG = 'pcapredict_addressy_settingsdata';
6+
7+
protected function _construct()
8+
{
9+
$this->_init('PCAPredict\Addressy\Model\ResourceModel\SettingsData');
10+
}
11+
12+
public function getIdentities()
13+
{
14+
return [self::CACHE_TAG . '_' . $this->getId()];
15+
}
16+
}

0 commit comments

Comments
 (0)