public function prepareBody($outputType) { $this->numRows = 0; $tblBody = "<tbody>"; while ($currentRow = $this->reportResult->fetchRowPersist(MYSQLI_ASSOC)) { if (isset($currentRow['platformID'])) { ReportNotes::addPlatform($currentRow['platformID']); } if (isset($currentRow['publisherPlatformID'])) { ReportNotes::addPublisher($currentRow['publisherPlatformID']); } $colnum = 1; $subtotal = 0; $rowOutput = "<tr class='data'>"; foreach (ReportTable::filterRow($currentRow) as $field => $value) { if ($this->performSubtotalFlag && isset($this->columnData['sum'][$field])) { // get the numbers out for summing if ($field === 'QUERY_TOTAL') { $value = $subtotal; } else { $subtotal += $value; } $this->totalSumArray[$field] += $value; } $rowOutput .= $this->formatColumn($outputType, $currentRow, $field, $value); // end if display columns is Y ++$colnum; } // end loop through columns $rowOutput .= "</tr>"; ++$this->numRows; if (!$this->report->onlySummary || $outputType !== 'web') { $tblBody .= $rowOutput; } } $tblBody .= "</tbody>"; return $tblBody; }
public function process(DBResult &$reportArray, ReportNotes &$notes) { $countForGrouping = 0; $sumArray = array(); $totalSumArray = array(); $holdArray = array(); $fields = $reportArray->fetchFields(); $numFields = count($fields); if ($numFields !== 0) { echo '<thead>'; $this->processColumns($fields); echo '</thead>'; // loop through resultset $groupArrayCount = count($this->groupColsArray); $rowNum = 1; echo '<tbody>'; while ($currentRow = $reportArray->fetchRowPersist(MYSQLI_ASSOC)) { if (isset($currentRow['platformID'])) { $notes->addPlatform($currentRow['platformID']); } if (isset($currentRow['publisherPlatformID'])) { $notes->addPublisher($currentRow['publisherPlatformID']); } $reset = $rowNum === $this->startPage; $performCheck = false; $print_subtotal_flag = false; $rowoutput = "<tr>"; $colNum = 0; foreach ($currentRow as $field => $data) { // stop displaying columns once we hit title ID or platform ID if ($field === 'titleID' || $field === 'platformID') { break; } if ($data === '') { $data = ' '; } // if sort is explicitly requested we will group on this column if it is allowed according to DB if (isset($holdArray[$colNum]) && isset($this->groupColsArray[$field]) && $data != $holdArray[$colNum]) { if ($this->sortColumn === $colNum + 1) { $hold_rprt_grpng_data = $holdArray[$colNum]; $print_subtotal_flag = true; // if no sort order is specified, use default grouping } else { if ($this->sortOrder === '' && $holdArray[$colNum] != '') { $this->groupColsArray[$field] = true; // default echo flag to Y, we will reset later $print_subtotal_flag = true; $performCheck = true; if ($groupArrayCount === 1) { $hold_rprt_grpng_data = $holdArray[$colNum]; } else { $hold_rprt_grpng_data = 'Group'; } } } } if ($data != (isset($holdArray[$colNum]) ? $holdArray[$colNum] : null) || $reset || $this->outputType === 'xls' || $this->perform_subtotal_flag && $this->sortOrder === '' && $groupArrayCount > 1) { $reset = true; $print_data = $data; } else { if ($print_data == '0' . $print_data) { $print_data = ' '; } else { $print_data = $data; } } if ($this->outputType === 'web' && $print_data !== ' ' && $field === 'TITLE') { if ($this->report->getID() != '1') { $print_data .= '<br><font size="-4"><a target="_BLANK" href="report.php?reportID=1&prm_4=' . ($this->showUnadjusted ? 'Y' : 'N') . "&titleID={$currentRow['titleID']}&outputType=web'>view related titles</a></font>"; } // echo link resolver link if (($currentRow['PRINT_ISSN'] || $currentRow['ONLINE_ISSN']) && isset($this->baseURL)) { $print_data .= '<br><font size="-4"><a target="_BLANK" href="' . $this->getLinkResolverLink($currentRow) . '">view in link resolver</a></font>'; } } if (isset($currentRow[$field . '_OVERRIDE']) || isset($currentRow[$field . '_OUTLIER']) && $currentRow[$field . '_OUTLIER'] > 0) { if (!$this->showUnadjusted && isset($currentRow[$field . '_OVERRIDE'])) { $rowoutput .= "<td class='overriden'>" . $currentRow[$field . '_OVERRIDE'] . "</td>"; } else { if ($this->showUnadjusted) { if ($currentRow[$field . '_OUTLIER'] >= 4) { $tmp_outlier_color = Color::$levelColors[$currentRow[$field . '_OUTLIER'] - 3]; } else { $tmp_outlier_color = Color::$levelColors[$currentRow[$field . '_OUTLIER']]; } $rowoutput .= "<td class='{$tmp_outlier_color['1']}'>{$print_data}</td>"; unset($tmp_outlier_color); } else { $rowoutput .= "<td class='flagged'>{$print_data}</td>"; } } } else { if (isset($currentRow['MERGE_IND'])) { $rowoutput .= "<td class='merged'>{$print_data}</td>"; } else { $rowoutput .= "<td>{$print_data}</td>"; } } $holdArray[$colNum] = $data; if (isset($this->groupColsArray[$field])) { if ($this->sortColumn === $colNum + 1) { $hold_rprt_grpng_data = $holdArray[$colNum]; } else { if ($this->sortOrder === '') { if ($groupArrayCount === 1) { $hold_rprt_grpng_data = $holdArray[$colNum]; } else { $hold_rprt_grpng_data = 'Group'; } } } } // get the numbers out for summing if (isset($sumArray[$field])) { $sumArray[$field][] = $data; $totalSumArray[$field] += $data; // filter_var($data, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) ); } else { $sumArray[$field] = array($data); $totalSumArray[$field] = $data; // filter_var($data, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) ); } // end if display columns is Y ++$colNum; } // end loop through columns ++$countForGrouping; // loop through the group arrays, if any are N then echo flag is N otherwise it will be left to Y // determine if the current row needs to be grouped if ($this->outputType != 'xls' && !($performCheck && in_array(false, $this->groupColsArray, true) !== false) && $print_subtotal_flag && $this->report->hasGroupTotalInd()) { $rowoutput .= "</tr>"; if ($countForGrouping > 1) { $rowoutput .= "<tr class='data'><td class='sum'>Total for {$hold_rprt_grpng_data}</td>"; foreach ($fields as $field) { $rowoutput .= '<td class="sum">' . $this->sumField($this->sumColsArray[$field], $sumArray[$field]) . '</td>'; } $rowoutput .= '</tr>'; } $sumArray = array(); $countForGrouping = 0; $rowoutput .= "<tr class='data'><td colspan={$numFields}> </td></tr><tr class='data'>"; } ++$rowNum; if ($this->maxRows <= 0 || $rowNum < $this->maxRows) { echo $rowoutput; } if ($rowNum % 15000 === 0) { ob_flush(); } } --$rowNum; if ($this->outputType != 'xls' && $this->perform_subtotal_flag) { if ($this->report->hasGroupTotalInd() && $hold_rprt_grpng_data) { // one last grouping summary if ($countForGrouping > 1) { $grp .= "<tr class='data'><td class='sum'>Total for {$hold_rprt_grpng_data}</td>"; foreach ($fields as $field) { $grp .= "<td class='sum'>" . $this->sumField($this->sumColsArray[$field], $sumArray[$field]) . "</td>"; } echo "{$grp}</tr>"; } echo "<tr class='data'><td colspan={$numFields}> </td></tr>"; } echo '<tr class="data"><td class="sum">Total for Report</td>'; $total = ''; for ($colNum = 1; $colNum < $numFields; ++$colNum) { if (isset($this->sumColsArray[$fields[$colNum]])) { $total = $this->sumColTotal($this->sumColsArray[$fields[$colNum]], $totalSumArray[$fields[$colNum]], $rowNum); } if ($total) { echo "<td class='sum'>{$total}</td>"; } else { echo "<td class='sum'> </td>"; } } echo '</tr>'; } if ($rowNum === 0) { echo "<tr class='data'><td colspan={$numFields}><i>Sorry, no rows were returned."; } else { echo "<tr><td colspan={$numFields} align='right'><i>Showing rows {$this->startPage} to "; if ($this->maxRows > 0 && $rowNum > $this->maxRows) { echo "{$this->maxRows} of {$this->maxRows}"; } else { echo "{$rowNum} of {$rowNum}"; } } echo '</i></td></tr></tbody>'; } }