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_Core
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: * Block, that can get data from layout or from registry.
29: * Can compare its data values by specified keys
30: *
31: * @category Mage
32: * @package Mage_Core
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Core_Block_Template_Facade extends Mage_Core_Block_Template
36: {
37: /**
38: * Just set data, like Varien_Object
39: *
40: * This method is to be used in layout.
41: * In layout it can be understood better, than setSomeKeyBlahBlah()
42: *
43: * @param string $key
44: * @param string $value
45: */
46: public function setDataByKey($key, $value)
47: {
48: $this->_data[$key] = $value;
49: }
50:
51: /**
52: * Also set data, but take the value from registry by registry key
53: *
54: * @param string $key
55: * @param string $registryKey
56: */
57: public function setDataByKeyFromRegistry($key, $registryKey)
58: {
59: $registryItem = Mage::registry($registryKey);
60: if (empty($registryItem)) {
61: return;
62: }
63: $value = $registryItem->getData($key);
64: $this->setDataByKey($key, $value);
65: }
66:
67: /**
68: * Check if data values by specified keys are equal
69: * $conditionKeys can be array or arbitrary set of params (func_get_args())
70: *
71: * @param array $conditionKeys
72: * @return bool
73: */
74: public function ifEquals($conditionKeys)
75: {
76: if (!is_array($conditionKeys)) {
77: $conditionKeys = func_get_args();
78: }
79:
80: // evaluate conditions (equality)
81: if (!empty($conditionKeys)) {
82: foreach ($conditionKeys as $key) {
83: if (!isset($this->_data[$key])) {
84: return false;
85: }
86: }
87: $lastValue = $this->_data[$key];
88: foreach ($conditionKeys as $key) {
89: if ($this->_data[$key] !== $lastValue) {
90: return false;
91: }
92: }
93: }
94: return true;
95: }
96: }
97: