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'));