PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php

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