KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dynamically add processes. #1126

Open KPA opened this topic on on Oct 11, 2019 - 2 comments

KPA commented on Oct 11, 2019

Hi,

I am trying to add data transformation processes dynamically into the pipeline using the ProcessGroup method. This is not working so far. My question is if this is possible at all and if so how to do it.

This is some test code I wrote to see if it is possible.

ProcessGroup

<?php

use \koolreport\processes\Filter;

class MyProcessGroup extends \koolreport\core\ProcessGroup
{


    public function setup()
    {
        $processes = [];

        $filter1 = new Filter(array(
            array(
                "value", ">", 50000
            )
        ));

        $filter2 = new Filter(array(array(
            "time", "=", "2018"
        )));

        $processes[] = $filter1;
        $processes[] = $filter2;

        $incoming = $this->incoming();

        foreach ($processes as $process) {
            $incoming->pipe($process);
        }

        $incoming->pipe($this->outcoming());

    }
}

The report itself

<?php

require_once "../vendor/koolreport/core/autoload.php";

class PopulationInTheNetherlands extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources" => array(
                "gdp" => array(
                    "class" => '\koolreport\datasources\CSVDataSource',
                    "filePath" => "C:\Users\Koen\Downloads\gdp.csv"
                )
            )
        );
    }

    protected function setup()
    {

        $processGroup = new MyProcessGroup();

        $this->src('gdp')
            ->pipe($processGroup)
            ->pipe($this->dataStore('data'));
    }
}

In the view I just simply display the data as a table for debugging purposes.

<?php

use \koolreport\widgets\google\Table;

?>

<div class="report-content">
    <div class="text-center">
        <h1>GDP Per Year</h1>
    </div>
</div>

<div style="width: 800px; height: 300px;">

    <?php
    
    Table::create(array(
        "dataSource" => $this->dataStore('data')
    ))

    ?>

</div>
KoolReport commented on Oct 11, 2019

It is totally possible but you need to do like this:

        $node = $this->incoming();

        foreach ($processes as $process) {
            $node = $node->pipe($process);
        }

        $node->pipe($this->outcoming());
KPA commented on Oct 11, 2019

Thank you that works :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None