PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/local/Evogue/Customer/Helper/Data.php

https://github.com/arush/desparation-deprecated
PHP | 309 lines | 290 code | 19 blank | 0 comment | 16 complexity | beb619650d8a0bbdf9b7bebe36b53836 MD5 | raw file
  1. <?php
  2. class Evogue_Customer_Helper_Data extends Mage_Core_Helper_Abstract {
  3. protected $_userDefinedAttributeCodes = array();
  4. public function getAttributeFormTypeIds($attribute) {
  5. $types = Mage::getResourceModel('eav/form_type')
  6. ->getFormTypesByAttribute($attribute);
  7. $typesIds = array();
  8. foreach ($types as $type) {
  9. $typesIds[] = $type['type_id'];
  10. }
  11. return $typesIds;
  12. }
  13. public function getCustomerAttributeFormOptions() {
  14. return array(
  15. array(
  16. 'label' => Mage::helper('evogue_customer')->__('Customer Checkout Register'),
  17. 'value' => 'checkout_register'
  18. ),
  19. array(
  20. 'label' => Mage::helper('evogue_customer')->__('Customer Registration'),
  21. 'value' => 'customer_account_create'
  22. ),
  23. array(
  24. 'label' => Mage::helper('evogue_customer')->__('Customer Account Edit'),
  25. 'value' => 'customer_account_edit'
  26. ),
  27. array(
  28. 'label' => Mage::helper('evogue_customer')->__('Admin Checkout'),
  29. 'value' => 'adminhtml_checkout'
  30. ),
  31. );
  32. }
  33. public function getCustomerAddressAttributeFormOptions() {
  34. return array(
  35. array(
  36. 'label' => Mage::helper('evogue_customer')->__('Customer Address Registration'),
  37. 'value' => 'customer_register_address'
  38. ),
  39. array(
  40. 'label' => Mage::helper('evogue_customer')->__('Customer Account Address'),
  41. 'value' => 'customer_address_edit'
  42. ),
  43. );
  44. }
  45. public function getAttributeInputTypes($inputType = null) {
  46. $inputTypes = array(
  47. 'text' => array(
  48. 'label' => Mage::helper('evogue_customer')->__('Text Field'),
  49. 'manage_options' => false,
  50. 'validate_types' => array(
  51. 'min_text_length',
  52. 'max_text_length',
  53. ),
  54. 'validate_filters' => array(
  55. 'alphanumeric',
  56. 'numeric',
  57. 'alpha',
  58. 'url',
  59. 'email',
  60. ),
  61. 'filter_types' => array(
  62. 'striptags',
  63. 'escapehtml'
  64. ),
  65. 'backend_type' => 'varchar',
  66. 'default_value' => 'text',
  67. ),
  68. 'textarea' => array(
  69. 'label' => Mage::helper('evogue_customer')->__('Text Area'),
  70. 'manage_options' => false,
  71. 'validate_types' => array(
  72. 'min_text_length',
  73. 'max_text_length',
  74. ),
  75. 'validate_filters' => array(),
  76. 'filter_types' => array(
  77. 'striptags',
  78. 'escapehtml'
  79. ),
  80. 'backend_type' => 'text',
  81. 'default_value' => 'textarea',
  82. ),
  83. 'multiline' => array(
  84. 'label' => Mage::helper('evogue_customer')->__('Multiple Line'),
  85. 'manage_options' => false,
  86. 'validate_types' => array(
  87. 'min_text_length',
  88. 'max_text_length',
  89. ),
  90. 'validate_filters' => array(
  91. 'alphanumeric',
  92. 'numeric',
  93. 'alpha',
  94. 'url',
  95. 'email',
  96. ),
  97. 'filter_types' => array(
  98. 'striptags',
  99. 'escapehtml'
  100. ),
  101. 'backend_type' => 'text',
  102. 'default_value' => 'text',
  103. ),
  104. 'date' => array(
  105. 'label' => Mage::helper('evogue_customer')->__('Date'),
  106. 'manage_options' => false,
  107. 'validate_types' => array(),
  108. 'validate_filters' => array(
  109. 'date'
  110. ),
  111. 'filter_types' => array(
  112. 'date'
  113. ),
  114. 'backend_model' => 'eav/entity_attribute_backend_datetime',
  115. 'backend_type' => 'datetime',
  116. 'default_value' => 'date',
  117. ),
  118. 'select' => array(
  119. 'label' => Mage::helper('evogue_customer')->__('Dropdown'),
  120. 'manage_options' => true,
  121. 'option_default' => 'radio',
  122. 'validate_types' => array(),
  123. 'validate_filters' => array(),
  124. 'filter_types' => array(),
  125. 'source_model' => 'eav/entity_attribute_source_table',
  126. 'backend_type' => 'int',
  127. 'default_value' => false,
  128. ),
  129. 'multiselect' => array(
  130. 'label' => Mage::helper('evogue_customer')->__('Multiple Select'),
  131. 'manage_options' => true,
  132. 'option_default' => 'checkbox',
  133. 'validate_types' => array(),
  134. 'filter_types' => array(),
  135. 'validate_filters' => array(),
  136. 'backend_model' => 'eav/entity_attribute_backend_array',
  137. 'source_model' => 'eav/entity_attribute_source_table',
  138. 'backend_type' => 'varchar',
  139. 'default_value' => false,
  140. ),
  141. 'boolean' => array(
  142. 'label' => Mage::helper('evogue_customer')->__('Yes/No'),
  143. 'manage_options' => false,
  144. 'validate_types' => array(),
  145. 'validate_filters' => array(),
  146. 'filter_types' => array(),
  147. 'source_model' => 'eav/entity_attribute_source_boolean',
  148. 'backend_type' => 'int',
  149. 'default_value' => 'yesno',
  150. ),
  151. 'file' => array(
  152. 'label' => Mage::helper('evogue_customer')->__('File (attachment)'),
  153. 'manage_options' => false,
  154. 'validate_types' => array(
  155. 'max_file_size',
  156. 'file_extensions'
  157. ),
  158. 'validate_filters' => array(),
  159. 'filter_types' => array(),
  160. 'backend_type' => 'varchar',
  161. 'default_value' => false,
  162. ),
  163. 'image' => array(
  164. 'label' => Mage::helper('evogue_customer')->__('Image File'),
  165. 'manage_options' => false,
  166. 'validate_types' => array(
  167. 'max_file_size',
  168. 'max_image_width',
  169. 'max_image_heght',
  170. ),
  171. 'validate_filters' => array(),
  172. 'filter_types' => array(),
  173. 'backend_type' => 'varchar',
  174. 'default_value' => false,
  175. ),
  176. );
  177. if (is_null($inputType)) {
  178. return $inputTypes;
  179. } else if (isset($inputTypes[$inputType])) {
  180. return $inputTypes[$inputType];
  181. }
  182. return array();
  183. }
  184. public function getFrontendInputOptions() {
  185. $inputTypes = $this->getAttributeInputTypes();
  186. $options = array();
  187. foreach ($inputTypes as $k => $v) {
  188. $options[] = array(
  189. 'value' => $k,
  190. 'label' => $v['label']
  191. );
  192. }
  193. return $options;
  194. }
  195. public function getAttributeValidateFilters() {
  196. return array(
  197. 'alphanumeric' => Mage::helper('evogue_customer')->__('Alphanumeric'),
  198. 'numeric' => Mage::helper('evogue_customer')->__('Numeric Only'),
  199. 'alpha' => Mage::helper('evogue_customer')->__('Alpha Only'),
  200. 'url' => Mage::helper('evogue_customer')->__('URL'),
  201. 'email' => Mage::helper('evogue_customer')->__('Email'),
  202. 'date' => Mage::helper('evogue_customer')->__('Date'),
  203. );
  204. }
  205. public function getAttributeFilterTypes() {
  206. return array(
  207. 'striptags' => Mage::helper('evogue_customer')->__('Strip HTML Tags'),
  208. 'escapehtml' => Mage::helper('evogue_customer')->__('Escape HTML Entities'),
  209. 'date' => Mage::helper('evogue_customer')->__('Normalize Date')
  210. );
  211. }
  212. public function getAttributeElementScopes() {
  213. return array(
  214. 'is_required' => 'website',
  215. 'is_visible' => 'website',
  216. 'multiline_count' => 'website',
  217. 'default_value_text' => 'website',
  218. 'default_value_yesno' => 'website',
  219. 'default_value_date' => 'website',
  220. 'default_value_textarea' => 'website'
  221. );
  222. }
  223. public function getAttributeDefaultValueByInput($inputType) {
  224. $inputTypes = $this->getAttributeInputTypes();
  225. if (isset($inputTypes[$inputType])) {
  226. $value = $inputTypes[$inputType]['default_value'];
  227. if ($value) {
  228. return 'default_value_' . $value;
  229. }
  230. }
  231. return false;
  232. }
  233. public function getAttributeValidateRules($inputType, array $data) {
  234. $inputTypes = $this->getAttributeInputTypes();
  235. $rules = array();
  236. if (isset($inputTypes[$inputType])) {
  237. foreach ($inputTypes[$inputType]['validate_types'] as $validateType) {
  238. if (!empty($data[$validateType])) {
  239. $rules[$validateType] = $data[$validateType];
  240. }
  241. }
  242. if (!empty($inputTypes[$inputType]['validate_filters']) && !empty($data['input_validation'])) {
  243. if (in_array($data['input_validation'], $inputTypes[$inputType]['validate_filters'])) {
  244. $rules['input_validation'] = $data['input_validation'];
  245. }
  246. }
  247. }
  248. return $rules;
  249. }
  250. public function getAttributeBackendModelByInputType($inputType) {
  251. $inputTypes = $this->getAttributeInputTypes();
  252. if (!empty($inputTypes[$inputType]['backend_model'])) {
  253. return $inputTypes[$inputType]['backend_model'];
  254. }
  255. return null;
  256. }
  257. public function getAttributeSourceModelByInputType($inputType) {
  258. $inputTypes = $this->getAttributeInputTypes();
  259. if (!empty($inputTypes[$inputType]['source_model'])) {
  260. return $inputTypes[$inputType]['source_model'];
  261. }
  262. return null;
  263. }
  264. public function getAttributeBackendTypeByInputType($inputType) {
  265. $inputTypes = $this->getAttributeInputTypes();
  266. if (!empty($inputTypes[$inputType]['backend_type'])) {
  267. return $inputTypes[$inputType]['backend_type'];
  268. }
  269. return null;
  270. }
  271. protected function _getUserDefinedAttributeCodes($entityTypeCode) {
  272. if (empty($this->_userDefinedAttributeCodes[$entityTypeCode])) {
  273. $this->_userDefinedAttributeCodes[$entityTypeCode] = array();
  274. $config = Mage::getSingleton('eav/config');
  275. foreach ($config->getEntityAttributeCodes($entityTypeCode) as $attributeCode) {
  276. $attribute = $config->getAttribute($entityTypeCode, $attributeCode);
  277. if ($attribute && $attribute->getIsUserDefined()) {
  278. $this->_userDefinedAttributeCodes[$entityTypeCode][] = $attributeCode;
  279. }
  280. }
  281. }
  282. return $this->_userDefinedAttributeCodes[$entityTypeCode];
  283. }
  284. public function getCustomerUserDefinedAttributeCodes() {
  285. return $this->_getUserDefinedAttributeCodes('customer');
  286. }
  287. public function getCustomerAddressUserDefinedAttributeCodes() {
  288. return $this->_getUserDefinedAttributeCodes('customer_address');
  289. }
  290. }