Definition at line 34 of file Grid.php.
__construct | ( | ) |
Constructor
By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes
Reimplemented from Varien_Object.
Reimplemented in Mage_Adminhtml_Block_Report_Customer_Accounts_Grid, Mage_Adminhtml_Block_Report_Customer_Orders_Grid, Mage_Adminhtml_Block_Report_Customer_Totals_Grid, Mage_Adminhtml_Block_Report_Product_Ordered_Grid, Mage_Adminhtml_Block_Report_Product_Sold_Grid, Mage_Adminhtml_Block_Report_Product_Viewed_Grid, Mage_Adminhtml_Block_Report_Sales_Coupons_Grid, Mage_Adminhtml_Block_Report_Sales_Invoiced_Grid, Mage_Adminhtml_Block_Report_Sales_Refunded_Grid, Mage_Adminhtml_Block_Report_Sales_Sales_Grid, Mage_Adminhtml_Block_Report_Sales_Shipping_Grid, and Mage_Adminhtml_Block_Report_Sales_Tax_Grid.
Definition at line 63 of file Grid.php.
00064 { 00065 parent::__construct(); 00066 $this->setFilterVisibility(false); 00067 $this->setPagerVisibility(false); 00068 $this->setTemplate('report/grid.phtml'); 00069 $this->setUseAjax(false); 00070 $this->setCountTotals(true); 00071 }
_prepareCollection | ( | ) | [protected] |
Prepare grid collection object
Validate from and to date
Getting and saving store ids for website & group
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Reimplemented in Mage_Adminhtml_Block_Report_Customer_Accounts_Grid, Mage_Adminhtml_Block_Report_Customer_Orders_Grid, Mage_Adminhtml_Block_Report_Customer_Totals_Grid, Mage_Adminhtml_Block_Report_Product_Ordered_Grid, Mage_Adminhtml_Block_Report_Product_Sold_Grid, Mage_Adminhtml_Block_Report_Product_Viewed_Grid, Mage_Adminhtml_Block_Report_Sales_Coupons_Grid, Mage_Adminhtml_Block_Report_Sales_Invoiced_Grid, Mage_Adminhtml_Block_Report_Sales_Refunded_Grid, Mage_Adminhtml_Block_Report_Sales_Sales_Grid, Mage_Adminhtml_Block_Report_Sales_Shipping_Grid, and Mage_Adminhtml_Block_Report_Sales_Tax_Grid.
Definition at line 103 of file Grid.php.
00104 { 00105 $filter = $this->getParam($this->getVarNameFilter(), null); 00106 00107 if (is_null($filter)) { 00108 $filter = $this->_defaultFilter; 00109 } 00110 00111 if (is_string($filter)) { 00112 $data = array(); 00113 $filter = base64_decode($filter); 00114 parse_str(urldecode($filter), $data); 00115 00116 if (!isset($data['report_from'])) { 00117 // getting all reports from 2001 year 00118 $date = new Zend_Date(mktime(0,0,0,1,1,2001)); 00119 $data['report_from'] = $date->toString($this->getLocale()->getDateFormat('short')); 00120 } 00121 00122 if (!isset($data['report_to'])) { 00123 // getting all reports from 2001 year 00124 $date = new Zend_Date(); 00125 $data['report_to'] = $date->toString($this->getLocale()->getDateFormat('short')); 00126 } 00127 00128 $this->_setFilterValues($data); 00129 } else if ($filter && is_array($filter)) { 00130 $this->_setFilterValues($filter); 00131 } else if(0 !== sizeof($this->_defaultFilter)) { 00132 $this->_setFilterValues($this->_defaultFilter); 00133 } 00134 00135 $collection = Mage::getResourceModel('reports/report_collection'); 00136 00137 $collection->setPeriod($this->getFilter('report_period')); 00138 00139 if ($this->getFilter('report_from') && $this->getFilter('report_to')) { 00140 /** 00141 * Validate from and to date 00142 */ 00143 try { 00144 $from = $this->getLocale()->date($this->getFilter('report_from'), Zend_Date::DATE_SHORT, null, false); 00145 $to = $this->getLocale()->date($this->getFilter('report_to'), Zend_Date::DATE_SHORT, null, false); 00146 00147 $collection->setInterval($from, $to); 00148 } 00149 catch (Exception $e) { 00150 $this->_errors[] = Mage::helper('reports')->__('Invalid date specified'); 00151 } 00152 } 00153 00154 /** 00155 * Getting and saving store ids for website & group 00156 */ 00157 if ($this->getRequest()->getParam('store')) { 00158 $storeIds = array($this->getParam('store')); 00159 } else if ($this->getRequest()->getParam('website')){ 00160 $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); 00161 } else if ($this->getRequest()->getParam('group')){ 00162 $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); 00163 } else { 00164 $storeIds = array(''); 00165 } 00166 $collection->setStoreIds($storeIds); 00167 00168 $collection->setPageSize($this->getSubReportSize()); 00169 00170 $this->setCollection($collection); 00171 00172 Mage::dispatchEvent('adminhtml_widget_grid_filter_collection', 00173 array('collection' => $this->getCollection(), 'filter_values' => $this->_filterValues) 00174 ); 00175 }
_prepareColumns | ( | ) | [protected] |
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Reimplemented in Mage_Adminhtml_Block_Report_Customer_Accounts_Grid, Mage_Adminhtml_Block_Report_Customer_Orders_Grid, Mage_Adminhtml_Block_Report_Customer_Totals_Grid, Mage_Adminhtml_Block_Report_Product_Ordered_Grid, Mage_Adminhtml_Block_Report_Product_Sold_Grid, Mage_Adminhtml_Block_Report_Product_Viewed_Grid, Mage_Adminhtml_Block_Report_Sales_Coupons_Grid, Mage_Adminhtml_Block_Report_Sales_Invoiced_Grid, Mage_Adminhtml_Block_Report_Sales_Refunded_Grid, Mage_Adminhtml_Block_Report_Sales_Sales_Grid, Mage_Adminhtml_Block_Report_Sales_Shipping_Grid, and Mage_Adminhtml_Block_Report_Sales_Tax_Grid.
Definition at line 94 of file Grid.php.
00095 { 00096 foreach ($this->_columns as $_column) { 00097 $_column->setSortable(false); 00098 } 00099 00100 parent::_prepareColumns(); 00101 }
_prepareLayout | ( | ) | [protected] |
Preparing global layout
You can redefine this method in child classes for changin layout
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 73 of file Grid.php.
00074 { 00075 $this->setChild('store_switcher', 00076 $this->getLayout()->createBlock('adminhtml/store_switcher') 00077 ->setUseConfirm(false) 00078 ->setSwitchUrl($this->getUrl('*/*/*', array('store'=>null))) 00079 ->setTemplate('report/store/switcher.phtml') 00080 ); 00081 00082 $this->setChild('refresh_button', 00083 $this->getLayout()->createBlock('adminhtml/widget_button') 00084 ->setData(array( 00085 'label' => Mage::helper('adminhtml')->__('Refresh'), 00086 'onclick' => $this->getRefreshButtonCallback(), 00087 'class' => 'task' 00088 )) 00089 ); 00090 parent::_prepareLayout(); 00091 return $this; 00092 }
_setFilterValues | ( | $ | data | ) | [protected] |
addExportType | ( | $ | url, | |
$ | label | |||
) |
Add new export type to grid
string | $url | |
string | $label |
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 341 of file Grid.php.
00342 { 00343 $this->_exportTypes[] = new Varien_Object( 00344 array( 00345 'url' => $this->getUrl($url, 00346 array( 00347 '_current'=>true, 00348 'filter' => $this->getParam($this->getVarNameFilter(), null) 00349 ) 00350 ), 00351 'label' => $label 00352 ) 00353 ); 00354 return $this; 00355 }
addGrandTotals | ( | $ | total | ) |
Definition at line 371 of file Grid.php.
00372 { 00373 $totalData = $total->getData(); 00374 foreach ($totalData as $key=>$value) { 00375 $_column = $this->getColumn($key); 00376 if ($_column->getTotal() != '') { 00377 $this->getGrandTotals()->setData($key, $this->getGrandTotals()->getData($key)+$value); 00378 } 00379 } 00380 /* 00381 * recalc totals if we have average 00382 */ 00383 foreach ($this->getColumns() as $key=>$_column) { 00384 if (strpos($_column->getTotal(), '/') !== FALSE) { 00385 list($t1, $t2) = explode('/', $_column->getTotal()); 00386 if ($this->getGrandTotals()->getData($t2) != 0) { 00387 $this->getGrandTotals()->setData( 00388 $key, 00389 (float)$this->getGrandTotals()->getData($t1)/$this->getGrandTotals()->getData($t2) 00390 ); 00391 } 00392 } 00393 } 00394 }
getCountTotals | ( | ) |
Return count totals
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 543 of file Grid.php.
00544 { 00545 $totals = $this->getGrandTotals()->getData(); 00546 if (parent::getCountTotals() && count($totals)) { 00547 return true; 00548 } else { 00549 return false; 00550 } 00551 }
getCsv | ( | ) |
Retrieve grid as CSV
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 414 of file Grid.php.
00415 { 00416 $csv = ''; 00417 $this->_prepareGrid(); 00418 00419 $data = array('"'.$this->__('Period').'"'); 00420 foreach ($this->_columns as $column) { 00421 if (!$column->getIsSystem()) { 00422 $data[] = '"'.$column->getHeader().'"'; 00423 } 00424 } 00425 $csv.= implode(',', $data)."\n"; 00426 00427 foreach ($this->getCollection()->getIntervals() as $_index=>$_item) { 00428 $report = $this->getReport($_item['start'], $_item['end']); 00429 foreach ($report as $_subIndex=>$_subItem) { 00430 $data = array('"'.$_index.'"'); 00431 foreach ($this->_columns as $column) { 00432 if (!$column->getIsSystem()) { 00433 $data[] = '"'.str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowField($_subItem)).'"'; 00434 } 00435 } 00436 $csv.= implode(',', $data)."\n"; 00437 } 00438 if ($this->getCountTotals() && $this->getSubtotalVisibility()) 00439 { 00440 $data = array('"'.$_index.'"'); 00441 $j = 0; 00442 foreach ($this->_columns as $column) { 00443 $j++; 00444 if (!$column->getIsSystem()) { 00445 $data[] = ($j==1)?'"'.$this->__('Subtotal').'"':'"'.str_replace('"', '""', $column->getRowField($this->getTotals())).'"'; 00446 } 00447 } 00448 $csv.= implode(',', $data)."\n"; 00449 } 00450 } 00451 00452 if ($this->getCountTotals()) 00453 { 00454 $data = array('"'.$this->__('Total').'"'); 00455 foreach ($this->_columns as $column) { 00456 if (!$column->getIsSystem()) { 00457 $data[] = '"'.str_replace('"', '""', $column->getRowField($this->getGrandTotals())).'"'; 00458 } 00459 } 00460 $csv.= implode(',', $data)."\n"; 00461 } 00462 00463 return $csv; 00464 }
getCurrentCurrencyCode | ( | ) |
Retrieve correct currency code for select website, store, group
Definition at line 579 of file Grid.php.
00580 { 00581 if (is_null($this->_currentCurrencyCode)) { 00582 if ($this->getRequest()->getParam('store')) { 00583 $this->_currentCurrencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrencyCode(); 00584 } else if ($this->getRequest()->getParam('website')){ 00585 $this->_currentCurrencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrencyCode(); 00586 } else if ($this->getRequest()->getParam('group')){ 00587 $this->_currentCurrencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrencyCode(); 00588 } else { 00589 $this->_currentCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); 00590 } 00591 } 00592 return $this->_currentCurrencyCode; 00593 }
getDateFilterVisibility | ( | ) |
getDateFormat | ( | ) |
Definition at line 282 of file Grid.php.
00283 { 00284 return $this->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); 00285 }
getEmptyText | ( | ) |
Return empty text for grid
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 538 of file Grid.php.
00539 { 00540 return $this->__('No records found for this period.'); 00541 }
getErrors | ( | ) |
getExcel | ( | $ | filename = '' |
) |
Retrieve grid as Excel Xml
Reimplemented from Mage_Adminhtml_Block_Widget_Grid.
Definition at line 471 of file Grid.php.
00472 { 00473 $this->_prepareGrid(); 00474 00475 $data = array(); 00476 $row = array($this->__('Period')); 00477 foreach ($this->_columns as $column) { 00478 if (!$column->getIsSystem()) { 00479 $row[] = $column->getHeader(); 00480 } 00481 } 00482 $data[] = $row; 00483 00484 foreach ($this->getCollection()->getIntervals() as $_index=>$_item) { 00485 $report = $this->getReport($_item['start'], $_item['end']); 00486 foreach ($report as $_subIndex=>$_subItem) { 00487 $row = array($_index); 00488 foreach ($this->_columns as $column) { 00489 if (!$column->getIsSystem()) { 00490 $row[] = $column->getRowField($_subItem); 00491 } 00492 } 00493 $data[] = $row; 00494 } 00495 if ($this->getCountTotals() && $this->getSubtotalVisibility()) 00496 { 00497 $row = array($_index); 00498 $j = 0; 00499 foreach ($this->_columns as $column) { 00500 $j++; 00501 if (!$column->getIsSystem()) { 00502 $row[] = ($j==1)?$this->__('Subtotal'):$column->getRowField($this->getTotals()); 00503 } 00504 } 00505 $data[] = $row; 00506 } 00507 } 00508 00509 if ($this->getCountTotals()) 00510 { 00511 $row = array($this->__('Total')); 00512 foreach ($this->_columns as $column) { 00513 if (!$column->getIsSystem()) { 00514 $row[] = $column->getRowField($this->getGrandTotals()); 00515 } 00516 } 00517 $data[] = $row; 00518 } 00519 00520 $xmlObj = new Varien_Convert_Parser_Xml_Excel(); 00521 $xmlObj->setVar('single_sheet', $filename); 00522 $xmlObj->setData($data); 00523 $xmlObj->unparse(); 00524 00525 return $xmlObj->getData(); 00526 }
getExportVisibility | ( | ) |
getFilter | ( | $ | name | ) |
getGrandTotals | ( | ) |
Definition at line 396 of file Grid.php.
00397 { 00398 if (!$this->_grandTotals) { 00399 $this->_grandTotals = new Varien_Object(); 00400 } 00401 return $this->_grandTotals; 00402 }
getLocale | ( | ) |
Retrieve locale
Definition at line 326 of file Grid.php.
00327 { 00328 if (!$this->_locale) { 00329 $this->_locale = Mage::app()->getLocale(); 00330 } 00331 return $this->_locale; 00332 }
getPeriods | ( | ) |
Definition at line 277 of file Grid.php.
00278 { 00279 return $this->getCollection()->getPeriods(); 00280 }
getPeriodText | ( | ) |
getRefreshButtonCallback | ( | ) |
onlick event for refresh button to show alert if fields are empty
Definition at line 558 of file Grid.php.
00559 { 00560 return "{$this->getJsObjectName()}.doFilter();"; 00561 return "if ($('period_date_to').value == '' && $('period_date_from').value == '') {alert('".$this->__('Please specify at least start or end date.')."'); return false;}else {$this->getJsObjectName()}.doFilter();"; 00562 }
getRefreshButtonHtml | ( | ) |
Return refresh button html
Definition at line 290 of file Grid.php.
00291 { 00292 return $this->getChildHtml('refresh_button'); 00293 }
getReport | ( | $ | from, | |
$ | to | |||
) |
Definition at line 357 of file Grid.php.
00358 { 00359 if ($from == '') { 00360 $from = $this->getFilter('report_from'); 00361 } 00362 if ($to == '') { 00363 $to = $this->getFilter('report_to'); 00364 } 00365 $totalObj = new Mage_Reports_Model_Totals(); 00366 $this->setTotals($totalObj->countTotals($this, $from, $to)); 00367 $this->addGrandTotals($this->getTotals()); 00368 return $this->getCollection()->getReport($from, $to); 00369 }
getStoreSwitcherHtml | ( | ) |
Return store switcher html
Definition at line 212 of file Grid.php.
00213 { 00214 return $this->getChildHtml('store_switcher'); 00215 }
getStoreSwitcherVisibility | ( | ) |
getSubReportSize | ( | ) |
getSubtotalText | ( | ) |
getSubtotalVisibility | ( | ) |
getTotalText | ( | ) |
setDateFilterVisibility | ( | $ | visible = true |
) |
setExportVisibility | ( | $ | visible = true |
) |
setFilter | ( | $ | name, | |
$ | value | |||
) |
setStoreSwitcherVisibility | ( | $ | visible = true |
) |
setSubReportSize | ( | $ | size | ) |
setSubtotalVisibility | ( | $ | visible = true |
) |
$_currentCurrencyCode = null [protected] |
$_defaultFilters [protected] |
$_subReportSize = 5 [protected] |
Reimplemented in Mage_Adminhtml_Block_Report_Product_Sold_Grid.