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_Eav
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: class Mage_Eav_Model_Entity_Attribute_Source_Boolean extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
29: {
30: /**
31: * Retrieve all options array
32: *
33: * @return array
34: */
35: public function getAllOptions()
36: {
37: if (is_null($this->_options)) {
38: $this->_options = array(
39: array(
40: 'label' => Mage::helper('eav')->__('Yes'),
41: 'value' => 1
42: ),
43: array(
44: 'label' => Mage::helper('eav')->__('No'),
45: 'value' => 0
46: ),
47: );
48: }
49: return $this->_options;
50: }
51:
52: /**
53: * Retrieve option array
54: *
55: * @return array
56: */
57: public function getOptionArray()
58: {
59: $_options = array();
60: foreach ($this->getAllOptions() as $option) {
61: $_options[$option['value']] = $option['label'];
62: }
63: return $_options;
64: }
65:
66: /**
67: * Get a text for option value
68: *
69: * @param string|integer $value
70: * @return string
71: */
72: public function getOptionText($value)
73: {
74: $options = $this->getAllOptions();
75: foreach ($options as $option) {
76: if ($option['value'] == $value) {
77: return $option['label'];
78: }
79: }
80: return false;
81: }
82:
83: /**
84: * Retrieve flat column definition
85: *
86: * @return array
87: */
88: public function getFlatColums()
89: {
90: $attributeCode = $this->getAttribute()->getAttributeCode();
91: $column = array(
92: 'unsigned' => false,
93: 'default' => null,
94: 'extra' => null
95: );
96:
97: if (Mage::helper('core')->useDbCompatibleMode()) {
98: $column['type'] = 'tinyint(1)';
99: $column['is_null'] = true;
100: } else {
101: $column['type'] = Varien_Db_Ddl_Table::TYPE_SMALLINT;
102: $column['length'] = 1;
103: $column['nullable'] = true;
104: $column['comment'] = $attributeCode . ' column';
105: }
106:
107: return array($attributeCode => $column);
108: }
109:
110: /**
111: * Retrieve Indexes(s) for Flat
112: *
113: * @return array
114: */
115: public function getFlatIndexes()
116: {
117: $indexes = array();
118:
119: $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode());
120: $indexes[$index] = array(
121: 'type' => 'index',
122: 'fields' => array($this->getAttribute()->getAttributeCode())
123: );
124:
125: return $indexes;
126: }
127:
128: /**
129: * Retrieve Select For Flat Attribute update
130: *
131: * @param int $store
132: * @return Varien_Db_Select|null
133: */
134: public function getFlatUpdateSelect($store)
135: {
136: return Mage::getResourceModel('eav/entity_attribute')
137: ->getFlatUpdateSelect($this->getAttribute(), $store);
138: }
139: }
140: