2020-11-17 16:40:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File containing lesson class.
|
|
|
|
*
|
|
|
|
* @package mod_timetable
|
|
|
|
* @copyright 2020 Raphael Dannecker <raphael.dannecker@steinbeisschule-reutlingen.de>
|
|
|
|
* @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 <raphael.dannecker@steinbeisschule-reutlingen.de>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
class lesson {
|
|
|
|
|
2020-11-22 09:21:53 +00:00
|
|
|
/** @var array the data of lesson */
|
|
|
|
public $data;
|
2020-11-17 16:40:21 +00:00
|
|
|
|
2020-11-22 09:21:53 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->type = $lesson->type;
|
2020-11-22 09:21:53 +00:00
|
|
|
$this->text = "";
|
|
|
|
$this->substitution = "";
|
|
|
|
$this->teachera = "";
|
|
|
|
$this->subjecta = "";
|
|
|
|
$this->classa = "";
|
|
|
|
$this->rooma = "";
|
|
|
|
//$this->teacherb = "";
|
|
|
|
//$this->subjectb = "";
|
|
|
|
//$this->classb = "";
|
|
|
|
//$this->roomb = "";
|
|
|
|
$this->teacherchanged = false;
|
|
|
|
$this->subjectchanged = false;
|
|
|
|
$this->classchanged = false;
|
|
|
|
$this->roomchanged = false;
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->reason = "";
|
|
|
|
$this->subtype = 0;
|
2020-11-22 09:21:53 +00:00
|
|
|
}
|
2020-11-21 16:57:50 +00:00
|
|
|
|
2020-11-22 09:21:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param object $substitution Substitution
|
|
|
|
*/
|
|
|
|
public function process_substitution($substitution) {
|
|
|
|
if (//$this->lessonid == $substitution->lesson &&
|
|
|
|
$this->teacher == $substitution->teacherb &&
|
|
|
|
$this->subject == $substitution->subjectb &&
|
|
|
|
preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/", $substitution->classb) &&
|
|
|
|
preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/", $substitution->roomb) ) {
|
|
|
|
// Append change info
|
|
|
|
$this->teachera = $substitution->teachera;
|
|
|
|
$this->subjecta = $substitution->subjecta;
|
|
|
|
$this->classa = $substitution->classa;
|
|
|
|
$this->rooma = $substitution->rooma;
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->teacherchanged = ($this->teacher != $this->teachera && $this->teachera) ? true : false;
|
|
|
|
$this->subjectchanged = ($this->subject != $this->subjecta && $this->subjecta) ? true : false;
|
|
|
|
$this->classchanged = (!preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/" , $this->classa ) && $this->classa) ? true : false;
|
|
|
|
$this->roomchanged = (!preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/" , $this->rooma ) && $this->rooma) ? true : false;
|
2020-11-22 09:21:53 +00:00
|
|
|
if ($substitution->text) $this->text .= $substitution->text;
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->subtype = $substitution->type;
|
2020-11-22 09:21:53 +00:00
|
|
|
$this->substitution = "1";
|
|
|
|
return 1;
|
|
|
|
} elseif (//$this->lessonid == $substitution->lesson &&
|
|
|
|
$this->teacher == $substitution->teachera &&
|
|
|
|
$this->subject == $substitution->subjecta &&
|
|
|
|
preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/", $substitution->classa) &&
|
|
|
|
preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/", $substitution->rooma) ) {
|
|
|
|
// Append change info
|
|
|
|
$this->teacherb = $substitution->teacherb;
|
|
|
|
$this->subjectb = $substitution->subjectb;
|
|
|
|
$this->classb = $substitution->classb;
|
|
|
|
$this->roomb = $substitution->roomb;
|
|
|
|
$this->teacherchanged = ($this->teacher != $this->teacherb) ? true : false;
|
|
|
|
$this->subjectchanged = ($this->subject != $this->subjectb) ? true : false;
|
|
|
|
$this->classchanged = (!preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/" , $this->classb )) ? true : false;
|
|
|
|
$this->roomchanged = (!preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/" , $this->roomb )) ? true : false;
|
|
|
|
if ($substitution->text) $this->text .= $substitution->text;
|
|
|
|
// TODO Entfall, falls teacherb!=teacher bzw. class not in classb bzw. roomb!=room TODO
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->subtype = $substitution->type;
|
2020-11-22 09:21:53 +00:00
|
|
|
$this->substitution = "1";
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2020-11-17 16:40:21 +00:00
|
|
|
}
|
2020-11-22 09:21:53 +00:00
|
|
|
}
|
2020-11-17 16:40:21 +00:00
|
|
|
|
2020-11-22 09:21:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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;
|
2020-11-17 16:40:21 +00:00
|
|
|
}
|
2020-11-22 09:21:53 +00:00
|
|
|
}
|
2020-11-17 16:40:21 +00:00
|
|
|
|
2020-11-22 09:21:53 +00:00
|
|
|
public function integrate($lesson) {
|
|
|
|
if($this->lessonid == $lesson->lessonid &&
|
|
|
|
//$this->teacher == $lesson->teacher &&
|
|
|
|
$this->subject == $lesson->subject &&
|
|
|
|
$this->room == $lesson->room &&
|
2020-12-05 10:03:20 +00:00
|
|
|
$this->type == $lesson->type &&
|
|
|
|
$this->subtype == $lesson->subtype &&
|
|
|
|
//$this->teacherchanged == $lesson->teacherchanged &&
|
2020-11-22 09:21:53 +00:00
|
|
|
$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;
|
|
|
|
}
|
2020-11-17 16:40:21 +00:00
|
|
|
}
|