DigitalPianism_TwelveHoursRange - Version 0.1.0

Version Notes

Stable version.

Download this release

Release Info

Developer Digital Pianism
Extension DigitalPianism_TwelveHoursRange
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/DigitalPianism/TwelveHoursRange/Block/Adminhtml/Dashboard/Graph.php ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adminhtml dashboard google chart block
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contacct@digital-pianism.com>
8
+ */
9
+
10
+ class DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Graph extends Mage_Adminhtml_Block_Dashboard_Graph
11
+ {
12
+ /**
13
+ * Get chart url
14
+ *
15
+ * @param bool $directUrl
16
+ * @return string
17
+ */
18
+ public function getChartUrl($directUrl = true)
19
+ {
20
+ $params = array(
21
+ 'cht' => 'lc',
22
+ 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
23
+ 'chm' => 'B,f4d4b2,0,0,0',
24
+ 'chco' => 'db4814'
25
+ );
26
+
27
+ $this->_allSeries = $this->getRowsData($this->_dataRows);
28
+
29
+ foreach ($this->_axisMaps as $axis => $attr){
30
+ $this->setAxisLabels($axis, $this->getRowsData($attr, true));
31
+ }
32
+
33
+ $timezoneLocal = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
34
+
35
+ list ($dateStart, $dateEnd) = Mage::getResourceModel('reports/order_collection')
36
+ ->getDateRange($this->getDataHelper()->getParam('period'), '', '', true);
37
+
38
+ $dateStart->setTimezone($timezoneLocal);
39
+ $dateEnd->setTimezone($timezoneLocal);
40
+
41
+ $dates = array();
42
+ $datas = array();
43
+
44
+ while($dateStart->compare($dateEnd) < 0){
45
+ switch ($this->getDataHelper()->getParam('period')) {
46
+ // Add the 12h in the options
47
+ case '12h':
48
+ case '24h':
49
+ $d = $dateStart->toString('yyyy-MM-dd HH:00');
50
+ $dateStart->addHour(1);
51
+ break;
52
+ case '7d':
53
+ case '1m':
54
+ $d = $dateStart->toString('yyyy-MM-dd');
55
+ $dateStart->addDay(1);
56
+ break;
57
+ case '1y':
58
+ case '2y':
59
+ $d = $dateStart->toString('yyyy-MM');
60
+ $dateStart->addMonth(1);
61
+ break;
62
+ }
63
+ foreach ($this->getAllSeries() as $index=>$serie) {
64
+ if (in_array($d, $this->_axisLabels['x'])) {
65
+ $datas[$index][] = (float)array_shift($this->_allSeries[$index]);
66
+ } else {
67
+ $datas[$index][] = 0;
68
+ }
69
+ }
70
+ $dates[] = $d;
71
+ }
72
+
73
+ /**
74
+ * setting skip step
75
+ */
76
+ if (count($dates) > 8 && count($dates) < 15) {
77
+ $c = 1;
78
+ } else if (count($dates) >= 15){
79
+ $c = 2;
80
+ } else {
81
+ $c = 0;
82
+ }
83
+ /**
84
+ * skipping some x labels for good reading
85
+ */
86
+ $i=0;
87
+ foreach ($dates as $k => $d) {
88
+ if ($i == $c) {
89
+ $dates[$k] = $d;
90
+ $i = 0;
91
+ } else {
92
+ $dates[$k] = '';
93
+ $i++;
94
+ }
95
+ }
96
+
97
+ $this->_axisLabels['x'] = $dates;
98
+ $this->_allSeries = $datas;
99
+
100
+ //Google encoding values
101
+ if ($this->_encoding == "s") {
102
+ // simple encoding
103
+ $params['chd'] = "s:";
104
+ $dataDelimiter = "";
105
+ $dataSetdelimiter = ",";
106
+ $dataMissing = "_";
107
+ } else {
108
+ // extended encoding
109
+ $params['chd'] = "e:";
110
+ $dataDelimiter = "";
111
+ $dataSetdelimiter = ",";
112
+ $dataMissing = "__";
113
+ }
114
+
115
+ // process each string in the array, and find the max length
116
+ foreach ($this->getAllSeries() as $index => $serie) {
117
+ $localmaxlength[$index] = sizeof($serie);
118
+ $localmaxvalue[$index] = max($serie);
119
+ $localminvalue[$index] = min($serie);
120
+ }
121
+
122
+ if (is_numeric($this->_max)) {
123
+ $maxvalue = $this->_max;
124
+ } else {
125
+ $maxvalue = max($localmaxvalue);
126
+ }
127
+ if (is_numeric($this->_min)) {
128
+ $minvalue = $this->_min;
129
+ } else {
130
+ $minvalue = min($localminvalue);
131
+ }
132
+
133
+ // default values
134
+ $yrange = 0;
135
+ $yLabels = array();
136
+ $miny = 0;
137
+ $maxy = 0;
138
+ $yorigin = 0;
139
+
140
+ $maxlength = max($localmaxlength);
141
+ if ($minvalue >= 0 && $maxvalue >= 0) {
142
+ $miny = 0;
143
+ if ($maxvalue > 10) {
144
+ $p = pow(10, $this->_getPow($maxvalue));
145
+ $maxy = (ceil($maxvalue/$p))*$p;
146
+ $yLabels = range($miny, $maxy, $p);
147
+ } else {
148
+ $maxy = ceil($maxvalue+1);
149
+ $yLabels = range($miny, $maxy, 1);
150
+ }
151
+ $yrange = $maxy;
152
+ $yorigin = 0;
153
+ }
154
+
155
+ $chartdata = array();
156
+
157
+ foreach ($this->getAllSeries() as $index => $serie) {
158
+ $thisdataarray = $serie;
159
+ if ($this->_encoding == "s") {
160
+ // SIMPLE ENCODING
161
+ for ($j = 0; $j < sizeof($thisdataarray); $j++) {
162
+ $currentvalue = $thisdataarray[$j];
163
+ if (is_numeric($currentvalue)) {
164
+ $ylocation = round((strlen($this->_simpleEncoding)-1) * ($yorigin + $currentvalue) / $yrange);
165
+ array_push($chartdata, substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter);
166
+ } else {
167
+ array_push($chartdata, $dataMissing . $dataDelimiter);
168
+ }
169
+ }
170
+ // END SIMPLE ENCODING
171
+ } else {
172
+ // EXTENDED ENCODING
173
+ for ($j = 0; $j < sizeof($thisdataarray); $j++) {
174
+ $currentvalue = $thisdataarray[$j];
175
+ if (is_numeric($currentvalue)) {
176
+ if ($yrange) {
177
+ $ylocation = (4095 * ($yorigin + $currentvalue) / $yrange);
178
+ } else {
179
+ $ylocation = 0;
180
+ }
181
+ $firstchar = floor($ylocation / 64);
182
+ $secondchar = $ylocation % 64;
183
+ $mappedchar = substr($this->_extendedEncoding, $firstchar, 1)
184
+ . substr($this->_extendedEncoding, $secondchar, 1);
185
+ array_push($chartdata, $mappedchar . $dataDelimiter);
186
+ } else {
187
+ array_push($chartdata, $dataMissing . $dataDelimiter);
188
+ }
189
+ }
190
+ // ============= END EXTENDED ENCODING =============
191
+ }
192
+ array_push($chartdata, $dataSetdelimiter);
193
+ }
194
+ $buffer = implode('', $chartdata);
195
+
196
+ $buffer = rtrim($buffer, $dataSetdelimiter);
197
+ $buffer = rtrim($buffer, $dataDelimiter);
198
+ $buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer);
199
+
200
+ $params['chd'] .= $buffer;
201
+
202
+ $labelBuffer = "";
203
+ $valueBuffer = array();
204
+ $rangeBuffer = "";
205
+
206
+ if (sizeof($this->_axisLabels) > 0) {
207
+ $params['chxt'] = implode(',', array_keys($this->_axisLabels));
208
+ $indexid = 0;
209
+ foreach ($this->_axisLabels as $idx=>$labels){
210
+ if ($idx == 'x') {
211
+ /**
212
+ * Format date
213
+ */
214
+ foreach ($this->_axisLabels[$idx] as $_index=>$_label) {
215
+ if ($_label != '') {
216
+ switch ($this->getDataHelper()->getParam('period')) {
217
+ // Add the 12h to the options
218
+ case '12h':
219
+ case '24h':
220
+ $this->_axisLabels[$idx][$_index] = $this->formatTime(
221
+ new Zend_Date($_label, 'yyyy-MM-dd HH:00'), 'short', false
222
+ );
223
+ break;
224
+ case '7d':
225
+ case '1m':
226
+ $this->_axisLabels[$idx][$_index] = $this->formatDate(
227
+ new Zend_Date($_label, 'yyyy-MM-dd')
228
+ );
229
+ break;
230
+ case '1y':
231
+ case '2y':
232
+ $formats = Mage::app()->getLocale()->getTranslationList('datetime');
233
+ $format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy';
234
+ $format = str_replace(array("yyyy", "yy", "MM"), array("Y", "y", "m"), $format);
235
+ $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label));
236
+ break;
237
+ }
238
+ } else {
239
+ $this->_axisLabels[$idx][$_index] = '';
240
+ }
241
+
242
+ }
243
+
244
+ $tmpstring = implode('|', $this->_axisLabels[$idx]);
245
+
246
+ $valueBuffer[] = $indexid . ":|" . $tmpstring;
247
+ if (sizeof($this->_axisLabels[$idx]) > 1) {
248
+ $deltaX = 100/(sizeof($this->_axisLabels[$idx])-1);
249
+ } else {
250
+ $deltaX = 100;
251
+ }
252
+ } else if ($idx == 'y') {
253
+ $valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
254
+ if (sizeof($yLabels)-1) {
255
+ $deltaY = 100/(sizeof($yLabels)-1);
256
+ } else {
257
+ $deltaY = 100;
258
+ }
259
+ // setting range values for y axis
260
+ $rangeBuffer = $indexid . "," . $miny . "," . $maxy . "|";
261
+ }
262
+ $indexid++;
263
+ }
264
+ $params['chxl'] = implode('|', $valueBuffer);
265
+ };
266
+
267
+ // chart size
268
+ $params['chs'] = $this->getWidth().'x'.$this->getHeight();
269
+
270
+ if (isset($deltaX) && isset($deltaY)) {
271
+ $params['chg'] = $deltaX . ',' . $deltaY . ',1,0';
272
+ }
273
+
274
+ // return the encoded data
275
+ if ($directUrl) {
276
+ $p = array();
277
+ foreach ($params as $name => $value) {
278
+ $p[] = $name . '=' .urlencode($value);
279
+ }
280
+ return self::API_URL . '?' . implode('&', $p);
281
+ } else {
282
+ $gaData = urlencode(base64_encode(serialize($params)));
283
+ $gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
284
+ $params = array('ga' => $gaData, 'h' => $gaHash);
285
+ return $this->getUrl('*/*/tunnel', array('_query' => $params));
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Prepare chart data
291
+ *
292
+ * @return void
293
+ */
294
+ protected function _prepareData()
295
+ {
296
+ $availablePeriods = array_keys($this->helper('digitalpianism/twelvehoursrange_adminhtml_dashboard_data')->getDatePeriods());
297
+ $period = $this->getRequest()->getParam('period');
298
+
299
+ // Set the default period to 12h
300
+ $this->getDataHelper()->setParam('period',
301
+ ($period && in_array($period, $availablePeriods)) ? $period : '12h'
302
+ );
303
+ }
304
+ }
app/code/community/DigitalPianism/TwelveHoursRange/Block/Adminhtml/Dashboard/Tab/Amounts.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adminhtml dashboard order amounts diagram
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contact@digital-pianism.com>
8
+ */
9
+
10
+ class DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Tab_Amounts extends Mage_Adminhtml_Block_Dashboard_Tab_Amounts
11
+ {
12
+ /**
13
+ * Prepare chart data
14
+ *
15
+ * @return void
16
+ */
17
+ protected function _prepareData()
18
+ {
19
+ $this->setDataHelperName('adminhtml/dashboard_order');
20
+ $this->getDataHelper()->setParam('store', $this->getRequest()->getParam('store'));
21
+ $this->getDataHelper()->setParam('website', $this->getRequest()->getParam('website'));
22
+ $this->getDataHelper()->setParam('group', $this->getRequest()->getParam('group'));
23
+ // 12h as the default parameter
24
+ $this->getDataHelper()->setParam(
25
+ 'period',
26
+ $this->getRequest()->getParam('period')?$this->getRequest()->getParam('period'):'12h'
27
+ );
28
+ $this->setDataRows('revenue');
29
+ $this->_axisMaps = array(
30
+ 'x' => 'range',
31
+ 'y' => 'revenue'
32
+ );
33
+
34
+ parent::_prepareData();
35
+ }
36
+ }
37
+
app/code/community/DigitalPianism/TwelveHoursRange/Block/Adminhtml/Dashboard/Tab/Orders.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adminhtml dashboard orders diagram
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contact@digital-pianism.com>
8
+ */
9
+
10
+ class DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Tab_Orders extends Mage_Adminhtml_Block_Dashboard_Tab_Orders
11
+ {
12
+ /**
13
+ * Prepare chart data
14
+ *
15
+ * @return void
16
+ */
17
+ protected function _prepareData()
18
+ {
19
+ $this->setDataHelperName('adminhtml/dashboard_order');
20
+ $this->getDataHelper()->setParam('store', $this->getRequest()->getParam('store'));
21
+ $this->getDataHelper()->setParam('website', $this->getRequest()->getParam('website'));
22
+ $this->getDataHelper()->setParam('group', $this->getRequest()->getParam('group'));
23
+ // 12h as the default parameter
24
+ $this->getDataHelper()->setParam(
25
+ 'period',
26
+ $this->getRequest()->getParam('period')?$this->getRequest()->getParam('period'):'12h'
27
+ );
28
+
29
+ $this->setDataRows('quantity');
30
+ $this->_axisMaps = array(
31
+ 'x' => 'range',
32
+ 'y' => 'quantity'
33
+ );
34
+
35
+ parent::_prepareData();
36
+ }
37
+ }
app/code/community/DigitalPianism/TwelveHoursRange/Block/Adminhtml/Dashboard/Totals.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adminhtml dashboard totals bar
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contact@digital-pianism.com>
8
+ */
9
+ class DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Totals extends Mage_Adminhtml_Block_Dashboard_Totals
10
+ {
11
+ protected function _prepareLayout()
12
+ {
13
+ if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
14
+ return $this;
15
+ }
16
+ $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
17
+ // Default period to 12h
18
+ $period = $this->getRequest()->getParam('period', '12h');
19
+
20
+ /* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */
21
+ $collection = Mage::getResourceModel('reports/order_collection')
22
+ ->addCreateAtPeriodFilter($period)
23
+ ->calculateTotals($isFilter);
24
+
25
+ if ($this->getRequest()->getParam('store')) {
26
+ $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
27
+ } else if ($this->getRequest()->getParam('website')){
28
+ $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
29
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
30
+ } else if ($this->getRequest()->getParam('group')){
31
+ $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
32
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
33
+ } elseif (!$collection->isLive()) {
34
+ $collection->addFieldToFilter('store_id',
35
+ array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
36
+ );
37
+ }
38
+
39
+ $collection->load();
40
+
41
+ $totals = $collection->getFirstItem();
42
+
43
+ $this->addTotal($this->__('Revenue'), $totals->getRevenue());
44
+ $this->addTotal($this->__('Tax'), $totals->getTax());
45
+ $this->addTotal($this->__('Shipping'), $totals->getShipping());
46
+ $this->addTotal($this->__('Quantity'), $totals->getQuantity()*1, true);
47
+ }
48
+ }
app/code/community/DigitalPianism/TwelveHoursRange/Helper/Adminhtml/Dashboard/Data.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Data helper for dashboard
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contact@digital-pianism.com>
8
+ */
9
+
10
+ class DigitalPianism_TwelveHoursRange_Helper_Adminhtml_Dashboard_Data extends Mage_Adminhtml_Helper_Dashboard_Data
11
+ {
12
+ /**
13
+ * Prepare array with periods for dashboard graphs
14
+ *
15
+ * @return array
16
+ */
17
+ public function getDatePeriods()
18
+ {
19
+ // Add 12h to the array of periods
20
+ return array(
21
+ '12h'=>$this->__('Last 12 Hours'),
22
+ '24h'=>$this->__('Last 24 Hours'),
23
+ '7d'=>$this->__('Last 7 Days'),
24
+ '1m'=>$this->__('Current Month'),
25
+ '1y'=>$this->__('YTD'),
26
+ '2y'=>$this->__('2YTD')
27
+ );
28
+ }
29
+ }
app/code/community/DigitalPianism/TwelveHoursRange/Model/Reports/Resource/Order/Collection.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reports orders collection
4
+ *
5
+ * @category Mage
6
+ * @package DigitalPianism_TwelveHoursRange
7
+ * @author Digital Pianism <contact@digital-pianism.com>
8
+ */
9
+ class DigitalPianism_TwelveHoursRange_Model_Reports_Resource_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection
10
+ {
11
+ /**
12
+ * Get range expression
13
+ *
14
+ * @param string $range
15
+ * @return Zend_Db_Expr
16
+ */
17
+ protected function _getRangeExpression($range)
18
+ {
19
+ switch ($range)
20
+ {
21
+ // Add 12h to the ranges
22
+ case '12h':
23
+ case '24h':
24
+ $expression = $this->getConnection()->getConcatSql(array(
25
+ $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d %H:'),
26
+ $this->getConnection()->quote('00')
27
+ ));
28
+ break;
29
+ case '7d':
30
+ case '1m':
31
+ $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d');
32
+ break;
33
+ case '1y':
34
+ case '2y':
35
+ case 'custom':
36
+ default:
37
+ $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m');
38
+ break;
39
+ }
40
+
41
+ return $expression;
42
+ }
43
+
44
+ /**
45
+ * Calculate From and To dates (or times) by given period
46
+ *
47
+ * @param string $range
48
+ * @param string $customStart
49
+ * @param string $customEnd
50
+ * @param boolean $returnObjects
51
+ * @return array
52
+ */
53
+ public function getDateRange($range, $customStart, $customEnd, $returnObjects = false)
54
+ {
55
+ $dateEnd = Mage::app()->getLocale()->date();
56
+ $dateStart = clone $dateEnd;
57
+
58
+ // go to the end of a day
59
+ $dateEnd->setHour(23);
60
+ $dateEnd->setMinute(59);
61
+ $dateEnd->setSecond(59);
62
+
63
+ $dateStart->setHour(0);
64
+ $dateStart->setMinute(0);
65
+ $dateStart->setSecond(0);
66
+
67
+ switch ($range)
68
+ {
69
+ // Case of the 12h range
70
+ case '12h':
71
+ $dateEnd = Mage::app()->getLocale()->date();
72
+ $dateEnd->addHour(1);
73
+ $dateStart = clone $dateEnd;
74
+ $dateStart->subHour(12);
75
+ break;
76
+
77
+ case '24h':
78
+ $dateEnd = Mage::app()->getLocale()->date();
79
+ $dateEnd->addHour(1);
80
+ $dateStart = clone $dateEnd;
81
+ $dateStart->subDay(1);
82
+ break;
83
+
84
+ case '7d':
85
+ // substract 6 days we need to include
86
+ // only today and not hte last one from range
87
+ $dateStart->subDay(6);
88
+ break;
89
+
90
+ case '1m':
91
+ $dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start'));
92
+ break;
93
+
94
+ case 'custom':
95
+ $dateStart = $customStart ? $customStart : $dateEnd;
96
+ $dateEnd = $customEnd ? $customEnd : $dateEnd;
97
+ break;
98
+
99
+ case '1y':
100
+ case '2y':
101
+ $startMonthDay = explode(',', Mage::getStoreConfig('reports/dashboard/ytd_start'));
102
+ $startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1;
103
+ $startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1;
104
+ $dateStart->setMonth($startMonth);
105
+ $dateStart->setDay($startDay);
106
+ if ($range == '2y') {
107
+ $dateStart->subYear(1);
108
+ }
109
+ break;
110
+ }
111
+
112
+ $dateStart->setTimezone('Etc/UTC');
113
+ $dateEnd->setTimezone('Etc/UTC');
114
+
115
+ if ($returnObjects) {
116
+ return array($dateStart, $dateEnd);
117
+ } else {
118
+ return array('from' => $dateStart, 'to' => $dateEnd, 'datetime' => true);
119
+ }
120
+ }
121
+ }
app/code/community/DigitalPianism/TwelveHoursRange/etc/config.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+
4
+ <modules>
5
+ <DigitalPianism_TwelveHoursRange>
6
+ <version>0.1.0</version>
7
+ </DigitalPianism_TwelveHoursRange>
8
+ </modules>
9
+
10
+ <global>
11
+ <models>
12
+ <reports>
13
+ <rewrite>
14
+ <!-- Mage_Reports_Model_Resource_Order_Collection -->
15
+ <resource_order_collection>DigitalPianism_TwelveHoursRange_Model_Reports_Resource_Order_Collection</resource_order_collection>
16
+ </rewrite>
17
+ </reports>
18
+ </models>
19
+
20
+ <blocks>
21
+ <adminhtml>
22
+ <rewrite>
23
+ <!-- Mage_Adminhtml_Block_Dashboard_Graph -->
24
+ <dashboard_graph>DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Graph</dashboard_graph>
25
+ <!-- Mage_Adminhtml_Block_Dashboard_Totals -->
26
+ <dashboard_totals>DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Totals</dashboard_totals>
27
+ <!-- Mage_Adminhtml_Block_Dashboard_Tab_Amounts -->
28
+ <dashboard_tab_amounts>DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Tab_Amounts</dashboard_tab_amounts>
29
+ <!-- Mage_Adminhtml_Block_Dashboard_Tab_Orders -->
30
+ <dashboard_tab_orders>DigitalPianism_TwelveHoursRange_Block_Adminhtml_Dashboard_Tab_Orders</dashboard_tab_orders>
31
+ </rewrite>
32
+ </adminhtml>
33
+ </blocks>
34
+
35
+ <helpers>
36
+ <adminhtml>
37
+ <rewrite>
38
+ <!-- Mage_Adminhtml_Helper_Dashboard_Data -->
39
+ <dashboard_data>DigitalPianism_TwelveHoursRange_Helper_Adminhtml_Dashboard_Data</dashboard_data>
40
+ </rewrite>
41
+ </adminhtml>
42
+ </helpers>
43
+ </global>
44
+
45
+ </config>
app/etc/modules/DigitalPianism_TwelveHoursRange.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DigitalPianism_TwelveHoursRange>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </DigitalPianism_TwelveHoursRange>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DigitalPianism_TwelveHoursRange</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds a 12 hours range to the dashboard graph.</summary>
10
+ <description>This extension adds a twelve hours range to the Magento backend dashboard graph in order to help store managers to have a better overview of their sales.</description>
11
+ <notes>Stable version.</notes>
12
+ <authors><author><name>Digital Pianism</name><user>digitalpianism</user><email>contact@digital-pianism.com</email></author></authors>
13
+ <date>2014-05-02</date>
14
+ <time>13:22:53</time>
15
+ <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="TwelveHoursRange"><dir name="Block"><dir name="Adminhtml"><dir name="Dashboard"><file name="Graph.php" hash="b0a9aa5b91fde009314c148db7d89424"/><dir name="Tab"><file name="Amounts.php" hash="795391ef2a46b323d6979ece3a56317d"/><file name="Orders.php" hash="554ad291d26c194f5213a2c0d8723ddd"/></dir><file name="Totals.php" hash="d3145437fff618b0d28c86783e515c71"/></dir></dir></dir><dir name="Helper"><dir name="Adminhtml"><dir name="Dashboard"><file name="Data.php" hash="2246c19ae94ffc6ce034bf403a3bae2c"/></dir></dir></dir><dir name="Model"><dir name="Reports"><dir name="Resource"><dir name="Order"><file name="Collection.php" hash="de1036063de366ee714b5304050a7f92"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="739351a2ee8f5a5d68d7956f4da5c921"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_TwelveHoursRange.xml" hash="ddbab62b38efb5d63bc21c9cbb1ea548"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>