KoolReport's Forum

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

School schedule like table #1224

Open Ron opened this topic on on Dec 22, 2019 - 40 comments

Ron commented on Dec 22, 2019

Hi,

My datasource is looking as follow:

[day, hour_num, teacher_id, teacher_name, class_id]

each row represent a single hour in a specific weekday.

for example

[1, 1, 1, 'John Do', 1] The teacher John Do is teaching class 1 on Sunday (1) First Hour (1) I want to to be able to generate this report but not to look like a table but like a teacher schedule look attached image for example

Ron commented on Dec 23, 2019

Sir, any comment?

KoolReport commented on Dec 23, 2019

Ron, I have forwarded your case of use to dev team. I will come back to you soon.

David Winterburn commented on Dec 24, 2019

Please use the Cube process in Cube package like this:

    ->pipe(new \koolreport\cube\processses\Cube(array(
        "row" => "hour_num",
        "column" => "day",
        "count" => "teacher_id",
    ))); 
Ron commented on Dec 24, 2019

this is what i get

require_once APPPATH."/libraries/koolreport/core/autoload.php";
use \koolreport\cube\processses\Cube;
class Teacher_schedule extends \koolreport\KoolReport
{
    
    function setup()
    {
        $this->src('sbm')
        ->query('CALL getTeacherSchedule(:year, :teacher_id)')
        ->params(array(
            ":year"=>$this->params["year"],
            ":date"=>$this->params["teacher_id"]
        ))
        ->pipe(new \koolreport\cube\Cube(array(
            "row" => "hour_num",
            "column" => "day",
            "count" => "teacher_id",
        )))
        ->pipe($this->dataStore("st"));
    }
}

An uncaught Exception was encountered Type: Error

Message: Class 'koolreport\cube\Cube' not found

Filename: /var/www/parashapp.com/public_html/dev/sbm/application/reports/Teacher_schedule.php

Line Number: 33

Backtrace:

File: /var/www/parashapp.com/public_html/dev/sbm/application/libraries/koolreport/core/src/KoolReport.php Line: 100 Function: setup

File: /var/www/parashapp.com/public_html/dev/sbm/application/controllers/Report.php Line: 30 Function: __construct

File: /var/www/parashapp.com/public_html/dev/sbm/index.php Line: 315 Function: require_once

David Winterburn commented on Dec 25, 2019

Use this:

