PageRenderTime 24ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/core/Mage/Adminhtml/Block/Widget/Container.php

https://github.com/leochaves/magento-pt_br
PHP | 206 lines | 96 code | 14 blank | 96 comment | 16 complexity | 3439cf161394fb560a968df5a2ba7040 MD5 | raw file
Possible License(s): GPL-2.0
  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_Adminhtml
  23. * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Adminhtml container block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Widget_Container extends Mage_Adminhtml_Block_Template
  34. {
  35. /**
  36. * So called "container controller" to specify group of blocks participating in some action
  37. *
  38. * @var string
  39. */
  40. protected $_controller = 'empty';
  41. /**
  42. * Array of buttons
  43. *
  44. *
  45. * @var array
  46. */
  47. protected $_buttons = array(
  48. -1 => array(),
  49. 0 => array(),
  50. 1 => array(),
  51. );
  52. /**
  53. * Header text
  54. *
  55. * @var string
  56. */
  57. protected $_headerText = 'Container Widget Header';
  58. /**
  59. * Add a button
  60. *
  61. * @param string $id
  62. * @param array $data
  63. * @param integer $level
  64. * @param string|null $placement area, that button should be displayed in ('header', 'footer', null)
  65. * @return Mage_Adminhtml_Block_Widget_Container
  66. */
  67. protected function _addButton($id, $data, $level = 0, $sortOrder = 100, $area = 'header')
  68. {
  69. if (!isset($this->_buttons[$level])) {
  70. $this->_buttons[$level] = array();
  71. }
  72. $this->_buttons[$level][$id] = $data;
  73. $this->_buttons[$level][$id]['area'] = $area;
  74. return $this;
  75. }
  76. /**
  77. * Remove existing button
  78. *
  79. * @param string $id
  80. * @return Mage_Adminhtml_Block_Widget_Container
  81. */
  82. protected function _removeButton($id)
  83. {
  84. foreach ($this->_buttons as $level => $buttons) {
  85. if (isset($buttons[$id])) {
  86. unset($this->_buttons[$level][$id]);
  87. }
  88. }
  89. return $this;
  90. }
  91. /**
  92. * Update specified button property
  93. *
  94. * @param string $id
  95. * @param string|null $key
  96. * @param mixed $data
  97. * @return Mage_Adminhtml_Block_Widget_Container
  98. */
  99. protected function _updateButton($id, $key=null, $data)
  100. {
  101. foreach ($this->_buttons as $level => $buttons) {
  102. if (isset($buttons[$id])) {
  103. if (!empty($key)) {
  104. if ($child = $this->getChild($id . '_button')) {
  105. $child->setData($key, $data);
  106. }
  107. if ('level' == $key) {
  108. $this->_buttons[$data][$id] = $this->_buttons[$level][$id];
  109. unset($this->_buttons[$level][$id]);
  110. } else {
  111. $this->_buttons[$level][$id][$key] = $data;
  112. }
  113. } else {
  114. $this->_buttons[$level][$id] = $data;
  115. }
  116. break;
  117. }
  118. }
  119. return $this;
  120. }
  121. protected function _prepareLayout()
  122. {
  123. foreach ($this->_buttons as $level => $buttons) {
  124. foreach ($buttons as $id => $data) {
  125. $this->setChild($id . '_button', $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data));
  126. }
  127. }
  128. return parent::_prepareLayout();
  129. }
  130. /**
  131. * Produce buttons HTML
  132. *
  133. * @param string $area
  134. * @return string
  135. */
  136. public function getButtonsHtml($area = null)
  137. {
  138. $out = '';
  139. foreach ($this->_buttons as $level => $buttons) {
  140. foreach ($buttons as $id => $data) {
  141. if ($area && isset($data['area']) && ($area != $data['area'])) {
  142. continue;
  143. }
  144. $out .= $this->getChildHtml($id . '_button');
  145. }
  146. }
  147. return $out;
  148. }
  149. /**
  150. * Get header text
  151. *
  152. * @return string
  153. */
  154. public function getHeaderText()
  155. {
  156. return $this->_headerText;
  157. }
  158. /**
  159. * Get header CSS class
  160. *
  161. * @return string
  162. */
  163. public function getHeaderCssClass()
  164. {
  165. return 'head-' . strtr($this->_controller, '_', '-');
  166. }
  167. /**
  168. * Get header HTML
  169. *
  170. * @return string
  171. */
  172. public function getHeaderHtml()
  173. {
  174. return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
  175. }
  176. /**
  177. * Check if there's anything to display in footer
  178. *
  179. * @return boolean
  180. */
  181. public function hasFooterButtons()
  182. {
  183. foreach ($this->_buttons as $level => $buttons) {
  184. foreach ($buttons as $id => $data) {
  185. if (isset($data['area']) && ('footer' == $data['area'])) {
  186. return true;
  187. }
  188. }
  189. }
  190. return false;
  191. }
  192. }