diff --git a/src/ZfcDatagrid/Column/Action.php b/src/ZfcDatagrid/Column/Action.php index 537e3d69..e4e15f65 100644 --- a/src/ZfcDatagrid/Column/Action.php +++ b/src/ZfcDatagrid/Column/Action.php @@ -4,8 +4,9 @@ /** * Action Column * IMPORTANT: Will only be shown on HTML renderer - * + * * So Attributes for HTML are valid... + * */ class Action extends AbstractColumn { @@ -28,13 +29,14 @@ public function __construct($uniqueId = 'action') } /** - * Add a action to the this action column + * @param Action\AbstractAction $action * - * @param Action\AbstractAction $action + * @return self */ - public function addAction(Action\AbstractAction $action) + public function addAction (Action\AbstractAction $action) { $this->actions[] = $action; + return $this; } /** @@ -45,4 +47,49 @@ public function getActions() { return $this->actions; } + + /** + * @param array|Action\AbstractAction[] $actions + * + * @return self + */ + 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 self + */ + public function removeAction($key = null) + { + unset ($this->actions[$key]); + + return $this; + } + + /** + * @return self + */ + public function clearActions() + { + $this->actions = array(); + + return $this; + } } diff --git a/tests/ZfcDatagridTest/Column/ActionTest.php b/tests/ZfcDatagridTest/Column/ActionTest.php index 5fb96dbe..3bb9aefa 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,17 @@ 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()); + $column->clearActions(); + $this->assertCount(0, $column->getActions()); } }