예제 #1
0
 /**
  * Take an existing table and digest it into a summary table.
  * @param unknown_type $params
  */
 protected function generateSummaryTable($report, $params)
 {
     $newFields = array($params["grouping_fields"][0]);
     $newHeaders = array($params["headers"][array_search($params["grouping_fields"][0], $params["fields"])]);
     $indices = array(array_search($params["grouping_fields"][0], $params["fields"]));
     $newParams = array("total" => array(false), "type" => array("string"));
     foreach ($params["data_params"]['total'] as $index => $value) {
         if ($value === true) {
             $tempField = $params["fields"][$index];
             $newFields[] = $tempField;
             $newHeaders[] = $params["headers"][array_search($tempField, $params["fields"])];
             $indices[] = array_search($tempField, $params["fields"]);
             $newParams["total"][] = true;
             $newParams["type"][] = $params["data_params"]["type"][$index];
         }
     }
     $filteredData = array();
     foreach ($this->reportData as $data) {
         $row = array();
         foreach ($indices as $index) {
             $row[] = $data[$index];
         }
         $filteredData[] = $row;
     }
     $summarizedData = array();
     $currentRow = $filteredData[0][0];
     for ($i = 0; $i < count($filteredData); $i++) {
         $row = array();
         $row[0] = $currentRow;
         $add = false;
         while ($filteredData[$i][0] == $currentRow) {
             for ($j = 1; $j < count($indices); $j++) {
                 $add = true;
                 $row[$j] += str_replace(",", "", $filteredData[$i][$j]);
             }
             $i++;
         }
         if ($add) {
             $summarizedData[] = $row;
         }
         $currentRow = $filteredData[$i][0];
         $i--;
     }
     $table = new TableContent($newHeaders, $summarizedData, $newParams);
     $table->setAutoTotals(true);
     $report->add($table);
 }