1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
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://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Adminhtml email template model
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Adminhtml_Model_Email_Template extends Mage_Core_Model_Email_Template
36: {
37: /**
38: * Xml path to email template nodes
39: *
40: */
41: const XML_PATH_TEMPLATE_EMAIL = '//sections/*/groups/*/fields/*[source_model="adminhtml/system_config_source_email_template"]';
42:
43: /**
44: * Collect all system config pathes where current template is used as default
45: *
46: * @return array
47: */
48: public function getSystemConfigPathsWhereUsedAsDefault()
49: {
50: $templateCode = $this->getOrigTemplateCode();
51: if (!$templateCode) {
52: return array();
53: }
54: $paths = array();
55:
56: $configSections = Mage::getSingleton('adminhtml/config')->getSections();
57:
58: // find nodes which are using $templateCode value
59: $defaultCfgNodes = Mage::getConfig()->getXpath('default/*/*[*="' . $templateCode . '"]');
60: if (!is_array($defaultCfgNodes)) {
61: return array();
62: }
63:
64: foreach ($defaultCfgNodes as $node) {
65: // create email template path in system.xml
66: $sectionName = $node->getParent()->getName();
67: $groupName = $node->getName();
68: $fieldName = substr($templateCode, strlen($sectionName . '_' . $groupName . '_'));
69: $paths[] = array('path' => implode('/', array($sectionName, $groupName, $fieldName)));
70: }
71: return $paths;
72: }
73:
74: /**
75: * Collect all system config pathes where current template is currently used
76: *
77: * @return array
78: */
79: public function getSystemConfigPathsWhereUsedCurrently()
80: {
81: $templateId = $this->getId();
82: if (!$templateId) {
83: return array();
84: }
85: $paths = array();
86:
87: $configSections = Mage::getSingleton('adminhtml/config')->getSections();
88:
89: // look for node entries in all system.xml that use source_model=adminhtml/system_config_source_email_template
90: // they are will be templates, what we try find
91: $sysCfgNodes = $configSections->xpath(self::XML_PATH_TEMPLATE_EMAIL);
92: if (!is_array($sysCfgNodes)) {
93: return array();
94: }
95:
96: foreach ($sysCfgNodes as $fieldNode) {
97:
98: $groupNode = $fieldNode->getParent()->getParent();
99: $sectionNode = $groupNode->getParent()->getParent();
100:
101: // create email template path in system.xml
102: $sectionName = $sectionNode->getName();
103: $groupName = $groupNode->getName();
104: $fieldName = $fieldNode->getName();
105:
106: $paths[] = implode('/', array($sectionName, $groupName, $fieldName));
107: }
108:
109: $configData = $this->_getResource()->getSystemConfigByPathsAndTemplateId($paths, $templateId);
110: if (!$configData) {
111: return array();
112: }
113:
114: return $configData;
115: }
116: }
117: