From 6548a89aafd25293b6a9f6e724c7846034478e24 Mon Sep 17 00:00:00 2001 From: Jared Hancock <gravydish@gmail.com> Date: Mon, 3 Sep 2012 22:26:20 -0500 Subject: [PATCH] Handle null items of the report table better Previously, if a SQL query did not return results for all rows, the results that were returned would be added to the table in a new column(s) and those (new) columns would be populated from top down. Therefore, the data would not correcly line up with the row to which it pertains. Now, results are matched back to the row to which they pertain, and rows are checked after each query to ensure they all have the same number of columns. --- include/ajax.reports.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/ajax.reports.php b/include/ajax.reports.php index 75394d623..87ae4a22a 100644 --- a/include/ajax.reports.php +++ b/include/ajax.reports.php @@ -104,16 +104,27 @@ class OverviewReportAjaxAPI extends AjaxController { ORDER BY '.$info['fields']) ); $rows = array(); + $cols = 1; foreach ($queries as $q) { list($c, $sql) = $q; $res = db_query($sql); - $i = 0; + $cols += $c; while ($row = db_fetch_row($res)) { - if (count($rows) <= $i) - $rows[] = array_slice($row, 0, count($row) - $c); - $rows[$i] = array_merge($rows[$i], array_slice($row, -$c)); - $i++; + $found = false; + foreach ($rows as &$r) { + if ($r[0] == $row[0]) { + $r = array_merge($r, array_slice($row, -$c)); + $found = true; + break; + } + } + if (!$found) + $rows[] = array_merge(array($row[0]), array_slice($row, -$c)); } + # Make sure each row has the same number of items + foreach ($rows as &$r) + while (count($r) < $cols) + $r[] = null; } return array("columns" => array_merge($info['headers'], array('Open','Assigned','Overdue','Closed','Reopened', -- GitLab