Mage_Reports_Model_Totals Class Reference

List of all members.

Public Member Functions

 countTotals ($grid, $from, $to)


Detailed Description

Definition at line 34 of file Totals.php.


Member Function Documentation

countTotals ( grid,
from,
to 
)

Definition at line 36 of file Totals.php.

00037     {
00038         $columns = array();
00039         foreach ($grid->getColumns() as $col)
00040             $columns[$col->getIndex()] = array("total" => $col->getTotal(), "value" => 0);
00041 
00042         $count = 0;
00043         $report = $grid->getCollection()->getReportFull($from, $to);
00044         foreach ($report as $item)
00045         {
00046             $data = $item->getData();
00047             foreach ($columns as $field=>$a){
00048                 if ($field !== '') {
00049                     $columns[$field]['value'] = $columns[$field]['value'] + (isset($data[$field]) ? $data[$field] : 0);
00050                 }
00051             }
00052             $count++;
00053         }
00054         $data = array();
00055         foreach ($columns as $field=>$a)
00056         {
00057             if ($a['total'] == 'avg') {
00058                 if ($field !== '') {
00059                     if ($count != 0) {
00060                         $data[$field] = $a['value']/$count;
00061                     } else {
00062                         $data[$field] = 0;
00063                     }
00064                 }
00065             } else if ($a['total'] == 'sum') {
00066                 if ($field !== '') {
00067                     $data[$field] = $a['value'];
00068                 }
00069             } else if (strpos($a['total'], '/') !== FALSE) {
00070                 if ($field !== '') {
00071                     $data[$field] = 0;
00072                 }
00073             }
00074         }
00075 
00076         $totals = new Varien_Object();
00077 
00078         $totals->setData($data);
00079 
00080         return $totals;
00081     }


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

Generated on Sat Jul 4 17:24:37 2009 for Magento by  doxygen 1.5.8