Notification.inc.php
3.66 KB
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
<?php
require_once(KT_LIB_DIR . "/ktentity.inc");
require_once(KT_LIB_DIR . "/dashboard/NotificationRegistry.inc.php");
/**
* class Notification
*
* Represents a basic message, about an item, to a user. This ends up on the dashboard.
*/
class KTNotification extends KTEntity {
/** primary key value */
var $iId = -1;
var $iUserId;
// sType and sLabel provide the title of the dashboard alert.
var $sLabel; // a simple label - e.g. the document's title, or so forth.
var $sType; // namespaced item type. (e.g. ktcore/subscriptions, word/officeupload)
// this is used to create the appropriate renderobj.
var $dCreationTime = null; // the date/time of this items creation.
// iData1 and iData2 and integers, which can be used for whatever.
// sData1 and sData2 are similar.
// (i.e. you get very stupid subclassing semantics with up to 4 variables this way.
var $iData1;
var $iData2;
var $sData1;
var $sData2;
var $_bUsePearError = true;
function getId() { return $this->iId; }
function getLabel() { return $this->sLabel; }
function setLabel($sLabel) { $this->sLabel = $sLabel; }
function getType() { return $this->sType; }
function setType($sType) { $this->sType = $sType; }
function getIntData1() { return $this->iData1; }
function setIntData1($iData1) { $this->iData1 = $iData1; }
function getIntData2() { return $this->iData2; }
function setIntData2($iData2) { $this->iData2 = $iData2; }
function getStrData1() { return $this->sData1; }
function setStrData1($sData1) { $this->sData1 = $sData1; }
function getStrData2() { return $this->sData2; }
function setStrData2($sData2) { $this->sData2 = $sData2; }
var $_aFieldToSelect = array(
"iId" => "id",
"iUserId" => "user_id",
"sLabel" => "label",
"sType" => "type",
"dCreationDate" => "creation_date",
"iData1" => "data_int_1",
"iData2" => "data_int_2",
"sData1" => "data_str_1",
"sData2" => "data_str_2",
);
function _table () {
return KTUtil::getTableName('notifications');
}
function render() {
$notificationRegistry =& KTNotificationRegistry::getSingleton();
$handler = $notificationRegistry->getHandler($this->sType);
return $handler->handleNotification($this);
}
// Static function
function &get($iId) { return KTEntityUtil::get('KTNotification', $iId); }
function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTNotification', $sWhereClause); }
function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTNotification', $aOptions); }
}
/** register the base handlers. */
$notificationRegistry =& KTNotificationRegistry::getSingleton();
// abstract base-class for notification handler.
class KTNotificationHandler {
function handleNotification($oKTNotification) {
$oTemplating = new KTTemplating;
$oTemplate = $oTemplating->loadTemplate("kt3/notifications/generic");
$aTemplateData = array(
"context" => $oKTNotification,
);
return $oTemplate->render($aTemplateData);
}
}
class KTSubscriptionNotification extends KTNotificationHandler {
function handleNotification($oKTNotification) {
$oTemplating = new KTTemplating;
$oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions");
$aTemplateData = array(
"context" => $oKTNotification,
);
return $oTemplate->render($aTemplateData);
}
}
$notificationRegistry->registerNotificationHandler("ktcore/subscriptions","KTSubscriptionNotification");
?>