Mage_Adminhtml_Block_Report_Grid Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Report_Grid:

Mage_Adminhtml_Block_Widget_Grid Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object 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 Mage_Adminhtml_Block_Report_Sales_Tax_Grid

List of all members.

Public Member Functions

 __construct ()
 setStoreSwitcherVisibility ($visible=true)
 getStoreSwitcherVisibility ()
 getStoreSwitcherHtml ()
 setDateFilterVisibility ($visible=true)
 getDateFilterVisibility ()
 setExportVisibility ($visible=true)
 getExportVisibility ()
 setSubtotalVisibility ($visible=true)
 getSubtotalVisibility ()
 getPeriods ()
 getDateFormat ()
 getRefreshButtonHtml ()
 setFilter ($name, $value)
 getFilter ($name)
 setSubReportSize ($size)
 getSubReportSize ()
 getLocale ()
 addExportType ($url, $label)
 getReport ($from, $to)
 addGrandTotals ($total)
 getGrandTotals ()
 getPeriodText ()
 getCsv ()
 getExcel ($filename= '')
 getSubtotalText ()
 getTotalText ()
 getEmptyText ()
 getCountTotals ()
 getRefreshButtonCallback ()
 getErrors ()
 getCurrentCurrencyCode ()

Protected Member Functions

 _prepareLayout ()
 _prepareColumns ()
 _prepareCollection ()
 _setFilterValues ($data)

Protected Attributes

 $_storeSwitcherVisibility = true
 $_dateFilterVisibility = true
 $_exportVisibility = true
 $_subtotalVisibility = false
 $_filters = array()
 $_defaultFilters
 $_subReportSize = 5
 $_grandTotals
 $_errors = array()
 $_currentCurrencyCode = null


Detailed Description

Definition at line 34 of file Grid.php.


Constructor & Destructor Documentation

__construct (  ) 


Member Function Documentation

_prepareCollection (  )  [protected]

Prepare grid collection object

Returns:
this

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]

_prepareLayout (  )  [protected]

Preparing global layout

You can redefine this method in child classes for changin layout

Returns:
Mage_Core_Block_Abstract

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]

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 177 of file Grid.php.

00178     {
00179         foreach ($data as $name => $value) {
00180             //if (isset($data[$name])) {
00181                 $this->setFilter($name, $data[$name]);
00182             //}
00183         }
00184         return $this;
00185     }

addExportType ( url,
label 
)

Add new export type to grid

Parameters:
string $url
string $label
Returns:
Mage_Adminhtml_Block_Widget_Grid

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

Returns:
boolean

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

Returns:
unknown

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

Returns:
string

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 (  ) 

Return visibility of date filter

Returns:
boolean

Definition at line 232 of file Grid.php.

00233     {
00234         return $this->_dateFilterVisibility;
00235     }

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

Returns:
string

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 (  ) 

Retrieve errors

Returns:
array

Definition at line 569 of file Grid.php.

00570     {
00571         return $this->_errors;
00572     }

getExcel ( filename = ''  ) 

Retrieve grid as Excel Xml

Returns:
unknown

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 (  ) 

Return visibility of export action

Returns:
boolean

Definition at line 252 of file Grid.php.

00253     {
00254         return $this->_exportVisibility;
00255     }

getFilter ( name  ) 

Definition at line 302 of file Grid.php.

00303     {
00304         if (isset($this->_filters[$name])) {
00305             return $this->_filters[$name];
00306         } else {
00307             return '';
00308         }
00309     }

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

Returns:
Mage_Core_Model_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 (  ) 

Definition at line 404 of file Grid.php.

00405     {
00406         return $this->__('Period');
00407     }

getRefreshButtonCallback (  ) 

onlick event for refresh button to show alert if fields are empty

Returns:
string

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

Returns:
string

Definition at line 212 of file Grid.php.

00213     {
00214         return $this->getChildHtml('store_switcher');
00215     }

getStoreSwitcherVisibility (  ) 

Return visibility of store switcher

Returns:
boolean

Definition at line 202 of file Grid.php.

00203     {
00204         return $this->_storeSwitcherVisibility;
00205     }

getSubReportSize (  ) 

Definition at line 316 of file Grid.php.

00317     {
00318         return $this->_subReportSize;
00319     }

getSubtotalText (  ) 

Definition at line 528 of file Grid.php.

00529     {
00530         return $this->__('Subtotal');
00531     }

getSubtotalVisibility (  ) 

Return visibility of subtotals

Returns:
boolean

Definition at line 272 of file Grid.php.

00273     {
00274         return $this->_subtotalVisibility;
00275     }

getTotalText (  ) 

Definition at line 533 of file Grid.php.

00534     {
00535         return $this->__('Total');
00536     }

setDateFilterVisibility ( visible = true  ) 

Set visibility of date filter

Parameters:
boolean $visible

Definition at line 222 of file Grid.php.

00223     {
00224         $this->_dateFilterVisibility = $visible;
00225     }

setExportVisibility ( visible = true  ) 

Set visibility of export action

Parameters:
boolean $visible

Definition at line 242 of file Grid.php.

00243     {
00244         $this->_exportVisibility = $visible;
00245     }

setFilter ( name,
value 
)

Definition at line 295 of file Grid.php.

00296     {
00297         if ($name) {
00298             $this->_filters[$name] = $value;
00299         }
00300     }

setStoreSwitcherVisibility ( visible = true  ) 

Set visibility of store switcher

Parameters:
boolean $visible

Definition at line 192 of file Grid.php.

00193     {
00194         $this->_storeSwitcherVisibility = $visible;
00195     }

setSubReportSize ( size  ) 

Definition at line 311 of file Grid.php.

00312     {
00313         $this->_subReportSize = $size;
00314     }

setSubtotalVisibility ( visible = true  ) 

Set visibility of subtotals

Parameters:
boolean $visible

Definition at line 262 of file Grid.php.

00263     {
00264         $this->_subtotalVisibility = $visible;
00265     }


Member Data Documentation

$_currentCurrencyCode = null [protected]

stores current currency code

Definition at line 61 of file Grid.php.

$_dateFilterVisibility = true [protected]

Definition at line 38 of file Grid.php.

$_defaultFilters [protected]

Initial value:

 array(
            'report_from' => '',
            'report_to' => '',
            'report_period' => 'day'
        )

Definition at line 46 of file Grid.php.

$_errors = array() [protected]

Definition at line 56 of file Grid.php.

$_exportVisibility = true [protected]

Definition at line 40 of file Grid.php.

$_filters = array() [protected]

Definition at line 44 of file Grid.php.

$_grandTotals [protected]

Definition at line 54 of file Grid.php.

$_storeSwitcherVisibility = true [protected]

Definition at line 36 of file Grid.php.

$_subReportSize = 5 [protected]

Reimplemented in Mage_Adminhtml_Block_Report_Product_Sold_Grid.

Definition at line 52 of file Grid.php.

$_subtotalVisibility = false [protected]

Definition at line 42 of file Grid.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:55 2009 for Magento by  doxygen 1.5.8