From 4a4ce051ea209b2e51e0a0b3206b114e5ba30b6f Mon Sep 17 00:00:00 2001 From: Ehsan Abbasi Date: Fri, 23 Sep 2016 23:29:29 +1000 Subject: [PATCH] Fix issue with adding data --- src/PhpTableGenerator/TableGenerator.php | 13 ++++++------- src/Tests/TableTest.php | 12 ++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/PhpTableGenerator/TableGenerator.php b/src/PhpTableGenerator/TableGenerator.php index 0fff676..a3af661 100644 --- a/src/PhpTableGenerator/TableGenerator.php +++ b/src/PhpTableGenerator/TableGenerator.php @@ -60,11 +60,12 @@ public function __construct($class = '', $id = '', $style = '') /** * add data to an element * - * @param array $data + * @param $key + * @param $value */ - public function addData(array $data) + public function addData($key, $value) { - $this->data[] = $data; + $this->data[$key] = $value; } /** @@ -93,10 +94,8 @@ public function getAttributeHtml($attribute) $allDataAttributes = ''; if (!empty($allData)) { - foreach ($allData as $data) { - if (isset($data[0]) && $data[1]) { - $allDataAttributes .= " data-{$data[0]}={$data[1]}"; - } + foreach ($allData as $key => $data) { + $allDataAttributes .= " data-{$key}={$data}"; } } diff --git a/src/Tests/TableTest.php b/src/Tests/TableTest.php index 927f787..b6a7fbc 100644 --- a/src/Tests/TableTest.php +++ b/src/Tests/TableTest.php @@ -62,7 +62,7 @@ public function testSimpleTableAddCell() $row3 = new Row(array($cell5, $cell6)); $head = new Head($row1); - $head->addData(array('myData', 'myDataValue')); + $head->addData('myData', 'myDataValue'); $body = new Body(array($row2, $row3)); @@ -94,7 +94,7 @@ public function testSimpleTableAddRow() $row3 = new Row(array($cell5, $cell6)); $head = new Head($row1); - $head->addData(array('myData', 'myDataValue')); + $head->addData('myData', 'myDataValue'); $body = new Body(array($row3)); @@ -140,7 +140,7 @@ public function testSimpleTableAttributes() $row3 = new Row(array($cell5, $cell6)); $head = new Head($row1); - $head->addData(array('myData', 'myDataValue')); + $head->addData('myData', 'myDataValue'); $body = new Body(array($row2, $row3)); @@ -183,7 +183,7 @@ public function testSimpleTableRowspanColspan() $row4 = new Row(array($cell6)); $head = new Head($row1); - $head->addData(array('myData', 'myDataValue')); + $head->addData('myData', 'myDataValue'); $body = new Body(array($row2, $row3, $row4)); @@ -233,10 +233,10 @@ public function testTableComplete() $caption = new Caption('This is caption content'); $caption->class = 'captionClass'; - $caption->addData(array('captionData', 'captionDataValue')); + $caption->addData('captionData', 'captionDataValue'); $head = new Head($row1); - $head->addData(array('myData', 'myDataValue')); + $head->addData('myData', 'myDataValue'); $body = new Body(array($row2, $row3, $row4));