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_ImportExport
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: * ImportExport config model
29: *
30: * @category Mage
31: * @package Mage_ImportExport
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_ImportExport_Model_Config
35: {
36: /**
37: * Get data about models from specified config key.
38: *
39: * @static
40: * @param string $configKey
41: * @throws Mage_Core_Exception
42: * @return array
43: */
44: public static function getModels($configKey)
45: {
46: $entities = array();
47:
48: foreach (Mage::getConfig()->getNode($configKey)->asCanonicalArray() as $entityType => $entityParams) {
49: if (empty($entityParams['model_token'])) {
50: Mage::throwException(Mage::helper('importexport')->__('Node does not has model token tag'));
51: }
52: $entities[$entityType] = array(
53: 'model' => $entityParams['model_token'],
54: 'label' => empty($entityParams['label']) ? $entityType : $entityParams['label']
55: );
56: }
57: return $entities;
58: }
59:
60: /**
61: * Get model params as combo-box options.
62: *
63: * @static
64: * @param string $configKey
65: * @param boolean $withEmpty OPTIONAL Include 'Please Select' option or not
66: * @return array
67: */
68: public static function getModelsComboOptions($configKey, $withEmpty = false)
69: {
70: $options = array();
71:
72: if ($withEmpty) {
73: $options[] = array('label' => Mage::helper('importexport')->__('-- Please Select --'), 'value' => '');
74: }
75: foreach (self::getModels($configKey) as $type => $params) {
76: $options[] = array('value' => $type, 'label' => $params['label']);
77: }
78: return $options;
79: }
80:
81: /**
82: * Get model params as array of options.
83: *
84: * @static
85: * @param string $configKey
86: * @param boolean $withEmpty OPTIONAL Include 'Please Select' option or not
87: * @return array
88: */
89: public static function getModelsArrayOptions($configKey, $withEmpty = false)
90: {
91: $options = array();
92: if ($withEmpty) {
93: $options[0] = Mage::helper('importexport')->__('-- Please Select --');
94: }
95: foreach (self::getModels($configKey) as $type => $params) {
96: $options[$type] = $params['label'];
97: }
98: return $options;
99: }
100: }
101: