Skip to content

Commit

Permalink
Fix issue with adding data
Browse files Browse the repository at this point in the history
  • Loading branch information
iranianpep committed Sep 23, 2016
1 parent de939c0 commit 4a4ce05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/PhpTableGenerator/TableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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}";
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Tests/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 4a4ce05

Please sign in to comment.