dudapiotr / ZfTable

*Not supported*ZfTable 3.1. Awesome ZF2 table / grid (and much much more) generator with huge possibilities of decorating and conditioning. Integrated with DataTables, Doctrine 2, Bootstrap 2.0 and 3.0.
http://dudapiotrek.laohost.net/
MIT License
75 stars 59 forks source link

Add callable render #12

Closed nicodmf closed 10 years ago

nicodmf commented 10 years ago

I have no time to commit

But theres changes works :


<?php
//in ZfTable\Decorator\DecoratorPluginManager
class DecoratorPluginManager extends AbstractPluginManager
{
    protected $invokableClasses = array(
        /*...*/
        'cellcallable' => '\ZfTable\Decorator\Cell\CallableDecorator',
        /*...*/
    );
        /*...*/
}

And the new file :


<?php

namespace ZfTable\Decorator\Cell;

/**
 * Description of CallableDecorator
 *
 * @author Nicolas de Marqué <nicolas.demarque@gmail.com>
 */
class CallableDecorator extends AbstractCellDecorator
{
    protected $callable;

    public function __construct(  callable $callable)
    {        
        $this->callable = $callable;        
    }

    public function render( $value )
    {
        $values = array();

        $actualRow = $this->getCell()->getActualRow();     

        return call_user_func_array($this->callable, array($value, $actualRow));

    }
}

The call is consequently :

<?php

        $this->getHeader( 'template' )->getCell()->addDecorator( 'callable', function($value, $values) {
            return $v . $values['anotherfield'] . "called";
        });

Thanks for your plugin very usefull :)

dudapiotr commented 10 years ago

Thanks for your proposition. It's added to 3.0 branch.