Skip to content

Commit

Permalink
bug #17002 [Console][Table] fixed render row that contains multiple c…
Browse files Browse the repository at this point in the history
…ells. (aitboudad)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console][Table] fixed render row that contains multiple cells.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |  #16998
| License       | MIT
| Doc PR        | n/a

Commits
-------

3790ac7 [Console][Table] fixed render row with multiple cells.
  • Loading branch information
fabpot committed Dec 18, 2015
2 parents 35a3ab3 + 6129f2a commit 111994f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ private function buildTableRows($rows)

// Remove any new line breaks and replace it with a new line
foreach ($rows[$rowKey] as $column => $cell) {
$rows[$rowKey] = $this->fillCells($rows[$rowKey], $column);
if (!strstr($cell, "\n")) {
continue;
}
Expand All @@ -363,7 +362,7 @@ private function buildTableRows($rows)

$tableRows = array();
foreach ($rows as $rowKey => $row) {
$tableRows[] = $row;
$tableRows[] = $this->fillCells($row);
if (isset($unmergedRows[$rowKey])) {
$tableRows = array_merge($tableRows, $unmergedRows[$rowKey]);
}
Expand Down Expand Up @@ -429,21 +428,23 @@ private function fillNextRows($rows, $line)
* fill cells for a row that contains colspan > 1.
*
* @param array $row
* @param int $column
*
* @return array
*/
private function fillCells($row, $column)
private function fillCells($row)
{
$cell = $row[$column];
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
// insert empty value into rows at column position
array_splice($row, $position, 0, '');
$newRow = array();
foreach ($row as $column => $cell) {
$newRow[] = $cell;
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
// insert empty value at column position
$newRow[] = '';
}
}
}

return $row;
return $newRow ?: $row;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,24 @@ public function testRenderProvider()
| ISBN | Title | Author |
+------+-------+--------+
TABLE
),
'Row with multiple cells' => array(
array(),
array(
array(
new TableCell('1', array('colspan' => 3)),
new TableCell('2', array('colspan' => 2)),
new TableCell('3', array('colspan' => 2)),
new TableCell('4', array('colspan' => 2)),
),
),
'default',
<<<TABLE
+--+--+--+--+--+--+--+--+--+
| 1 | 2 | 3 | 4 |
+--+--+--+--+--+--+--+--+--+
TABLE
),
);
Expand Down

0 comments on commit 111994f

Please sign in to comment.