1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Store
36: extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
37: {
38: protected $_skipAllStoresLabel = false;
39: protected $_skipEmptyStoresLabel = false;
40:
41: 42: 43: 44: 45:
46: protected function _getStoreModel()
47: {
48: return Mage::getSingleton('adminhtml/system_store');
49: }
50:
51: 52: 53: 54: 55:
56: protected function _getShowAllStoresLabelFlag()
57: {
58: return $this->getColumn()->getData('skipAllStoresLabel')
59: ? $this->getColumn()->getData('skipAllStoresLabel')
60: : $this->_skipAllStoresLabel;
61: }
62:
63: 64: 65: 66: 67:
68: protected function _getShowEmptyStoresLabelFlag()
69: {
70: return $this->getColumn()->getData('skipEmptyStoresLabel')
71: ? $this->getColumn()->getData('skipEmptyStoresLabel')
72: : $this->_skipEmptyStoresLabel;
73: }
74:
75: 76: 77: 78: 79: 80:
81: public function render(Varien_Object $row)
82: {
83: $out = '';
84: $skipAllStoresLabel = $this->_getShowAllStoresLabelFlag();
85: $skipEmptyStoresLabel = $this->_getShowEmptyStoresLabelFlag();
86: $origStores = $row->getData($this->getColumn()->getIndex());
87:
88: if (is_null($origStores) && $row->getStoreName()) {
89: $scopes = array();
90: foreach (explode("\n", $row->getStoreName()) as $k => $label) {
91: $scopes[] = str_repeat(' ', $k * 3) . $label;
92: }
93: $out .= implode('<br/>', $scopes) . $this->__(' [deleted]');
94: return $out;
95: }
96:
97: if (empty($origStores) && !$skipEmptyStoresLabel) {
98: return '';
99: }
100: if (!is_array($origStores)) {
101: $origStores = array($origStores);
102: }
103:
104: if (empty($origStores)) {
105: return '';
106: }
107: elseif (in_array(0, $origStores) && count($origStores) == 1 && !$skipAllStoresLabel) {
108: return Mage::helper('adminhtml')->__('All Store Views');
109: }
110:
111: $data = $this->_getStoreModel()->getStoresStructure(false, $origStores);
112:
113: foreach ($data as $website) {
114: $out .= $website['label'] . '<br/>';
115: foreach ($website['children'] as $group) {
116: $out .= str_repeat(' ', 3) . $group['label'] . '<br/>';
117: foreach ($group['children'] as $store) {
118: $out .= str_repeat(' ', 6) . $store['label'] . '<br/>';
119: }
120: }
121: }
122:
123: return $out;
124: }
125:
126: 127: 128: 129: 130: 131:
132: public function renderExport(Varien_Object $row)
133: {
134: $out = '';
135: $skipAllStoresLabel = $this->_getShowAllStoresLabelFlag();
136: $origStores = $row->getData($this->getColumn()->getIndex());
137:
138: if (is_null($origStores) && $row->getStoreName()) {
139: $scopes = array();
140: foreach (explode("\n", $row->getStoreName()) as $k => $label) {
141: $scopes[] = str_repeat(' ', $k * 3) . $label;
142: }
143: $out .= implode("\r\n", $scopes) . $this->__(' [deleted]');
144: return $out;
145: }
146:
147: if (!is_array($origStores)) {
148: $origStores = array($origStores);
149: }
150:
151: if (in_array(0, $origStores) && !$skipAllStoresLabel) {
152: return Mage::helper('adminhtml')->__('All Store Views');
153: }
154:
155: $data = $this->_getStoreModel()->getStoresStructure(false, $origStores);
156:
157: foreach ($data as $website) {
158: $out .= $website['label'] . "\r\n";
159: foreach ($website['children'] as $group) {
160: $out .= str_repeat(' ', 3) . $group['label'] . "\r\n";
161: foreach ($group['children'] as $store) {
162: $out .= str_repeat(' ', 6) . $store['label'] . "\r\n";
163: }
164: }
165: }
166:
167: return $out;
168: }
169: }
170: