<?php
require_once APPPATH."Libraries/koolreport/core/autoload.php";
use \koolreport\cube\processes\Cube;
use \koolreport\processes\Filter;
class Class_schedule extends \koolreport\KoolReport
{
use \koolreport\export\Exportable;
var $classList = null;
function setup()
{
if ( $this->params['class_id'] != 0 ) {
$this->classList[] = array('id'=>$this->params['class_id'], 'class_name'=>'');
} else {
$this->classList = is_array($this->params['class_list']) ? $this->params['class_list'] : [] ;
}
$this->src("db")
//the last parameter 1 hides nn scedulabale professions 0 shows all.
->query('CALL getClassSchedule(:year, :class_id, 1)')
->params(array(
':year' => $this->params['year'],
':class_id' => $this->params['class_id']
))
->saveTo($node1);
foreach ($this->classList as $class) {
$node1->pipe( new Filter( array (
//array("class_id", "=", $class['id'])
array("class_id","contain",$class['id'])
)))
->pipe(new \koolreport\processes\Map(array(
"{value}" => function($row) {
$row['profession_name'] =
$row['profession_name'].
( $this->params['show_teacher'] != null ? $row['teacher_name'] != '' ? '<br>'.$row['teacher_name'] : lang('tts.no_class') : null ).
( $this->params['show_group_name'] != null ? '<br>'.$row['name'] : null ).
( $this->params['show_room'] != null ? '<br>'.$row['room_name'] : null );
if ( $this->params['class_id'] != 0 ) {
$this->classList[0]['class_name'] = $row['class_name'];
}
return $row;
}
)))
->pipe(new \koolreport\processes\Map(array(
"{end}" => function($count, $mapState) {
$emptyRows = [];
//$days = [1, 2, 3, 4, 5, 6]; //use day name if it's your case
foreach ($_SESSION['settings']->allowed_days as $key => $day) {
if ($day == 5 || $day == 6 ) {//if ($day ==true) {
foreach ($_SESSION['settings']->allowed_hours as $h_key => $hour) {
if ($hour == true) {
$emptyRows[] = ['day' => $key, 'hour_num' => $h_key];
}
}
}
}
return $emptyRows;
}
)))
->pipe(new Cube(array(
'row' => 'hour_num',
'column' => 'day',
'max' => 'profession_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\Map(array(
"{meta}" => function($meta) {
$colMetas = $meta["columns"];
foreach ($colMetas as $colKey => $colMeta) {
if (is_numeric($colKey)) {
$colMetas[$colKey]['label'] = lang("tts.day_$colKey"); //for columns '1', '2', etc
$colMetas[$colKey]['cssStyle'] = "width: 120px";
}
else {
$colMetas[$colKey]['label'] = lang("tts.$colKey"); //for column 'hour_num'
$colMetas[$colKey]['cssStyle'] = "width: 80px";
}
}
$meta["columns"] = $colMetas;
return $meta;
}
)))
->pipe(new \koolreport\processes\RemoveColumn(array(
'{{all}}'
)))
->pipe($this->dataStore("DS_" . $class['id']));
}
}
}