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) 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: * Adminhtml dashboard bar block
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Adminhtml_Block_Dashboard_Bar extends Mage_Adminhtml_Block_Dashboard_Abstract
36: {
37: protected $_totals = array();
38: protected $_currentCurrencyCode = null;
39:
40: protected function _construct()
41: {
42: parent::_construct();
43: $this->setTemplate('dashboard/bar.phtml');
44: }
45:
46: protected function getTotals()
47: {
48: return $this->_totals;
49: }
50:
51: public function addTotal($label, $value, $isQuantity=false)
52: {
53: /*if (!$isQuantity) {
54: $value = $this->format($value);
55: $decimals = substr($value, -2);
56: $value = substr($value, 0, -2);
57: } else {
58: $value = ($value != '')?$value:0;
59: $decimals = '';
60: }*/
61: if (!$isQuantity) {
62: $value = $this->format($value);
63: }
64: $decimals = '';
65: $this->_totals[] = array(
66: 'label' => $label,
67: 'value' => $value,
68: 'decimals' => $decimals,
69: );
70:
71: return $this;
72: }
73:
74: /**
75: * Formating value specific for this store
76: *
77: * @param decimal $price
78: * @return string
79: */
80: public function format($price)
81: {
82: return $this->getCurrency()->format($price);
83: }
84:
85: /**
86: * Setting currency model
87: *
88: * @param Mage_Directory_Model_Currency $currency
89: */
90: public function setCurrency($currency)
91: {
92: $this->_currency = $currency;
93: }
94:
95: /**
96: * Retrieve currency model if not set then return currency model for current store
97: *
98: * @return Mage_Directory_Model_Currency
99: */
100: public function getCurrency()
101: {
102: if (is_null($this->_currentCurrencyCode)) {
103: if ($this->getRequest()->getParam('store')) {
104: $this->_currentCurrencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrency();
105: } else if ($this->getRequest()->getParam('website')){
106: $this->_currentCurrencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrency();
107: } else if ($this->getRequest()->getParam('group')){
108: $this->_currentCurrencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrency();
109: } else {
110: $this->_currentCurrencyCode = Mage::app()->getStore()->getBaseCurrency();
111: }
112: }
113:
114: return $this->_currentCurrencyCode;
115: }
116: }
117: