-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclass.notification.php
104 lines (94 loc) · 3.56 KB
/
class.notification.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
<?php
class notification {
private $iUser = 0;
private $iSender = 0;
private $strKey = NULL;
private $strMessage = NULL;
private $strLink = NULL;
public function notification($iUser = NULL, $strKey = NULL, $strMessage = NULL, $strLink = NULL) {
if (is_null($iUser)) $iUser = me();
$this->iUser = $iUser;
$this->strKey = is_null($strKey) ? "message" + floor(time()/10) : $strKey;
if (!is_null($strKey)) $this->key($strKey);
if (!is_null($strMessage)) $this->message($strMessage);
if (!is_null($strLink)) $this->link($strLink);
$this->sender(me());
}
public function sender($iSender = NULL) {
if (!is_null($iSender)) $this->iSender = $iSender;
return $this->iSender;
}
public function key($strKey = NULL) { /* get / set key => een key wordt gebruikt als een notification overschreven kan worden
bv. key = "subscription.35" => "Marcel heeft zich ingeschreven voor dit item"
later key = "subscription.35" => "Marcel en Ludo hebben zich ingeschreven voor dit item"
*/
if (!is_null($strKey)) $this->strKey = $strKey;
return $this->strKey;
}
public function message($strMessage = NULL) {
if (!is_null($strMessage)) $this->strMessage = $strMessage;
return $this->strMessage;
}
public function link($strLink = NULL) {
if (!is_null($strLink)) $this->strLink = $strLink;
return $this->strLink;
}
public function send() {
$arFields = array(
"sleutel" => $this->strKey,
"readdate" => 0,
"message" => $this->strMessage,
"link" => $this->strLink,
"author" => $this->iSender,
"receiver" => $this->iUser,
"datum" => owaestime(),
);
$oDB = new database();
$arKeys = array();
$arValues = array();
foreach ($arFields as $strKey=>$strValue) {
$arKeys[] = $strKey;
$arValues[] = "'" . $oDB->escape($strValue) . "'";
}
$strSQL = "insert into tblNotifications (" . implode(", ", $arKeys) . ") values (" . implode(", ", $arValues) . "); ";
$oDB->execute($strSQL);
return true;
}
public function read($strKey) {
$oDB = new database();
$strSQL = "update tblNotifications set readdate = " . owaestime() . " where receiver = " . $this->iUser . " and sleutel = '" . $oDB->escape($strKey) . "' and readdate = 0; ";
$oDB->execute($strSQL);
}
public function getList($iLimit = NULL) {
$arMessages = array();
$arJoin = array();
$strLimit = "";
$arOrder = array();
$arWhere = array(
"n.receiver = " . $this->iUser,
);
if (is_null($iLimit)) $arWhere[] = "n.readdate = 0";
if (is_numeric($iLimit)) {
$strLimit = " limit $iLimit ";
$arJoin[] = " LEFT OUTER JOIN tblNotifications n2 ON n2.sleutel = n.sleutel AND n2.id > n.id ";
$arWhere[] = " n2.id IS NULL";
$arWhere[] = "n.datum > " . (time()-60*60*24*14);
$arOrder[] = "n.datum desc";
} else {
$arOrder[] = "n.datum";
}
$oDB = new database("select n.* from tblNotifications n " . implode(" ", $arJoin) . " where " . implode(" and ", $arWhere) . " order by " . implode(",", $arOrder) . " $strLimit ;", TRUE);
while ($oDB->nextRecord()) {
$arMessage =array(
"title" => "",
"time" => $oDB->get("datum"),
"from" => $oDB->get("author"),
"message" => $oDB->get("message"),
"icon" => ($oDB->get("author")==0) ? fixPath("/img/owaes80x80.png") : user($oDB->get("author"))->getImage("80x80", FALSE),
);
if ($oDB->get("link") != "") $arMessage["link"] = $oDB->get("link");
$arMessages[$oDB->get("sleutel")] = $arMessage;
}
return $arMessages;
}
}