From b105763189b8014d996b7cbf9cae042c9fa00115 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Mon, 31 Aug 2015 08:38:19 +0200 Subject: [PATCH 1/3] adding pull #200 --- docs/03. Columns.md | 3 +++ .../Column/Action/AbstractAction.php | 2 +- src/ZfcDatagrid/Column/Action/Button.php | 23 ++++++++++++++++--- .../Column/Action/AbstractActionTest.php | 6 ++--- .../Column/Action/ButtonTest.php | 16 ++++++++++++- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/docs/03. Columns.md b/docs/03. Columns.md index b918226c..01b25db1 100644 --- a/docs/03. Columns.md +++ b/docs/03. Columns.md @@ -78,6 +78,9 @@ $viewAction = new Column\Action\Button(); $viewAction->setLabel('View'); $viewAction->setLink('view/url/id'); +//or set a dynamic column/row value as label +$viewAction->setLabel($oneColumn); + $actions = new Column\Action(); $actions->setLabel(''); $actions->addAction($viewAction); diff --git a/src/ZfcDatagrid/Column/Action/AbstractAction.php b/src/ZfcDatagrid/Column/Action/AbstractAction.php index 2c85a79a..ac7ae868 100644 --- a/src/ZfcDatagrid/Column/Action/AbstractAction.php +++ b/src/ZfcDatagrid/Column/Action/AbstractAction.php @@ -298,7 +298,7 @@ public function isDisplayed(array $row) if (isset($row[$rule['column']->getUniqueId()])) { $value = $row[$rule['column']->getUniqueId()]; } - + if ($rule['value'] instanceof AbstractColumn) { if (isset($row[$rule['value']->getUniqueId()])) { $ruleValue = $row[$rule['value']->getUniqueId()]; diff --git a/src/ZfcDatagrid/Column/Action/Button.php b/src/ZfcDatagrid/Column/Action/Button.php index 954b5431..2041142f 100644 --- a/src/ZfcDatagrid/Column/Action/Button.php +++ b/src/ZfcDatagrid/Column/Action/Button.php @@ -1,6 +1,8 @@ getLabel() == '') { throw new \InvalidArgumentException('A label is required for this action type, please call $action->setLabel()!'); } - return $this->getLabel(); + $label = $this->getLabel(); + if ($label instanceof AbstractColumn) { + $label = $row[$label->getUniqueId()]; + } + + return 'getAttributesString($row) . '>' . $label . ''; } } diff --git a/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php b/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php index be020a9f..04ccce0d 100644 --- a/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php +++ b/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php @@ -226,7 +226,7 @@ public function testIsDisplayedException() $this->column->getUniqueId() => '32', ]); } - + public function testIsDisplayedByColumn() { /* @var $action \ZfcDatagrid\Column\Action\AbstractAction */ @@ -238,8 +238,8 @@ public function testIsDisplayedByColumn() $action->addShowOnValue($this->column, $columnCompare, Filter::GREATER_EQUAL); $this->assertEquals([ [ - 'column' => $this->column, - 'value' => $columnCompare, + 'column' => $this->column, + 'value' => $columnCompare, 'comparison' => Filter::GREATER_EQUAL, ], ], $action->getShowOnValues()); diff --git a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php index cc5f0b74..75a2a898 100644 --- a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php +++ b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php @@ -20,7 +20,7 @@ public function testConstruct() ], $button->getAttributes()); } - public function testLabel() + public function testLabelAndToHtml() { $button = new Button(); @@ -31,6 +31,20 @@ public function testLabel() $this->assertEquals($html, $button->toHtml([])); } + public function testColumnLabelAndToHtml() + { + $col = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn'); + $col->setUniqueId('myCol'); + + $button = new Button(); + + $button->setLabel($col); + $this->assertEquals('My label', $button->getLabel()); + + $html = 'Blubb'; + $this->assertEquals($html, $button->toHtml(['myCol' => 'Blubb'])); + } + public function testHtmlException() { $button = new Button(); From 6562180991c2ba4cf7ec4bc6cc986a71eda4d019 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Mon, 31 Aug 2015 09:00:54 +0200 Subject: [PATCH 2/3] fixing test /no string conversion --- src/ZfcDatagrid/Column/Action/Button.php | 2 +- tests/ZfcDatagridTest/Column/Action/ButtonTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ZfcDatagrid/Column/Action/Button.php b/src/ZfcDatagrid/Column/Action/Button.php index 2041142f..62d432d5 100644 --- a/src/ZfcDatagrid/Column/Action/Button.php +++ b/src/ZfcDatagrid/Column/Action/Button.php @@ -20,7 +20,7 @@ public function __construct() */ public function setLabel($name) { - $this->label = (string) $name; + $this->label = $name; } /** diff --git a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php index 75a2a898..3a1f9626 100644 --- a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php +++ b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php @@ -39,7 +39,7 @@ public function testColumnLabelAndToHtml() $button = new Button(); $button->setLabel($col); - $this->assertEquals('My label', $button->getLabel()); + $this->assertInstanceOf('ZfcDatagrid\Column\AbstractColumn', $button->getLabel()); $html = 'Blubb'; $this->assertEquals($html, $button->toHtml(['myCol' => 'Blubb'])); From 72821c9a0fe8fb6f62d9231b93620e346195ba50 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Mon, 31 Aug 2015 11:00:49 +0200 Subject: [PATCH 3/3] fixing tets --- tests/ZfcDatagridTest/Column/Action/ButtonTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php index 3a1f9626..0929b2e0 100644 --- a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php +++ b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php @@ -16,7 +16,7 @@ public function testConstruct() $this->assertEquals([ 'href' => '#', - 'class' => 'btn', + 'class' => 'btn btn-default', ], $button->getAttributes()); } @@ -27,7 +27,7 @@ public function testLabelAndToHtml() $button->setLabel('My label'); $this->assertEquals('My label', $button->getLabel()); - $html = 'My label'; + $html = 'My label'; $this->assertEquals($html, $button->toHtml([])); } @@ -41,7 +41,7 @@ public function testColumnLabelAndToHtml() $button->setLabel($col); $this->assertInstanceOf('ZfcDatagrid\Column\AbstractColumn', $button->getLabel()); - $html = 'Blubb'; + $html = 'Blubb'; $this->assertEquals($html, $button->toHtml(['myCol' => 'Blubb'])); }