-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.coverLesson.php
188 lines (161 loc) · 5.66 KB
/
class.coverLesson.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
class CoverLesson {
//GETTERS SHOULD BE IMPLEMENTED
public $primaryKey;
public $tag;
public $datum;//Format Tag DD.MM.YYYY
public $timestampDatum;// Format YYYYMMDD
//public $vTeacher;//String
public $vTeacherObject;//Teacher
public $stunde;
public $klassen;
public $vFach;
public $vRaum;
public $eTeacherKurz;//String
public $eTeacherObject;//Teacher
public $eFach;
public $eRaum;
public $kommentar;
public $id;
public $aktiv;//boolean
public $emailed = 0;
public $changedEntry = 0;
public $stand;//Datum der letzten �nderung
private $connection;
/*
*Erstelle ein Objekt aus dem per Post gesendeten String
*@param text String
*/
public function constructFromPOST($text) {
$text = str_replace("'", "", $text);
$ta = explode(";", $text);
$v = array();
foreach ($ta as $t) {
$v[] = $t;
}
$this->tag = $v[0];
$this->datum = $v[1];
$this->vTeacher = $v[2];
$this->klassen = $this->trimClassString($v[3]);
$this->stunde = $this->trimPeriodString($v[4]);
$this->vFach = $v[5];
$this->vRaum = $v[6];
$this->eTeacherKurz = $v[7];
$this->eFach = $v[8];
$this->kommentar = $v[9];
if (isset($v[10])) {
$this->changedEntry = $v[10];
}
$this->stand = $v[11];
$this->id = $this->makeId();
}
/**
*Erstelle das Objekt aus den Daten der DB
*/
public function constructFromDB($data) {
$this->primaryKey = $data['vnr'];
$this->tag = $data['tag'];
$this->datum = Model::getInstance()->formatDateToCompleteDate($data['datum']);
$this->timestampDatum = $data['datum'];
//vertretender Lehrer als Objekt
//$vTeacher = new Teacher($this->getTeacherIdByUntisName($data['vLehrer']),$this->connection);
$rawData = array("untisName" => $data['vLehrer']);
$constructData = Model::getInstance()->getTeacherDataByUntisName($data['vLehrer']);
//$this->vTeacherObject = new Teacher($constructData['email'],$constructData['id'],$rawData);
$this->vTeacherObject = new Teacher(null, $constructData['id'], $rawData);
$this->vTeacherObject->getData();
$this->klassen = $data['klassen'];
$this->stunde = $data['stunde'];
$this->vFach = $data['fach'];
$this->vRaum = $data['raum'];
//zu vertretender Lehrer als Objekt
if ($this->vTeacherObject->getShortName() == $data['eLehrer']) {
//Vertreter und zu Vertretender sind identisch -> z.B. bei Raum�nderung
$this->eTeacherObject = $this->vTeacherObject;
} else {
$rawData = array("shortName" => $data['eLehrer']);
$constructData = Model::getInstance()->getTeacherDataByShortName($data['eLehrer']);
$eTeacher = new Teacher($constructData['email'], $constructData['id'], $rawData);
$eTeacher->getData();
$this->eTeacherObject = $eTeacher;
}
$this->eFach = $data['eFach'];
$this->kommentar = $data['kommentar'];
$this->id = $data['id'];
}
/**
* Formatierung der Daten (f�hrende Null bei Klassennamen, Leerzeichen entfernen etc)
*
* @param String
*
* @return String
*/
private function trimClassString($clStrg) {
//Klassenstring anpassen
$kArr = explode(",", $clStrg);
for ($x = 0; $x < count($kArr); $x++) {
$kArr[$x] = trim($kArr[$x], $character_mask = " \t\n\r\0\x0B");
if (strlen($kArr[$x]) < 3 && $kArr[$x][0] <> "K" && $kArr[$x][0] <> "A") {
$kArr[$x] = '0' . $kArr[$x];
}
}
$klassenString = "";
for ($x = 0; $x < count($kArr); $x++) {
if ($x == 0) {
$klassenstring = $kArr[$x];
} else {
$klassenstring = $klassenstring . ',' . $kArr[$x];
}
}
$search = array('K1', 'K2');
$replace = array('11', '12');
$klassenstring = str_replace($search, $replace, $klassenstring);
return $klassenstring;
}
/*
*Formatierung der Daten entferne Leerzeichen aus dem String der die betroffene Stunde anzeigt
*/
private function trimperiodString($pString) {
//Stundenstring
return str_replace(" ", "", $pString);
}
/**
*Erstlle eine ID zum Eintrag in die DB mittels welcher die Existenz einse Eintrags �berpr�ft wird
*
* @return string
*/
private function makeId() {
return $this->datum . $this->vTeacher . $this->klassen . $this->stunde . $this->eTeacherKurz;
}
/*
*Ermittle Primary key zu Lehrer Untis Name
*/
private function getTeacherIdByUntisName($untisName) {
//check if still needed
/* OLD CODE
$data = $this->connection->selectValues("SELECT lNr FROM lehrerdata WHERE untisName=\"$untisName\" ");
if(count($data)>0){
return $data[0][0];
}
else{
return $untisName;//z.B. "---" oder "selbst"
}
*/
}
/*
*Ermittle Primary key zu Lehrer Kurzzeichen
*/
private function getTeacherIdByKurz($kurz) {
//check if still needed
/* OLD CODE
$data = $this->connection->selectValues("SELECT lNr FROM lehrerdata WHERE kurz=\"$kurz\" ");
if(count($data)>0){
return $data[0][0];
}
else{
return $kurz;
}
*/
}
}
?>