use \koolreport\cube\processes\Cube;
...
->pipe(new Cube(array(

or:

->pipe(new \koolreport\cube\processes\Cube(array(
Ron commented on Dec 25, 2019

Gives the same error in both options

David Winterburn commented on Dec 26, 2019

Did you install the Cube package or Pro version?

Ron commented on Dec 26, 2019

I have the pro version. I am using it with codeigniter and it in the library folder. I have other report that is using datagrid and it is working but with the cube it is making a problem. I verified the the cube folder exists and it is!

Ron commented on Dec 26, 2019

this is a screen shot of the project folder where the koolreport is located

David Winterburn commented on Dec 26, 2019

Well, typo be damned. In your code please replace:

processses\Cube //3 continuous letter "s"

with:

processes\Cube //2 continuous letter "s"
Ron commented on Dec 26, 2019

tnx david. btw this typo appears in your documentation website

https://www.koolreport.com/docs/cube/cube_process/

<?php
use \koolreport\cube\processses\Cube;
class MyReport extends \koolreport\KoolReport
{
    ...
    public function setup()
    {
        $this->src('sales')
        ->query("SELECT country,product,sale from tblPurchases")
        ->pipe(new Cube(array(
            "row"=>"country",
            "column"=>"product",
            "sum"=>"sale"
        )))
        ->pipe($this->dataStore('sales'));
    }
}
Ron commented on Dec 26, 2019

this is where I took it from

KoolReport commented on Dec 26, 2019

Sorry Ron, we have fixed the documentation.

Ron commented on Dec 26, 2019

this is the code of the view

Table::create(array(
            "dataSource"=>$this->dataStore("st"),
             "cssClass"=>array(
                "table"=>"table table-bordered",
                "th"=>"table-dark",
            )
        ))

and this is the result

  1. I want to remove/hide the {{all}} column
  2. I want to replace the day number and hour number to text
David Winterburn commented on Dec 27, 2019

With the Table widget, don't define its columns property if your columns are of integer type like "1", "2", "3", etc. Omit the columns property completely.

Instead, use processes like RemoveColumn, ColumnMeta, etc in your report's setup like this:

function Setup()
{
...
->pipe(new \koolreport\processes\RemoveColumn(array(
    "{{all}}"
)))
->pipe(new \koolreport\processes\ColumnMeta(array(
    "1" => array("label" => "Monday"),
    "2" => array("label" => "Tuesday"),
    ...
)))
->pipe($this->dataStore("myDatastore"));

}
Ron commented on Dec 27, 2019

tnx david. I want to add extra data that is in the stored procedure. currently I display only class_name in each <TD> but I want to add profession_name and group_name both are from the stored procedure. when I defined the cube it give me only class name. please view the setup:

function setup()
    {
        $this->src('sbm')
        ->query('CALL getTeacherSchedule(:year, :teacher_id)')
        ->params(array(
            ':year'=>$this->params['year'],
            ':teacher_id'=>$this->params['teacher_id']
        ))
        ->pipe(new Cube(array(
            'row' => 'hour_num',
            'column' => 'day',
            'max' => 'class_name',
        )))
        ->pipe(new \koolreport\processes\RemoveColumn(array(
            '{{all}}'
        )))
        ->pipe(new \koolreport\processes\ColumnMeta(array(
            'hour_num'=>array('label'=>lang('hour_num')),
            '1' => array("label" => lang('day_1')),
            '2' => array("label" => lang('day_2')),
            '3' => array("label" => lang('day_3')),
            '4' => array("label" => lang('day_4')),
            '5' => array("label" => lang('day_5')),
            '6' => array("label" => lang('day_6')),
        )))
        ->pipe($this->dataStore("st"));
    }

I want each TD to display more columns (class_name, group_name, profession_name etc)

David Winterburn commented on Dec 27, 2019

Maybe SuperCube could help if you want more rows or columns:

        ->pipe(new \koolreport\cube\processes\SuperCube(array(
            'rows' => 'profession_name, group_name, hour_num',
            'columns' => 'day',
            'max' => 'class_name',
        )))
Ron commented on Dec 27, 2019

I need all the data inside one cell no to generate more columns. superCube will just add me more columns

David Winterburn commented on Dec 27, 2019
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row) {
                $row['hour_num'] = $row['profession_name'] . ' - ' . $row['group_name'] . ' - ' . $row['hour_num'];
                return $row;
            }
        )))
        ->pipe(new Cube(array(
            'row' => 'hour_num',
            'column' => 'day',
            'max' => 'class_name',
        ))) 
Ron commented on Dec 27, 2019
  1. when I do this it is doing the job BUT the right side column of hour_num which should display the hour number of each day is gone.
  2. in each cell where the is not value I see 0. I need it to be empty string /null
David Winterburn commented on Dec 27, 2019
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row) {
                if (isset($row['hour_num'])) {
                    $row['hour_num'] = $row['profession_name'] . ' - ' . $row['group_name'] . ' - ' . $row['hour_num'];
                }
                return $row;
            }
        )))
Ron commented on Dec 27, 2019

still see 0 in empty cells

David Winterburn commented on Dec 27, 2019
        ...
        ->pipe(new Cube(array(
            'row' => 'hour_num',
            'column' => 'day',
            'max' => 'class_name',
        ))) 
        ->pipe(new Map(array(
            "{value}" => function($row) {
                foreach ($row as $k => $v)
                    if ($v == 0) $row[$k] = null;
                return $row;
            }
        )))
Ron commented on Dec 27, 2019

