KoolReport's Forum

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

Adding Pipes to source without chaining #2730

Open pbs opened this topic on on Jun 16, 2022 - 2 comments

pbs commented on Jun 16, 2022

I am new to Koolreports and trying to see if it will do what we need, and I am sure it will as it looks great. I have created a simple report which reads students from a database, and their grades. It groups on name and grade and totals the number of each grade per student.

This is working.

public function setup()
    {
        $this->src('students')        
        ->query("SELECT S.FirstName, S.LastName, SR.Grade FROM tbl_students AS S INNER JOIN tbl_results as SR ON S.StudentId = SR.StudentId)
        ->pipe(new Sort(array(
            "LastName"=>"asc",
            "FirstName"=>"asc"
        )))
        ->pipe(new Group(array(
            "by" => "FirstName,Lastname,Grade",
            "count" => "Grades"
        )))        
        ->pipe($this->dataStore('grades'));
}

However, depending on conditions, I may or may not want to do the group section. So I have tried this, and separated the group pipe. The report runs but the group pipe does not get added. How would I go about doing this.

$this->src('students')
        ->query("SELECT S.FirstName, S.LastName, SR.Grade FROM tbl_students AS S INNER JOIN tbl_results as SR ON S.StudentId = SR.StudentId)
        ->pipe(new Sort(array(
            "LastName"=>"asc",
            "FirstName"=>"asc"
        )))
        ->saveTo($root);
        
        /* potential if's here to decide if grouping is required */        
        $root->pipe(new Group(array(
            "by" => "FirstName,Lastname,Grade",
            "count" => "Grades"
        )));
        
        $root->pipe($this->dataStore('grades'));

Sebastian Morales commented on Jun 17, 2022

Pls try this:

    if (...) {
        $root->pipe(new Group(array(
            "by" => "FirstName,Lastname,Grade",
            "count" => "Grades"
        )))
        ->saveTo($root);
    }

    $root->pipe($this->dataStore('grades'));
pbs commented on Jun 17, 2022

Thank you so much - it worked.

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
solved

None