<?php
// Standard GPL and phpdocs
namespace mod_timetable\output;                                                                                                         
 
use renderable;                                                                                                                     
use renderer_base;                                                                                                                  
use templatable;                                                                                                                    
use stdClass;                                                                                                                       
 
class timetable implements renderable, templatable {                                                                               
    /** @var string $sometext Some text to show how to pass data to a template. */                                                  
    var $sometext = null;                                                                                                           
 
    public function __construct($timetable) {                                                                                        
        $this->timetable = $timetable;                                                                                                
    }
 
    /**                                                                                                                             
     * Export this data so it can be used as the context for a mustache template.                                                   
     *                                                                                                                              
     * @return stdClass                                                                                                             
     */                                                                                                                             
    public function export_for_template(renderer_base $output) {
        /*                                                                    
        $data = new stdClass();
        $numperiod = get_config('timetable', 'numperiod');
        if ($this->timetable->periodmax > $numperiod) $numperiod = $this->timetable->periodmax;
	    $numdayweek = 5 + get_config('timetable', 'saturday');
        if ($numdayweek == 6) $data->saturday = 1;
        $periods = array();

        for ($period=0; $period<$numperiod; $period++) {
            $days = array();
            for ($day=0; $day<$numdayweek; $day++) {
                $days[$day] = new stdClass;
                //$days[$day]->lessons = "$period, $day";
                $days[$day]->lessons = array();

                if (array_key_exists($period+1,$this->timetable->data[$day+1]) 
                    && array_key_exists('lesson',$this->timetable->data[$day+1][$period+1])) {
                    foreach ($this->timetable->data[$day+1][$period+1]['lesson'] as $lesson) {
                        $mylesson = new stdClass;
                        $mylesson->class = $lesson->class;
                        $mylesson->teacher = $lesson->teacher;
                        $mylesson->room = $lesson->room;
                        $mylesson->subject = $lesson->subject;
                        $mylesson->status = $lesson->week[$this->timetable->week-1];
                        $mylesson->flag = $lesson->flag;
                        $days[$day]->lessons[] = $mylesson;
                    }
                }
            }
            $periods[$period] = new stdClass;
            $periods[$period]->days = $days;
            $periods[$period]->number = $period+1;
        }
        $data->periods = $periods;
        //echo var_dump($data);  */                                                                                                                                                                                             
        return $this->timetable->prepare_output();                                                                                                               
    }
}