* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace mod_timetable; defined('MOODLE_INTERNAL') || die(); /** * Class lesson * * @package mod_timetable * @copyright 2020 Raphael Dannecker * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class lesson { /** @var array the data of lesson */ public $data; /** * Class constructor * * @param object $lesson Lesson */ public function __construct($lesson) { $this->lessonid= $lesson->lessonid; $this->teacher = $lesson->teacher; $this->subject = $lesson->subject; $this->class = $lesson->class; $this->room = $lesson->room; $this->period = $lesson->period; $this->day = $lesson->day; $this->text = ""; $this->substitution = ""; $this->teachera = ""; $this->subjecta = ""; $this->classa = ""; $this->rooma = ""; } /** * * @param object $substitution Substitution */ public function process_substitution($substitution) { // echo "Entering substitution! $this->teacher, $this->subject, $this->class, $this->room \n\t $substitution->teacherb, $substitution->subjectb, $substitution->classb, $substitution->roomb\n"; if (//$this->lessonid == $substitution->lesson && $this->teacher == $substitution->teacherb && $this->subject == $substitution->subjectb && $this->class == $substitution->classb && $this->room == $substitution->roomb) { //preg_match("(^|~)$this->teacher($|~)", $substitution->teacherb) && //preg_match("(^|~)$this->subject($|~)", $substitution->subjectb) && //preg_match("(^|~)$this->class($|~)", $substitution->classb) && //preg_match("(^|~)$this->room($|~)", $substitution->roomb)) { // Append change info // if (!preg_match("(^|~)$this->teacher($|~)", $substitution->teachera)) $this->teachera = $substitution->teachera; // if (!preg_match("(^|~)$this->subject($|~)", $substitution->subjecta)) $this->subjecta = $substitution->subjecta; // if (!preg_match("(^|~)$this->class($|~)" , $substitution->classa )) $this->classa = $substitution->classa; // if (!preg_match("(^|~)$this->room($|~)" , $substitution->rooma )) $this->rooma = $substitution->rooma; if ($this->teacher != $substitution->teachera) $this->teachera = $substitution->teachera; if ($this->subject != $substitution->subjecta) $this->subjecta = $substitution->subjecta; if ($this->class != $substitution->classa ) $this->classa = $substitution->classa; if ($this->room != $substitution->rooma ) $this->rooma = $substitution->rooma; if ($substitution->text) $this->text .= $substitution->text; // echo "In substitution! $this->teachera, $this->subjecta, $this->classa, $this->rooma\n"; $this->substitution = "1"; return 1; } elseif (//$this->lessonid == $substitution->lesson && $this->teacher == $substitution->teachera && $this->subject == $substitution->subjecta && $this->class == $substitution->classa && $this->room == $substitution->rooma) { if ($substitution->text) $this->text .= $substitution->text; $this->type .= $substitution->type; // echo "In substitution! $this->teachera, $this->subjecta, $this->classa, $this->rooma\n"; #$this->substitution = "1"; return 1; } else { return 0; } } /** * * @param object $absence Absence */ public function process_absence($absence) { // echo "Process_absence: $absence->endperiod"; if ((($absence->type == 'L' && $absence->name == $this->teacher) || ($absence->type == 'K' && $absence->name == $this->class) || ($absence->type == 'R' && $absence->name == $this->room)) && $absence->startperiod <= $this->period && $absence->endperiod >= $this->period) { $this->text .= $absence->text; $this->reason = $absence->reason; $this->startperiod = $absence->startperiod; $this->endperiod = $absence->endperiod; return 1; } else { return 0; } } public function integrate($lesson) { if($this->lessonid == $lesson->lessonid && //$this->teacher == $lesson->teacher && $this->subject == $lesson->subject && $this->room == $lesson->room && $this->text == $lesson->text) { if ($this->class != $lesson->class) { $class1parts = explode("/", $this->class); $class2parts = explode("/", $lesson->class); if (count($class1parts)>1 && count($class2parts)==2) { $this->class .= "/".$class2parts[1]; } else $this->class .= $lesson->class; } if ($this->teacher != $lesson->teacher) { $this->teacher .= "/".$lesson->teacher; } return true; } else return false; } }