I fixed the code a little bit and it did the job ` ->pipe(new Map(array(

        "{value}" => function($row) {
            foreach ($row as $k => $v)
                if ($v == null) $row[$k] = 0;
            return $row;
        }
    )))

I have two extra questions:
1. I want to display in each report page a different teacher schedule. the datasource will include rows with all the teachers. teacher_id is the unique column for each teacher's schedule. 
2. In the datasource I have a column called "teacher_name" I want to display this name in the top of the table but not part of the table element like this 


Ron commented on Dec 27, 2019

sorry i missed this part <h3 class="text-center"><u><?php echo $row['teacher_name']; ?></u></h3>

Ron commented on Dec 29, 2019

sir?

David Winterburn commented on Dec 31, 2019

Hi Ron,

  1. Use a for loop in your report's setup running through your list of teacher. For each teacher set up a pipe from your datasource, filter with the teacher name and finally use the Cube process to save to a datastore.

  2. Again, use a for loop in your report's view. For each teacher print out their name and then their saved datastore as table.

Ron commented on Jan 6, 2020

Can you give me a sample code how to do it. this is my current setup function

function setup()
    {
        $this->src('sbm')
        ->query('CALL getTeacherSchedule(:year, :teacher_id)')
        ->params(array(
            ':year'=>$this->params['year'],
            ':teacher_id'=>$this->params['teacher_id']
        ))
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row) {
                $row['class_name'] =
                    $row['group_name'].'<br>'.
                    ( $this->params['show_class'] != null ? $row['class_name'] != '' ? $row['class_name'] : 'ללא כיתה' : null ).'<br>'.
                    ( $this->params['show_profession'] != null ? $row['profession_name'] : null ).'<br>'.
                    ( $this->params['show_room'] != null ? $row['room_name'] : null );
                $this->teacherName = $row['teacher_name'];
                return $row;
            }
        )))
        ->pipe(new Cube(array(
            'row' => 'hour_num',
            'column' => 'day',
            'max' => 'class_name'
        )))
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row) {
                foreach ($row as $k => $v)
                    if ($v == null) $row[$k] = "";
                return $row;
            }
        )))
        ->pipe(new \koolreport\processes\RemoveColumn(array(
            '{{all}}'
        )))
        ->pipe(new \koolreport\processes\ColumnMeta(array(
            'hour_num'=>array('label'=>lang('hour_num')),
            '1' => array("label" => lang('day_1')),
            '2' => array("label" => lang('day_2')),
            '3' => array("label" => lang('day_3')),
            '4' => array("label" => lang('day_4')),
            '5' => array("label" => lang('day_5')),
            '6' => array("label" => lang('day_6')),
        )))
        ->pipe($this->dataStore("st"));
    }

and the this is the view code:

<?php
    //MyReport.view.php
    use \koolreport\widgets\koolphp\Table;
?>
<html>
    <head>
        <title><?php echo lang('report_teacher_schdule'); ?></title></title>
        <style>
        @media print {
            .hidden-print {
                display: none !important;
            }
        }
        </style>
    </head>
    <body DIR="RTL">
        <div class="row">
            <div class="col text-center">
                <div class="hidden-print">
                    <button id="print" class="btn btn-success" href="<?php echo base_url('reports'); ?>" onclick="javascript: window.print()">
                        <?php echo lang('print'); ?>
                    </button>
                    <a class="btn btn-secondary mr-2" href="<?php echo base_url('reports'); ?>">
                        <?php echo lang('back'); ?>
                    </a>
                </div>
            </div>
        </div>
        <h1 class="text-center"><?php echo lang('report_teacher_schdule'); ?></h1>
        <h3 class="text-center"><u><?php echo $this->teacherName; ?></u></h3>

        <?php
        Table::create(array(
            "dataSource"=>$this->dataStore("st"),
            "cssClass"=>array(
                "table"=>"table table-bordered text-center",
                "th"=>"table-dark text-center",
            ),
            "sorting"=>array(
                "hour_num"=>"asc",
            )
        ))
        ?>
    </body>
</html>
Ron commented on Jan 19, 2020

Sir?

Ron commented on Jan 20, 2020

I will appreciate you response for the above?

Ron commented on Jan 28, 2020

I am trying to get your response for the last two weeks?

KoolReport commented on Jan 29, 2020

We are in the holiday so David will come back tomorrow. Please forgive us on this late.

Ron commented on Jan 29, 2020

ok sir. wating for david.

David Winterburn commented on Jan 30, 2020

Hi Ron,

I can only give direction but can''t write whole specific code for you. So here's some guide for your case:

//MyReport.php
$this->src("myDataSource")
->saveTo($node1);

foreach ($this->allTeachers as $teacher) {
  $node1->pipe(new Filter(array(
    array("teacher_name", "=", $teacher)
)))
->pipe(new Cube(...))
->pipe($this->dataStore("DS_" . $teacher);
}

//MyReport.view.php
foreach ($this->allTeachers as $teacher) {
    Table::create(array(
        "dataSource" => $this->dataStore("DS_" . $teacher),
    ));
}

Let us know if you have any difficulty doing this. Thanks!

Ron commented on Jan 30, 2020

ok I got it to work. tnx. now two questions: 1. In the report view header I have the teacher name. I do I make it to replace in each data source? 2. How do I make a page break for each teacher to be printed in a single page?

here is the code

<?php
//MyReport.php
require_once APPPATH."libraries/koolreport/core/autoload.php";
use \koolreport\cube\processes\Cube;
use \koolreport\processes\Filter;
class Teacher_schedule extends \koolreport\KoolReport
{
    use \koolreport\amazing\Theme;

    var $teacherName = "";

    function settings()
    {
        return array(
            "assets"=>array(
                "path"=>"../../assets",
                "url"=>"assets",
            ),
            "dataSources"=>array(
                "sbm"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=sbm",
                    "username"=>"admin",
                    "password"=>"9b72fa959aecee8a397ae1c3192ad30bef8ec2fe76cfe68a",
                    "charset"=>"utf8"
                )
            )
        );
    }

    function setup()
    {
        $this->src("sbm")
        ->query('CALL getTeacherSchedule(:year, :teacher_id)')
        ->params(array(
            ':year'=>$this->params['year'],
            ':teacher_id'=>$this->params['teacher_id']
        ))
        ->saveTo($node1);

        foreach (array(1,2,3,4) as $teacher) {
            $node1->pipe( new Filter( array (
                array("teacher_id", "=", $teacher)
            )))
            ->pipe(new \koolreport\processes\Map(array(
                "{value}" => function($row) {
                    $row['class_name'] =
                        $row['group_name'].'<br>'.
                        ( $this->params['show_class'] != null ? $row['class_name'] != '' ? $row['class_name'] : 'ללא כיתה' : null ).'<br>'.
                        ( $this->params['show_profession'] != null ? $row['profession_name'] : null ).'<br>'.
                        ( $this->params['show_room'] != null ? $row['room_name'] : null );
                    $this->teacherName = $row['teacher_name'];
                    return $row;
                }
            )))
            ->pipe(new Cube(array(
                'row' => 'hour_num',
                'column' => 'day',
                'max' => 'class_name'
            )))
            ->pipe(new \koolreport\processes\Map(array(
                "{value}" => function($row) {
                    foreach ($row as $k => $v)
                        if ($v == null) $row[$k] = "";
                    return $row;
                }
            )))
            ->pipe(new \koolreport\processes\RemoveColumn(array(
                '{{all}}'
            )))
            ->pipe(new \koolreport\processes\ColumnMeta(array(
                'hour_num'=>array('label'=>lang('hour_num')),
                '1' => array("label" => lang('day_1')),
                '2' => array("label" => lang('day_2')),
                '3' => array("label" => lang('day_3')),
                '4' => array("label" => lang('day_4')),
                '5' => array("label" => lang('day_5')),
                '6' => array("label" => lang('day_6')),
            )))
            ->pipe($this->dataStore("DS_" . $teacher));
        }    
    }
}

Ron commented on Feb 2, 2020

ok I managed to solve the issue with the teacher name in the header of each table. the only issue I have now is that I want each table (teacher) to appear is a single portrait page like page breaks. how do I do it?

KoolReport commented on Feb 2, 2020

You may use the page-break class before rendering widget:

<div class="page-break"></div>

Here is the documentation of page-break

Ron commented on Feb 3, 2020

its not working!

David Winterburn commented on Feb 5, 2020

Are you using Export or CloudExport package?

Ron commented on Feb 5, 2020

no

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