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: class Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Main_Layout
35: extends Mage_Adminhtml_Block_Template implements Varien_Data_Form_Element_Renderer_Interface
36: {
37: 38: 39:
40: protected $_element = null;
41:
42: 43: 44:
45: protected function _construct()
46: {
47: parent::_construct();
48: $this->setTemplate('widget/instance/edit/layout.phtml');
49: }
50:
51: 52: 53: 54: 55:
56: public function render(Varien_Data_Form_Element_Abstract $element)
57: {
58: $this->setElement($element);
59: return $this->toHtml();
60: }
61:
62: 63: 64: 65: 66: 67:
68: public function setElement(Varien_Data_Form_Element_Abstract $element)
69: {
70: $this->_element = $element;
71: return $this;
72: }
73:
74: 75: 76: 77: 78:
79: public function getElement()
80: {
81: return $this->_element;
82: }
83:
84: 85: 86: 87: 88:
89: public function getCategoriesChooserUrl()
90: {
91: return $this->getUrl('*/*/categories', array('_current' => true));
92: }
93:
94: 95: 96: 97: 98:
99: public function getProductsChooserUrl()
100: {
101: return $this->getUrl('*/*/products', array('_current' => true));
102: }
103:
104: 105: 106: 107: 108:
109: public function getBlockChooserUrl()
110: {
111: return $this->getUrl('*/*/blocks', array('_current' => true));
112: }
113:
114: 115: 116: 117: 118:
119: public function getTemplateChooserUrl()
120: {
121: return $this->getUrl('*/*/template', array('_current' => true));
122: }
123:
124: 125: 126: 127: 128:
129: public function getDisplayOnSelectHtml()
130: {
131: $selectBlock = $this->getLayout()->createBlock('core/html_select')
132: ->setName('widget_instance[{{id}}][page_group]')
133: ->setId('widget_instance[{{id}}][page_group]')
134: ->setClass('required-entry page_group_select select')
135: ->setExtraParams("onchange=\"WidgetInstance.displayPageGroup(this.value+\'_{{id}}\')\"")
136: ->setOptions($this->_getDisplayOnOptions());
137: return $selectBlock->toHtml();
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147:
148: protected function _getDisplayOnOptions()
149: {
150: $options = array();
151: $options[] = array(
152: 'value' => '',
153: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('-- Please Select --'))
154: );
155: $options[] = array(
156: 'label' => Mage::helper('widget')->__('Categories'),
157: 'value' => array(
158: array(
159: 'value' => 'anchor_categories',
160: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Anchor Categories'))
161: ),
162: array(
163: 'value' => 'notanchor_categories',
164: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Non-Anchor Categories'))
165: )
166: )
167: );
168: foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) {
169: $productsOptions[] = array(
170: 'value' => $typeId.'_products',
171: 'label' => $this->helper('core')->jsQuoteEscape($type['label'])
172: );
173: }
174: array_unshift($productsOptions, array(
175: 'value' => 'all_products',
176: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('All Product Types'))
177: ));
178: $options[] = array(
179: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Products')),
180: 'value' => $productsOptions
181: );
182: $options[] = array(
183: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Generic Pages')),
184: 'value' => array(
185: array(
186: 'value' => 'all_pages',
187: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('All Pages'))
188: ),
189: array(
190: 'value' => 'pages',
191: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Specified Page'))
192: )
193: )
194: );
195: return $options;
196: }
197:
198: 199: 200: 201: 202:
203: public function getDisplayOnContainers()
204: {
205: $container = array();
206: $container['anchor'] = array(
207: 'label' => 'Categories',
208: 'code' => 'categories',
209: 'name' => 'anchor_categories',
210: 'layout_handle' => 'default,catalog_category_layered',
211: 'is_anchor_only' => 1,
212: 'product_type_id' => ''
213: );
214: $container['notanchor'] = array(
215: 'label' => 'Categories',
216: 'code' => 'categories',
217: 'name' => 'notanchor_categories',
218: 'layout_handle' => 'default,catalog_category_default',
219: 'is_anchor_only' => 0,
220: 'product_type_id' => ''
221: );
222: $container['all_products'] = array(
223: 'label' => 'Products',
224: 'code' => 'products',
225: 'name' => 'all_products',
226: 'layout_handle' => 'default,catalog_product_view',
227: 'is_anchor_only' => '',
228: 'product_type_id' => ''
229: );
230: foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) {
231: $container[$typeId] = array(
232: 'label' => 'Products',
233: 'code' => 'products',
234: 'name' => $typeId . '_products',
235: 'layout_handle' => 'default,catalog_product_view,PRODUCT_TYPE_'.$typeId,
236: 'is_anchor_only' => '',
237: 'product_type_id' => $typeId
238: );
239: }
240: return $container;
241: }
242:
243: 244: 245: 246: 247:
248: public function getLayoutsChooser()
249: {
250: $layouts = $this->getLayout()
251: ->createBlock('widget/adminhtml_widget_instance_edit_chooser_layout')
252: ->setSelectName('widget_instance[{{id}}][pages][layout_handle]')
253: ->setArea($this->getWidgetInstance()->getArea())
254: ->setPackage($this->getWidgetInstance()->getPackage())
255: ->setTheme($this->getWidgetInstance()->getTheme());
256: return $layouts->toHtml();
257: }
258:
259: 260: 261: 262: 263:
264: public function getAddLayoutButtonHtml()
265: {
266: $button = $this->getLayout()->createBlock('adminhtml/widget_button')
267: ->setData(array(
268: 'label' => Mage::helper('widget')->__('Add Layout Update'),
269: 'onclick' => 'WidgetInstance.addPageGroup({})',
270: 'class' => 'add'
271: ));
272: return $button->toHtml();
273: }
274:
275: 276: 277: 278: 279:
280: public function getRemoveLayoutButtonHtml()
281: {
282: $button = $this->getLayout()->createBlock('adminhtml/widget_button')
283: ->setData(array(
284: 'label' => $this->helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Remove Layout Update')),
285: 'onclick' => 'WidgetInstance.removePageGroup(this)',
286: 'class' => 'delete'
287: ));
288: return $button->toHtml();
289: }
290:
291: 292: 293: 294: 295:
296: public function getPageGroups()
297: {
298: $widgetInstance = $this->getWidgetInstance();
299: $pageGroups = array();
300: if ($widgetInstance->getPageGroups()) {
301: foreach ($widgetInstance->getPageGroups() as $pageGroup) {
302: $pageGroups[] = array(
303: 'page_id' => $pageGroup['page_id'],
304: 'group' => $pageGroup['page_group'],
305: 'block' => $pageGroup['block_reference'],
306: 'for_value' => $pageGroup['page_for'],
307: 'layout_handle' => $pageGroup['layout_handle'],
308: $pageGroup['page_group'].'_entities' => $pageGroup['entities'],
309: 'template' => $pageGroup['page_template']
310: );
311: }
312: }
313: return $pageGroups;
314: }
315: }
316: