PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Enterprise/Rma/Helper/Eav.php

https://bitbucket.org/kdms/sh-magento
PHP | 214 lines | 131 code | 10 blank | 73 comment | 6 complexity | c6cee6bccddee656a2a304f6f055e56a MD5 | raw file
  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  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 Enterprise
  22. * @package Enterprise_Rma
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * RMA Helper
  28. *
  29. * @category Enterprise
  30. * @package Enterprise_Rma
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Enterprise_Rma_Helper_Eav extends Enterprise_Eav_Helper_Data
  34. {
  35. /**
  36. * complicated array of select-typed attribute values for all stores
  37. *
  38. * @var array
  39. */
  40. protected $_attributeOptionValues = array();
  41. /**
  42. * Default attribute entity type code
  43. *
  44. * @return string
  45. */
  46. protected function _getEntityTypeCode()
  47. {
  48. return 'rma_item';
  49. }
  50. /**
  51. * Return data array of RMA item attribute Input Types
  52. *
  53. * @param string|null $inputType
  54. * @return array
  55. */
  56. public function getAttributeInputTypes($inputType = null)
  57. {
  58. $inputTypes = array(
  59. 'text' => array(
  60. 'label' => $this->__('Text Field'),
  61. 'manage_options' => false,
  62. 'validate_types' => array(
  63. 'min_text_length',
  64. 'max_text_length',
  65. ),
  66. 'validate_filters' => array(
  67. 'alphanumeric',
  68. 'numeric',
  69. 'alpha',
  70. 'url',
  71. 'email',
  72. ),
  73. 'filter_types' => array(
  74. 'striptags',
  75. 'escapehtml'
  76. ),
  77. 'backend_type' => 'varchar',
  78. 'default_value' => 'text',
  79. ),
  80. 'textarea' => array(
  81. 'label' => $this->__('Text Area'),
  82. 'manage_options' => false,
  83. 'validate_types' => array(
  84. 'min_text_length',
  85. 'max_text_length',
  86. ),
  87. 'validate_filters' => array(),
  88. 'filter_types' => array(
  89. 'striptags',
  90. 'escapehtml'
  91. ),
  92. 'backend_type' => 'text',
  93. 'default_value' => 'textarea',
  94. ),
  95. 'select' => array(
  96. 'label' => $this->__('Dropdown'),
  97. 'manage_options' => true,
  98. 'option_default' => 'radio',
  99. 'validate_types' => array(),
  100. 'validate_filters' => array(),
  101. 'filter_types' => array(),
  102. 'source_model' => 'eav/entity_attribute_source_table',
  103. 'backend_type' => 'int',
  104. 'default_value' => false,
  105. ),
  106. 'image' => array(
  107. 'label' => $this->__('Image File'),
  108. 'manage_options' => false,
  109. 'validate_types' => array(
  110. 'max_file_size',
  111. 'max_image_width',
  112. 'max_image_heght',
  113. ),
  114. 'validate_filters' => array(),
  115. 'filter_types' => array(),
  116. 'backend_type' => 'varchar',
  117. 'default_value' => false,
  118. ),
  119. );
  120. if (is_null($inputType)) {
  121. return $inputTypes;
  122. } else if (isset($inputTypes[$inputType])) {
  123. return $inputTypes[$inputType];
  124. }
  125. return array();
  126. }
  127. /**
  128. * Get array of select-typed attribute values depending by store
  129. *
  130. * Uses internal protected method, which must use data from protected variable
  131. *
  132. * @param null|int|Mage_Core_Model_Store $storeId
  133. * @param bool $useDefaultValue
  134. * @return array
  135. */
  136. public function getAttributeOptionStringValues($storeId = null, $useDefaultValue = true)
  137. {
  138. $values = $this->_getAttributeOptionValues($storeId, $useDefaultValue);
  139. $return = array();
  140. foreach ($values as $temValue) {
  141. foreach ($temValue as $value) {
  142. $return[$value['option_id']] = $value['value'];
  143. }
  144. }
  145. return $return;
  146. }
  147. /**
  148. * Get array of key=>value pair for passed attribute code depending by store
  149. *
  150. * Uses internal protected method, which must use data from protected variable
  151. *
  152. * @param string $attributeCode
  153. * @param null|int|Mage_Core_Model_Store $storeId
  154. * @param bool $useDefaultValue
  155. * @return array
  156. */
  157. public function getAttributeOptionValues($attributeCode, $storeId = null, $useDefaultValue = true)
  158. {
  159. $values = $this->_getAttributeOptionValues($storeId, $useDefaultValue);
  160. $return = array();
  161. if (isset($values[$attributeCode])) {
  162. foreach ($values[$attributeCode] as $key => $value) {
  163. $return[$key] = $value['value'];
  164. }
  165. }
  166. return $return;
  167. }
  168. /**
  169. * Get complicated array of select-typed attribute values depending by store
  170. *
  171. * @param null|int|Mage_Core_Model_Store $storeId
  172. * @param bool $useDefaultValue
  173. * @return array
  174. */
  175. protected function _getAttributeOptionValues($storeId = null, $useDefaultValue = true)
  176. {
  177. if (is_null($storeId)) {
  178. $storeId = Mage::app()->getStore()->getId();
  179. } elseif ($storeId instanceof Mage_Core_Model_Store) {
  180. $storeId = $storeId->getId();
  181. }
  182. if (!isset($this->_attributeOptionValues[$storeId])) {
  183. $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
  184. ->setStoreFilter($storeId, $useDefaultValue);
  185. $optionCollection
  186. ->getSelect()
  187. ->join(
  188. array('ea' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')),
  189. 'main_table.attribute_id = ea.attribute_id',
  190. array('attribute_code' => 'ea.attribute_code'))
  191. ->join(
  192. array('eat' => Mage::getSingleton('core/resource')->getTableName('eav/entity_type')),
  193. 'ea.entity_type_id = eat.entity_type_id',
  194. array(''))
  195. ->where('eat.entity_type_code = ?', $this->_getEntityTypeCode());
  196. $value = array();
  197. foreach($optionCollection as $option){
  198. $value[$option->getAttributeCode()][$option->getOptionId()] = $option->getData();
  199. }
  200. $this->_attributeOptionValues[$storeId] = $value;
  201. }
  202. return $this->_attributeOptionValues[$storeId];
  203. }
  204. }