From 94555b357a01b567446de3d1cf385dc2bf5546f3 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 9 Jul 2024 00:54:14 +0300 Subject: [PATCH] fix: Fix to Few Detected Bugs --- webfiori/ui/HTMLTable.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/webfiori/ui/HTMLTable.php b/webfiori/ui/HTMLTable.php index 97b6e81..74e6386 100644 --- a/webfiori/ui/HTMLTable.php +++ b/webfiori/ui/HTMLTable.php @@ -159,7 +159,7 @@ public function getValue(int $rowIndex, int $colIndex) { if ($cell != null) { $ch = $cell->getChild(0); - if ($ch->getName() == '#TEXT') { + if ($ch->getNodeName() == '#TEXT') { return $ch->getText(); } @@ -170,6 +170,8 @@ public function getValue(int $rowIndex, int $colIndex) { /** * Removes a column from the table given column index. * + * Note that if the table has one column, the method will not remove it. + * * @param int $colIndex The index of the column. * * @return array The method will return an array that holds objects that @@ -179,10 +181,11 @@ public function getValue(int $rowIndex, int $colIndex) { public function removeCol(int $colIndex) : array { $colCells = []; - if ($colIndex < $this->cols()) { + if ($colIndex < $this->cols() && $this->cols() > 1) { foreach ($this as $row) { $colCells[] = $row->children()->remove($colIndex); } + $this->cols--; } return $colCells; @@ -190,6 +193,8 @@ public function removeCol(int $colIndex) : array { /** * Removes a row given its index. * + * Note that if the table has only one row, the method will not remove it. + * * @param int $rowIndex The index of the row. * * @return TableRow|null If the row is removed, the method will return @@ -197,7 +202,15 @@ public function removeCol(int $colIndex) : array { * will return null. */ public function removeRow(int $rowIndex) { - return $this->removeChild($rowIndex); + if ($this->rows() > 1) { + $row = $this->removeChild($rowIndex); + + if ($row !== null) { + $this->rows--; + } + + return $row; + } } /** * Returns number of rows in the table.