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: /**
29: * Adminhtml abstract dashboard helper.
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: abstract class Mage_Adminhtml_Helper_Dashboard_Abstract extends Mage_Core_Helper_Data
36: {
37: /**
38: * Helper collection
39: *
40: * @var Mage_Core_Model_Mysql_Collection_Abstract|Mage_Eav_Model_Entity_Collection_Abstract|array
41: */
42: protected $_collection;
43:
44: /**
45: * Parameters for helper
46: *
47: * @var array
48: */
49: protected $_params = array();
50:
51: public function getCollection()
52: {
53: if(is_null($this->_collection)) {
54: $this->_initCollection();
55: }
56: return $this->_collection;
57: }
58:
59: abstract protected function _initCollection();
60:
61: /**
62: * Returns collection items
63: *
64: * @return array
65: */
66: public function getItems()
67: {
68: return is_array($this->getCollection()) ? $this->getCollection() : $this->getCollection()->getItems();
69: }
70:
71: public function getCount()
72: {
73: return sizeof($this->getItems());
74: }
75:
76: public function getColumn($index)
77: {
78: $result = array();
79: foreach ($this->getItems() as $item) {
80: if (is_array($item)) {
81: if(isset($item[$index])) {
82: $result[] = $item[$index];
83: } else {
84: $result[] = null;
85: }
86: } elseif ($item instanceof Varien_Object) {
87: $result[] = $item->getData($index);
88: } else {
89: $result[] = null;
90: }
91: }
92: return $result;
93: }
94:
95: public function setParam($name, $value)
96: {
97: $this->_params[$name] = $value;
98: }
99:
100: public function setParams(array $params)
101: {
102: $this->_params = $params;
103: }
104:
105: public function getParam($name)
106: {
107: if(isset($this->_params[$name])) {
108: return $this->_params[$name];
109: }
110:
111: return null;
112: }
113:
114: public function getParams()
115: {
116: return $this->_params;
117: }
118:
119: }
120: