-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.newsletter.php
197 lines (169 loc) · 4.25 KB
/
class.newsletter.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
189
190
191
192
193
194
195
196
197
<?php
/*
* Klasse Newsletter
*/
class Newsletter {
private $id;
private $newsDate;
private $newsText;
private $lastChanged;
private $sendDate;
private $schoolYear;
/***********************
****GETTER und SETTER***
***********************/
/*
* getId
* return int
*/
public function getId() {
return $this->id;
}
/*
* getNewsdate
* return int
*/
public function getNewsDate() {
return $this->newsDate;
}
/*
* getnewsText
* return String
*/
public function getNewsText() {
return $this->newsText;
}
/*
* getlastchanged
* return int
*/
public function getLastChanged() {
return $this->lastChanged;
}
/*
* get sendDate
* return int
*/
public function getSendDate() {
return $this->sendDate;
}
/*
* getSchoolYear
* return String
*/
public function getSchoolYear() {
return $this->schoolYear;
}
/*
* setId
* @param int
*/
private function setId($value) {
$this->id = $value;
}
/*
* setNewsDate
* @param int
*/
private function setNewsDate($value) {
$this->newsDate = $value;
}
/*
* setnewsText
* @param String
*/
private function setNewsText($value) {
$this->newsText = $value;
}
/*
* setlastChanged
* @param int
*/
private function setLastChanged($value) {
$this->lastChanged = $value;
}
/*
* setsendDate
* @param int
*/
private function setSendDate($value) {
$this->sendDate = $value;
}
/*
* setSchoolYear
* @param String
*/
private function setSchoolYear($value) {
$this->schoolYear = $value;
}
/*********************
***Konstruktoren******
*********************/
/**
* Konstruktor nach Übergabe von id
* param int id
*/
public function createFromId($id) {
$data = Model::getInstance()->getNewsletterData($id);
$this->id = $id;
$date = $data["publishdate"];
$date = $date[6] . $date[7] . '.' . $date[4] . $date[5] . '.' . $date[0] . $date[1] . $date[2] . $date[3];
$this->setNewsDate($date);
$this->setNewsText($data["text"]);
$this->setLastChanged($data["lastchanged"]);
$this->setSendDate($data["sent"]);
$this->setSchoolYear($data["schoolyear"]);
ChromePhp::info($this);
}
/**
* Konstruktor nach Übergabe von POST Werten
*
* @param newsDate
* @param newsText
* @param int id
*/
public function createFromPOST($newsdate, $newstext, $id) {
$datearr = explode(".", $newsdate);
$dyr = $datearr[2];
$dmt = $datearr[1];
$dd = $datearr[0];
$publishdate = $dyr . $dmt . $dd;
($dmt > 7) ? $schoolYear = $dyr . "/" . ($dyr + 1) : $schoolYear = ($dyr - 1) . "/" . $dyr;
$this->setNewsDate($publishdate);
//trimming whitespaces
$newstext = trim($newstext);
//Escaping quotes in text
$newstext = str_replace("'", "'", $newstext);
$newstext = str_replace('"', '\"', $newstext);
$this->setNewsText($newstext);
$this->setSendDate(null);
$this->setSchoolYear($schoolYear);
if (isset($id)) {
Model::getInstance()->UpdateNewsInDB($id, $publishdate, $newstext, $schoolYear);
$this->setId = $id;
} else {
$this->setId(Model::getInstance()->InsertNewsIntoDB($publishdate, $newstext, $schoolYear));
}
}
/**
* enter sendDate
*/
public function UpdateSendDate() {
Model::getInstance()->setNewsSendDate($this->id);
}
/**
* make Text to view
*
* @param bool html
*
* @return String
*/
public function makeViewText($user, $html = true, $send = false) {
if ($html) {
$text = Model::getInstance()->makeHTMLNewsletter($this, $user, $send);
} else {
$text = Model::getInstance()->makePlainTextNewsletter($this);
}
return $text;
}
}