Skip to content

Commit

Permalink
MagePal Core 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Jul 3, 2020
0 parents commit 63c2f66
Show file tree
Hide file tree
Showing 21 changed files with 1,194 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Block/Adminhtml/Badge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\Core\Block\Adminhtml;

use Magento\Backend\Block\Template;
use MagePal\Core\Controller\Adminhtml\Version\Index;

class Badge extends Template
{
const SEARCH_URL = 'https://www.magepal.com/catalogsearch/result/?utm_source=search&utm_medium=admin&utm_campaign=core';

public function getNotificationUrl()
{
return $this->getUrl('magepal/version/index');
}

public function isAuthorized()
{
return $this->_authorization->isAllowed(Index::ADMIN_RESOURCE);
}

public function getSearchUrl()
{
return self::SEARCH_URL;
}
}
55 changes: 55 additions & 0 deletions Block/Adminhtml/System/Config/Composer/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* https://www.magepal.com | [email protected]
*/

namespace MagePal\Core\Block\Adminhtml\System\Config\Composer;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use MagePal\Core\Model\Module;

class Version extends Field
{
/**
* @var Module
*/
private $module;

/**
* @param Context $context
* @param Module $module
* @param array $data
*/
public function __construct(
Context $context,
Module $module,
array $data = []
) {
parent::__construct($context, $data);
$this->module = $module;
}

/**
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->module->getInstalledVersion($this->getModuleName());
}
}
59 changes: 59 additions & 0 deletions Block/Adminhtml/System/Config/Field/Extensions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* https://www.magepal.com | [email protected]
*/

namespace MagePal\Core\Block\Adminhtml\System\Config\Field;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use MagePal\Core\Model\Module;

class Extensions extends Field
{
/**
* @var string
*/
protected $_template = 'MagePal_Core::system/config/field/extensions.phtml';
/**
* @var Module
*/
private $module;

public function __construct(
Context $context,
Module $module,
array $data = []
) {
parent::__construct($context, $data);
$this->module = $module;
}

/**
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
return $this->toHtml();
}

/**
* @return int
*/
public function getUpdateCount()
{
return $this->module->getUpdateCount();
}

/**
* @return array
*/
public function getExtensionList()
{
return $this->module->getOutDatedExtension();
}
}
28 changes: 28 additions & 0 deletions Block/Adminhtml/System/Config/Field/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* https://www.magepal.com | [email protected]
*/

namespace MagePal\Core\Block\Adminhtml\System\Config\Field;

use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

class Search extends Field
{
/**
* @var string
*/
protected $_template = 'MagePal_Core::system/config/field/search.phtml';

/**
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
return $this->toHtml();
}
}
61 changes: 61 additions & 0 deletions Controller/Adminhtml/Version/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\Core\Controller\Adminhtml\Version;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
use MagePal\Core\Model\Module;

class Index extends Action
{
public const ADMIN_RESOURCE = 'MagePal_Core::config';
/**
* @var JsonFactory
*/
private $resultJsonFactory;
/**
* @var Module
*/
private $module;

/**
* Index constructor.
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param Module $module
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
Module $module
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->module = $module;
}
/**
* Index action
*
* @return ResultInterface
*/
public function execute()
{
$date = [
'success' => 1,
'count' => $this->module->getUpdateCount()
];

$result = $this->resultJsonFactory->create();
$result->setHeader('Cache-Control', 'max-age=302400', true);
$result->setHeader('Pragma', 'cache', true);
$result->setData($date);
return $result;
}
}
Loading

0 comments on commit 63c2f66

Please sign in to comment.