From b63cbe5e7758e55776ed5ceb4c8a98654c9856a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Belair Date: Sun, 9 Feb 2014 12:47:16 +0100 Subject: [PATCH 1/5] add actions overrides --- src/ZfcDatagrid/Column/Action.php | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/ZfcDatagrid/Column/Action.php b/src/ZfcDatagrid/Column/Action.php index acbc9cc4..bc224c65 100644 --- a/src/ZfcDatagrid/Column/Action.php +++ b/src/ZfcDatagrid/Column/Action.php @@ -24,9 +24,15 @@ public function __construct ($uniqueId = 'action') $this->setRowClickDisabled(true); } + /** + * @param Action\AbstractAction $action + * + * @return $this + */ public function addAction (Action\AbstractAction $action) { $this->actions[] = $action; + return $this; } /** @@ -37,4 +43,42 @@ public function getActions () { return $this->actions; } + + /** + * @param array|Action\AbstractAction[] $actions + * + * @return $this + */ + public function setActions (array $actions) + { + $this->actions = $actions; + return $this; + } + + /** + * @param int $key + * + * @return mixed + */ + public function getAction($key) + { + if (isset($this->actions[$key])) { + return $this->actions[$key]; + } + } + + /** + * @param int $key + * + * @return $this + */ + public function removeAction($key = null) + { + if (null === $key) { + return $this->setActions(array()); + } + unset ($this->actions[$key]); + + return $this; + } } From 9d92ecbae5df1f33e05aea6b7cadca4251a12ea9 Mon Sep 17 00:00:00 2001 From: Emmanuel Belair Date: Mon, 24 Feb 2014 18:10:28 +0100 Subject: [PATCH 2/5] ActionTest --- tests/ZfcDatagridTest/Column/ActionTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/ZfcDatagridTest/Column/ActionTest.php b/tests/ZfcDatagridTest/Column/ActionTest.php index 5fb96dbe..0f548150 100644 --- a/tests/ZfcDatagridTest/Column/ActionTest.php +++ b/tests/ZfcDatagridTest/Column/ActionTest.php @@ -22,7 +22,7 @@ public function testConstructDefaultBoth () $this->assertFalse($column->isRowClickEnabled()); } - public function testAddAction () + public function testAddRemoveAction () { $column = new Column\Action(); @@ -39,5 +39,15 @@ public function testAddAction () $column->addAction($action3); $this->assertCount(3, $column->getActions()); + $this->assertEquals($action2, $column->getAction(1)); + $column->removeAction(2); + $this->assertCount(2, $column->getActions()); + + $actions = array( + $this->getMock('ZfcDatagrid\Column\Action\Button'), + $this->getMock('ZfcDatagrid\Column\Action\Button') + ); + $column->setActions($actions); + $this->assertEquals($actions, $column->getActions()); } } From 2b084e4d87f3b8a53634c9eae1c36a78ab04494c Mon Sep 17 00:00:00 2001 From: Emmanuel Belair Date: Tue, 25 Feb 2014 08:46:43 +0100 Subject: [PATCH 3/5] Action self --- src/ZfcDatagrid/Column/Action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ZfcDatagrid/Column/Action.php b/src/ZfcDatagrid/Column/Action.php index 16b497eb..f1224421 100644 --- a/src/ZfcDatagrid/Column/Action.php +++ b/src/ZfcDatagrid/Column/Action.php @@ -31,7 +31,7 @@ public function __construct($uniqueId = 'action') /** * @param Action\AbstractAction $action * - * @return $this + * @return self */ public function addAction (Action\AbstractAction $action) { @@ -51,7 +51,7 @@ public function getActions() /** * @param array|Action\AbstractAction[] $actions * - * @return $this + * @return self */ public function setActions (array $actions) { @@ -74,7 +74,7 @@ public function getAction($key) /** * @param int $key * - * @return $this + * @return self */ public function removeAction($key = null) { From 8655a901b331050ea289649416622b6c2bbfd674 Mon Sep 17 00:00:00 2001 From: Emmanuel Belair Date: Tue, 25 Feb 2014 09:12:51 +0100 Subject: [PATCH 4/5] Action clear --- src/ZfcDatagrid/Column/Action.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ZfcDatagrid/Column/Action.php b/src/ZfcDatagrid/Column/Action.php index f1224421..e4e15f65 100644 --- a/src/ZfcDatagrid/Column/Action.php +++ b/src/ZfcDatagrid/Column/Action.php @@ -78,11 +78,18 @@ public function getAction($key) */ public function removeAction($key = null) { - if (null === $key) { - return $this->setActions(array()); - } unset ($this->actions[$key]); return $this; } + + /** + * @return self + */ + public function clearActions() + { + $this->actions = array(); + + return $this; + } } From bd93b0737bc8ab4209688d1192c89675ce2b3edc Mon Sep 17 00:00:00 2001 From: Emmanuel Belair Date: Tue, 25 Feb 2014 09:15:26 +0100 Subject: [PATCH 5/5] Action clear --- tests/ZfcDatagridTest/Column/ActionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ZfcDatagridTest/Column/ActionTest.php b/tests/ZfcDatagridTest/Column/ActionTest.php index 0f548150..3bb9aefa 100644 --- a/tests/ZfcDatagridTest/Column/ActionTest.php +++ b/tests/ZfcDatagridTest/Column/ActionTest.php @@ -49,5 +49,7 @@ public function testAddRemoveAction () ); $column->setActions($actions); $this->assertEquals($actions, $column->getActions()); + $column->clearActions(); + $this->assertCount(0, $column->getActions()); } }