Validate.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Mageplaza
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Mageplaza.com license that is
  8. * available through the world-wide-web at this URL:
  9. * https://www.mageplaza.com/LICENSE.txt
  10. *
  11. * DISCLAIMER
  12. *
  13. * Do not edit or add to this file if you wish to upgrade this extension to newer
  14. * version in the future.
  15. *
  16. * @category Mageplaza
  17. * @package Mageplaza_Core
  18. * @copyright Copyright (c) 2016-2018 Mageplaza (http://www.mageplaza.com/)
  19. * @license https://www.mageplaza.com/LICENSE.txt
  20. */
  21. namespace Mageplaza\Core\Model\Message;
  22. use Magento\Framework\Notification\MessageInterface;
  23. use Magento\Framework\UrlInterface;
  24. use Mageplaza\Core\Helper\Validate as ValidateHelper;
  25. /**
  26. * Class Validate
  27. * @package Mageplaza\Core\Model\Message
  28. */
  29. class Validate implements MessageInterface
  30. {
  31. /**
  32. * @var \Mageplaza\Core\Helper\Validate
  33. */
  34. protected $_helper;
  35. /**
  36. * @var \Magento\Framework\UrlInterface
  37. */
  38. protected $urlBuilder;
  39. /**
  40. * @var array
  41. */
  42. protected $_needActiveModules = [];
  43. /**
  44. * Validate constructor.
  45. * @param \Mageplaza\Core\Helper\Validate $helper
  46. * @param \Magento\Framework\UrlInterface $urlBuilder
  47. */
  48. public function __construct(
  49. ValidateHelper $helper,
  50. UrlInterface $urlBuilder
  51. )
  52. {
  53. $this->_helper = $helper;
  54. $this->urlBuilder = $urlBuilder;
  55. }
  56. /**
  57. * Check whether all extensions are valid or not
  58. *
  59. * @return bool
  60. */
  61. public function isDisplayed()
  62. {
  63. $notActiveModules = $this->getModules();
  64. if (sizeof($notActiveModules)) {
  65. return true;
  66. }
  67. return false;
  68. }
  69. /**
  70. * @return array
  71. */
  72. public function getModules()
  73. {
  74. if (empty($this->_needActiveModules)) {
  75. $moduleLists = $this->_helper->getModuleList();
  76. foreach ($moduleLists as $module) {
  77. if ($this->_helper->needActive($module) && !$this->_helper->isModuleActive($module)) {
  78. $this->_needActiveModules[] = $module;
  79. }
  80. }
  81. }
  82. return $this->_needActiveModules;
  83. }
  84. /**
  85. * Retrieve unique message identity
  86. *
  87. * @return string
  88. */
  89. public function getIdentity()
  90. {
  91. return md5('MAGEPLAZA_VALIDATE_MESSAGE');
  92. }
  93. /**
  94. * Retrieve message text
  95. *
  96. * @return \Magento\Framework\Phrase|string
  97. */
  98. public function getText()
  99. {
  100. $modules = $this->getModules();
  101. if (empty($modules)) {
  102. return '';
  103. }
  104. $sectionName = $this->_helper->getConfigModulePath($modules[0]);
  105. $url = $this->urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => $sectionName]);
  106. return __(
  107. 'One or more Mageplaza extensions are not validated. Click <a href="%1">here</a> to validate them.',
  108. $url
  109. );
  110. }
  111. /**
  112. * Retrieve message severity
  113. *
  114. * @return int
  115. */
  116. public function getSeverity()
  117. {
  118. return self::SEVERITY_MAJOR;
  119. }
  120. }