PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/local/AW/All/Block/Additional/Website.php

https://bitbucket.org/deniskulikouski/belvg.deniska
PHP | 229 lines | 172 code | 33 blank | 24 comment | 31 complexity | 9c75053ea4530b530568b946fd12da77 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * aheadWorks Co.
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the EULA
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://ecommerce.aheadworks.com/AW-LICENSE.txt
  11. *
  12. * =================================================================
  13. * MAGENTO EDITION USAGE NOTICE
  14. * =================================================================
  15. * This software is designed to work with Magento community edition and
  16. * its use on an edition other than specified is prohibited. aheadWorks does not
  17. * provide extension support in case of incorrect edition use.
  18. * =================================================================
  19. *
  20. * @category AW
  21. * @package AW_Advancedreports
  22. * @version 2.8.0
  23. * @copyright Copyright (c) 2010-2012 aheadWorks Co. (http://www.aheadworks.com)
  24. * @license http://ecommerce.aheadworks.com/AW-LICENSE.txt
  25. */
  26. class AW_All_Block_Additional_Website extends Mage_Adminhtml_Block_Abstract
  27. {
  28. const SUCCESS_RESULT = '<span class="available">%s</span>';
  29. const ERROR_RESULT = '<span class="error">%s</span>';
  30. protected $_rewrites = null;
  31. public function getHeaderText()
  32. {
  33. return $this->__('Website Info');
  34. }
  35. public function getHtmlId()
  36. {
  37. return 'website_plugin';
  38. }
  39. public function getTemplate()
  40. {
  41. return 'aw_all/additional_website.phtml';
  42. }
  43. public function getMagentoCronStatusToHtml($fieldName = 'scheduled_at')
  44. {
  45. $scheduleCollection = Mage::getModel('cron/schedule')->getCollection();
  46. $scheduleCollection
  47. ->setOrder($fieldName)
  48. ->setPageSize(1)
  49. ->setCurPage(1);
  50. $scheduleModel = $scheduleCollection->getFirstItem();
  51. $result = sprintf(self::ERROR_RESULT, $this->__('Never'));
  52. if ($scheduleModel->getId()
  53. && $scheduleModel->getData($fieldName) != '0000-00-00 00:00:00'
  54. ) {
  55. $findDate = new Zend_Date($scheduleModel->getData($fieldName), Varien_Date::DATETIME_INTERNAL_FORMAT);
  56. $today = new Zend_Date(null, Zend_Date::DATE_SHORT);
  57. $result = sprintf(self::SUCCESS_RESULT, $findDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
  58. if ($findDate->compare($today, Zend_Date::DATE_SHORT) < 0) {
  59. $result = sprintf(self::ERROR_RESULT, $findDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
  60. }
  61. }
  62. return $result;
  63. }
  64. public function getCompilationStatusToHtml()
  65. {
  66. $result = sprintf(self::SUCCESS_RESULT, $this->__('Disabled'));
  67. if (defined('COMPILER_INCLUDE_PATH')) {
  68. $result = sprintf(self::ERROR_RESULT, $this->__('Enabled'));
  69. }
  70. return $result;
  71. }
  72. public function getRewrites()
  73. {
  74. if (null === $this->_rewrites) {
  75. $result = array();
  76. foreach ($this->getModulesArray() as $moduleName => $options) {
  77. if (!array_key_exists('codePool', $options)) {
  78. continue;
  79. }
  80. $_moduleConfigFilePath = Mage::getConfig()->getModuleDir('etc', $moduleName) . DS . 'config.xml';
  81. if (!file_exists($_moduleConfigFilePath)) {
  82. continue;
  83. }
  84. $_moduleConfigFile = file_get_contents($_moduleConfigFilePath);
  85. $_configXml = new DOMDocument();
  86. $_configXml->loadXML($_moduleConfigFile);
  87. $result = $this->_getRewritesFromConfigFile($_configXml, $result);
  88. }
  89. foreach ($result as $rewritedPath => $_rewrites) {
  90. if (count($_rewrites) < 2) {
  91. unset($result[$rewritedPath]);
  92. continue;
  93. }
  94. $_classNames = array('aw' => array(), 'other' => array());
  95. foreach ($_rewrites as $_rewriteClass) {
  96. $_modulePath = explode('_', $_rewriteClass);
  97. $_usedClass = Mage::getConfig()->getGroupedClassName(strtolower($_modulePath[2]), $rewritedPath);
  98. $_rewriteClassHtml = sprintf(self::ERROR_RESULT, $_rewriteClass);
  99. if ($_usedClass == $_rewriteClass) {
  100. $_rewriteClassHtml = sprintf(self::SUCCESS_RESULT, $_rewriteClass);
  101. }
  102. if ($this->isAWModule($_rewriteClass)) {
  103. $_classNames['aw'][] = $_rewriteClassHtml;
  104. } else {
  105. $_classNames['other'][] = $_rewriteClassHtml;
  106. }
  107. }
  108. unset($result[$rewritedPath]);
  109. array_push($result, $_classNames);
  110. }
  111. $this->_rewrites = $result;
  112. }
  113. return $this->_rewrites;
  114. }
  115. protected function getModulesArray()
  116. {
  117. return Mage::getConfig()->getNode('modules')->asArray();
  118. }
  119. public function isAWModule($className)
  120. {
  121. $_modulePath = explode('_', $className);
  122. if (count($_modulePath) != 0 && $_modulePath[0] == 'AW') {
  123. return true;
  124. }
  125. return false;
  126. }
  127. protected function _getRewritesFromConfigFile($_configXml, $result)
  128. {
  129. $nodeTypes = array('blocks', 'models', 'helpers');
  130. foreach ($nodeTypes as $nodeType) {
  131. if (!$_configXml->documentElement) {
  132. continue;
  133. }
  134. foreach ($_configXml->documentElement->getElementsByTagName($nodeType) as $nodeElements) {
  135. foreach ($nodeElements->getElementsByTagName('rewrite') as $nodeAttribute) {
  136. $moduleName = $nodeAttribute->parentNode->tagName;
  137. foreach ($nodeAttribute->getElementsByTagName('*') as $childNode) {
  138. $rewriteClass = $childNode->nodeValue;
  139. $key = $moduleName . DS . $childNode->tagName;
  140. if (!isset($result[$key])) {
  141. $result[$key] = array();
  142. }
  143. $result[$key][] = $rewriteClass;
  144. }
  145. }
  146. }
  147. }
  148. return $result;
  149. }
  150. public function getWebsiteThemesParams()
  151. {
  152. $result = array();
  153. $stores = Mage::app()->getStores();
  154. foreach ($stores as $storeModel) {
  155. $storeDesignModel = Mage::getModel('core/design_package')->setStore($storeModel);
  156. $_designRules = Mage::getModel('core/design')->loadChange($storeModel->getId());
  157. $_packageName = $storeDesignModel->getPackageName();
  158. if (null !== $_designRules->getPackage() && $_designRules->getPackage() != $_packageName) {
  159. $_packageName = $_designRules->getPackage();
  160. }
  161. $_templatesPath = $storeDesignModel->getTheme('template');
  162. if (null !== $_designRules->getTheme() && $_designRules->getTheme() != $_templatesPath) {
  163. $_templatesPath = $_designRules->getTheme();
  164. }
  165. $_storeDesign = array(
  166. 'store' => $storeModel->getWebsite()->getName() . DS . $storeModel->getName(),
  167. 'package' => $_packageName,
  168. 'templates' => $_templatesPath,
  169. 'skin' => $storeDesignModel->getTheme('skin'),
  170. 'layout' => $storeDesignModel->getTheme('layout')
  171. );
  172. array_push($result, $_storeDesign);
  173. }
  174. return $result;
  175. }
  176. public function getDisabledAWModules()
  177. {
  178. $result = array();
  179. foreach ($this->getModulesArray() as $moduleName => $options) {
  180. if (!$this->isAWModule($moduleName)) {
  181. continue;
  182. }
  183. $_source = array();
  184. if (!array_key_exists('active', $options) || !in_array($options['active'], array('true', '1'))) {
  185. array_push($_source, 'xml');
  186. }
  187. if (Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) {
  188. array_push($_source, 'output');
  189. }
  190. if (count($_source) != 0) {
  191. $result[] = array('module_name' => $moduleName, 'source' => implode('/', $_source));
  192. }
  193. }
  194. return $result;
  195. }
  196. }