Skip to content

Commit

Permalink
Merge pull request #73 from manuscle/master
Browse files Browse the repository at this point in the history
add actions overrides
  • Loading branch information
ThaDafinser committed Feb 25, 2014
2 parents 0dd3cec + bd93b07 commit 232603c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
55 changes: 51 additions & 4 deletions src/ZfcDatagrid/Column/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
/**
* Action Column
* IMPORTANT: Will only be shown on HTML renderer
*
*
* So Attributes for HTML are valid...
*
*/
class Action extends AbstractColumn
{
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
14 changes: 13 additions & 1 deletion tests/ZfcDatagridTest/Column/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testConstructDefaultBoth ()
$this->assertFalse($column->isRowClickEnabled());
}

public function testAddAction ()
public function testAddRemoveAction ()
{
$column = new Column\Action();

Expand All @@ -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());
}
}

0 comments on commit 232603c

Please sign in to comment.