SubscriptionManager.inc
7.12 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
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
198
199
200
201
202
203
204
205
206
207
208
<?php
require_once("$default->owl_fs_root/lib/documentmanagement/Document.inc");
require_once("$default->owl_fs_root/lib/foldermanagement/Folder.inc");
require_once("$default->owl_fs_root/lib/subscriptions/DocumentSubscription.inc");
require_once("$default->owl_fs_root/lib/subscriptions/FolderSubscription.inc");
/**
*
* $Id$
*
* Facilitates adding and removing file and folder subscriptions.
*
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* @version $Revision$
* @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa
*
* @package lib.subscriptions
*/
class SubscriptionManager {
/**
* The default text for the folder subscription alert email
*/
var $sFolderSubscriptionEmail;
/**
* The default text for the document subscription alert email
*/
var $sDocumentSubscriptionEmail;
/**
* Creates a folder subscription.
*
* @param int the folder to create the subscription for
* @param int the user to create the subscription for
* @return true if the subscription creation succeed, false and error message otherwise
*/
function createFolderSubscription($iFolderID, $iUserID) {
global $lang_folder_subs_exists;
if (!FolderSubscription::exists($iFolderID, $iUserID)) {
$oFolderSubscription = new FolderSubscription($iFolderID, $iUserID);
if ($oFolderSubscription->create()) {
return true;
} else {
// error message set in FolderSubscription::create
return false;
}
} else {
// TODO: lookup username and folder name from ids for error message
$_SESSION["errorMessage"] = $lang_folder_sub_exists . " folderID=$iFolderID, userID=$iUserID";
return false;
}
}
/**
* Removes a folder subscription.
*
* @param int the folder to remove the subscription for
* @param int the user to remove the subscription for
*/
function removeFolderSubscription($iFolderID, $iUserID) {
global $lang_folder_sub_not_exists;
if (FolderSubscription::exists($iFolderID, $iUserID)) {
$oFolderSubscription = FolderSubscription::getByIDs($iFolderID, $iUserID);
if ($oFolderSubscription->delete()) {
return true;
} else {
// error message set in FolderSubscription::delete
return false;
}
} else {
$_SESSION["errorMessage"] = $lang_folder_sub_not_exists;
return false;
}
}
/**
* Sends an alert to each of the users subscribed to this folder
* that the folder has changed.
*
* @param int the folder to fire alerts for
*/
function fireFolderSubscriptionAlert($iFolderID) {
// retrieve all users subscribed to this folder and their notification settings
// insert into notification table (dashboard)
// if email notification is enabled, email them
// if sms notification is enabled, sms them
}
/**
* Sends an alert to each of the users subscribed to this document
* that the document has changed.
*
* @param int the document to fire alerts for
*/
function fireDocumentSubscriptionAlert($iDocumentID) {
}
/**
* Creates a document subscription.
*
* @param int the document to create the subscription for
* @param int the user to create the subscription for
*/
function createDocumentSubscription($iDocumentID, $iUserID) {
global $lang_document_subs_exists;
if (!DocumentSubscription::exists($iDocumentID, $iUserID)) {
$oDocumentSubscription = new DocumentSubscription($iDocumentID, $iUserID);
if ($oDocumentSubscription->create()) {
return true;
} else {
// error message set in DocumentSubscription::create
return false;
}
} else {
// TODO: lookup username and folder name from ids for error message
$_SESSION["errorMessage"] = $lang_document_subs_exists . " documentID=$iDocumentID, userID=$iUserID";
return false;
}
}
/**
* Removes a document subscription.
*
* @param int the document to remove the subscription for
* @param int the user to remove the subscription for
*/
function removeDocumentSubscription($iDocumentID, $iUserID) {
global $lang_document_sub_not_exists;
if (DocumentSubscription::exists($iDocumentID, $iUserID)) {
$oDocumentSubscription = DocumentSubscription::getByIDs($iDocumentID, $iUserID);
if ($oDocumentSubscription->delete()) {
return true;
} else {
// error message set in DocumentSubscription::delete
return false;
}
} else {
$_SESSION["errorMessage"] = $lang_document_sub_not_exists;
return false;
}
}
/**
* Retrieves all document and folders that the user is subscribed to
*
* @param integer the ID of the user to retrieve subscriptions for
* @return array of folder objects
*/
function retrieveSubscriptions($iUserID) {
return $aSubscriptions = array("folders" => SubscriptionManager::retrieveFolderSubscriptions($iUserID),
"documents" => SubscriptionManager::retrieveDocumentSubscriptions($iUserID));
}
/**
* Retrieves the folders that the passed user is subscribed to
*
* @param integer the ID of the user to retrieve folder subscriptions for
* @return array of folder objects, false if the database interaction fails
*/
function retrieveFolderSubscriptions($iUserID) {
global $default;
$sql = $default->db;
if ($sql->query("SELECT folder_id FROM " . $default->owl_folder_subscriptions_table . " WHERE user_id = $iUserID")) {
$aFolders = array();
while ($sql->next_record()) {
$aFolders[] = & Folder::get($sql->f("folder_id"));
}
} else {
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
return $aFolders;
}
/**
* Retrieves the documents that the passed user is subscribed to
*
* @param integer the ID of the user to retrieve document subscriptions for
* @return array of document objects
*/
function retrieveDocumentSubscriptions($iUserID) {
global $default;
$sql = $default->db;
if ($sql->query("SELECT document_id FROM " . $default->owl_document_subscriptions_table . " WHERE user_id = $iUserID")) {
$aDocuments = array();
while ($sql->next_record()) {
$aDocuments[] = & Document::get($sql->f("document_id"));
}
} else {
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
return $aDocuments;
}
}
?>