1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29:
30: class Mage_Reports_Helper_Data extends Mage_Core_Helper_Abstract
31: {
32: const REPORT_PERIOD_TYPE_DAY = 'day';
33: const REPORT_PERIOD_TYPE_MONTH = 'month';
34: const REPORT_PERIOD_TYPE_YEAR = 'year';
35: 36: 37: 38: 39: 40: 41: 42:
43: public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
44: {
45: $intervals = array();
46: if (!$from && !$to){
47: return $intervals;
48: }
49:
50: $start = new Zend_Date($from, Varien_Date::DATE_INTERNAL_FORMAT);
51:
52: if ($period == self::REPORT_PERIOD_TYPE_DAY) {
53: $dateStart = $start;
54: }
55:
56: if ($period == self::REPORT_PERIOD_TYPE_MONTH) {
57: $dateStart = new Zend_Date(date("Y-m", $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
58: }
59:
60: if ($period == self::REPORT_PERIOD_TYPE_YEAR) {
61: $dateStart = new Zend_Date(date("Y", $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
62: }
63:
64: $dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT);
65:
66: while ($dateStart->compare($dateEnd) <= 0) {
67: switch ($period) {
68: case self::REPORT_PERIOD_TYPE_DAY :
69: $t = $dateStart->toString('yyyy-MM-dd');
70: $dateStart->addDay(1);
71: break;
72: case self::REPORT_PERIOD_TYPE_MONTH:
73: $t = $dateStart->toString('yyyy-MM');
74: $dateStart->addMonth(1);
75: break;
76: case self::REPORT_PERIOD_TYPE_YEAR:
77: $t = $dateStart->toString('yyyy');
78: $dateStart->addYear(1);
79: break;
80: }
81: $intervals[] = $t;
82: }
83: return $intervals;
84: }
85:
86: public function prepareIntervalsCollection($collection, $from, $to, $periodType = self::REPORT_PERIOD_TYPE_DAY)
87: {
88: $intervals = $this->getIntervals($from, $to, $periodType);
89:
90: foreach ($intervals as $interval) {
91: $item = Mage::getModel('adminhtml/report_item');
92: $item->setPeriod($interval);
93: $item->setIsEmpty();
94: $collection->addItem($item);
95: }
96: }
97: }
98:
99: