00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Reports_Model_Mysql4_Report_Collection
00036 {
00037
00038 protected $_from;
00039 protected $_to;
00040 protected $_period;
00041
00042 protected $_model;
00043
00044 protected $_intervals;
00045
00046 protected $_pageSize;
00047
00048 protected $_storeIds;
00049
00050 protected function _construct()
00051 {
00052
00053 }
00054
00055 public function setPeriod($period)
00056 {
00057 $this->_period = $period;
00058 }
00059
00060 public function setInterval($from, $to)
00061 {
00062 $this->_from = $from;
00063 $this->_to = $to;
00064 }
00065
00066 public function getIntervals()
00067 {
00068 if (!$this->_intervals) {
00069 $this->_intervals = array();
00070 if (!$this->_from && !$this->_to){
00071 return $this->_intervals;
00072 }
00073 $dateStart = new Zend_Date($this->_from);
00074 $dateStart2 = new Zend_Date($this->_from);
00075
00076 $dateEnd = new Zend_Date($this->_to);
00077
00078
00079 $t = array();
00080 while ($dateStart->compare($dateEnd)<=0) {
00081
00082 switch ($this->_period) {
00083 case 'day' :
00084 $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
00085 $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
00086 $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
00087 $dateStart->addDay(1);
00088 break;
00089 case 'month':
00090 $t['title'] = $dateStart->toString('MM/yyyy');
00091 $t['start'] = $dateStart->toString('yyyy-MM-01 00:00:00');
00092 $t['end'] = $dateStart->toString('yyyy-MM-'.date('t', $dateStart->getTimestamp()).' 23:59:59');
00093 $dateStart->addMonth(1);
00094 break;
00095 case 'year':
00096 $t['title'] = $dateStart->toString('yyyy');
00097 $t['start'] = $dateStart->toString('yyyy-01-01 00:00:00');
00098 $t['end'] = $dateStart->toString('yyyy-12-31 23:59:59');
00099 $dateStart->addYear(1);
00100 break;
00101 }
00102 $this->_intervals[$t['title']] = $t;
00103 }
00104
00105 if ($this->_period != 'day') {
00106 $titles = array_keys($this->_intervals);
00107 if (count($titles) > 0) {
00108 $this->_intervals[$titles[0]]['start'] = $dateStart2->toString('yyyy-MM-dd 00:00:00');
00109 $this->_intervals[$titles[count($titles)-1]]['end'] = $dateEnd->toString('yyyy-MM-dd 23:59:59');
00110 }
00111 }
00112 }
00113 return $this->_intervals;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122 public function getPeriods()
00123 {
00124 return array(
00125 'day'=>Mage::helper('reports')->__('Day'),
00126 'month'=>Mage::helper('reports')->__('Month'),
00127 'year'=>Mage::helper('reports')->__('Year')
00128 );
00129 }
00130
00131 public function setStoreIds($storeIds)
00132 {
00133 $this->_storeIds = $storeIds;
00134 }
00135
00136 public function getStoreIds()
00137 {
00138 return $this->_storeIds;
00139 }
00140
00141 public function getSize()
00142 {
00143 return count($this->getIntervals());
00144 }
00145
00146 public function setPageSize($size)
00147 {
00148 $this->_pageSize = $size;
00149 return $this;
00150 }
00151
00152 public function getPageSize()
00153 {
00154 return $this->_pageSize;
00155 }
00156
00157 public function initReport($modelClass)
00158 {
00159
00160
00161 $this->_model = Mage::getModel('reports/report')
00162 ->setPageSize($this->getPageSize())
00163 ->setStoreIds($this->getStoreIds())
00164 ->initCollection($modelClass);
00165
00166
00167
00168
00169 }
00170
00171 public function getReportFull($from, $to)
00172 {
00173 return $this->_model->getReportFull($this->timeShift($from), $this->timeShift($to));
00174 }
00175
00176 public function getReport($from, $to)
00177 {
00178 return $this->_model->getReport($this->timeShift($from), $this->timeShift($to));
00179 }
00180
00181 public function timeShift($datetime)
00182 {
00183 return date('Y-m-d H:i:s', strtotime($datetime) - Mage::getModel('core/date')->getGmtOffset());
00184 }
00185 }