Commit ba43fa86043a056190e16f4ff44abc307e6ae09a

Authored by Michael Joseph
1 parent 58235c72

reformatted, added datetime_alerted and is_alerted attributes and updated update method accordingly


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@814 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/subscriptions/DocumentSubscription.inc
1 <?php 1 <?php
2 /** 2 /**
3 - *  
4 - * $Id$  
5 - *  
6 - * Represents a document subscription.  
7 - *  
8 - * Licensed under the GNU GPL. For full terms see the file COPYING.  
9 - *  
10 - * @version $Revision$  
11 - * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa  
12 - *  
13 - * @package lib.subscriptions  
14 - */ 3 +*
  4 +* $Id$
  5 +*
  6 +* Represents a document subscription.
  7 +*
  8 +* Licensed under the GNU GPL. For full terms see the file COPYING.
  9 +*
  10 +* @version $Revision$
  11 +* @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa
  12 +*
  13 +* @package lib.subscriptions
  14 +*/
15 class DocumentSubscription { 15 class DocumentSubscription {
16 - 16 +
17 /** 17 /**
18 - * Primary key  
19 - */ 18 + * Primary key
  19 + */
20 var $iID; 20 var $iID;
21 /** 21 /**
22 - * The ID of the document subscribed to  
23 - */ 22 + * The ID of the document subscribed to
  23 + */
24 var $iDocumentID; 24 var $iDocumentID;
25 /** 25 /**
26 - * The ID of the user subscribed to the document  
27 - */ 26 + * The ID of the user subscribed to the document
  27 + */
28 var $iUserID; 28 var $iUserID;
29 -  
30 /** 29 /**
31 - * Creates a new document subscription object  
32 - *  
33 - * @param integer the document ID  
34 - * @param integer the user ID 30 + * The time this subscription was triggered
  31 + */
  32 + var $dTimeAlerted;
  33 + /**
  34 + * Whether this subscription is triggered
35 */ 35 */
  36 + var $bIsAlerted;
  37 +
  38 + /**
  39 + * Creates a new document subscription object
  40 + *
  41 + * @param integer the document ID
  42 + * @param integer the user ID
  43 + */
36 function DocumentSubscription($iDocumentID, $iUserID) { 44 function DocumentSubscription($iDocumentID, $iUserID) {
37 - //id of -1 means that the object has not yet been stored in the database 45 + //id of -1 means that the object has not yet been stored in the database
38 $this->iID = -1; 46 $this->iID = -1;
39 $this->iDocumentID = $iDocumentID; 47 $this->iDocumentID = $iDocumentID;
40 $this->iUserID = $iUserID; 48 $this->iUserID = $iUserID;
  49 + $this->dTimeAlerted = getCurrentDateTime();
  50 + $this->bIsAlerted = false;
  51 + }
  52 +
  53 + /**
  54 + * Get the primary key of the current document subscription object
  55 + *
  56 + * @return integer primary key of document subscription
  57 + */
  58 + function getID() {
  59 + return $this->iID;
  60 + }
  61 +
  62 + /**
  63 + * Get the primary key of the document.
  64 + *
  65 + * @return integer primary key of document
  66 + */
  67 + function getDocumentID() {
  68 + return $this->iDocumentID;
  69 + }
  70 +
  71 + /**
  72 + * Set the document id
  73 + *
  74 + * @param integer new document primary key
  75 + */
  76 + function setDocumentID($iNewValue) {
  77 + $this->iDocumentID = $iNewValue;
  78 + }
  79 +
  80 + /**
  81 + * Get the primary key of the user
  82 + *
  83 + * @return integer primary key of user
  84 + */
  85 + function getUserID() {
  86 + return $this->iUserID;
  87 + }
  88 +
  89 + /**
  90 + * Set the user id
  91 + *
  92 + * @param integer new user primary key
  93 + */
  94 + function setUserID($iNewValue) {
  95 + $this->iUserID = $iNewValue;
  96 + }
  97 +
  98 + /**
  99 + * Get the time this document subscription was alerted
  100 + *
  101 + * @return string the date time the subscription alert was triggered
  102 + */
  103 + function getTimeAlerted() {
  104 + return $this->dTimeAlerted;
  105 + }
  106 +
  107 + /**
  108 + * Get the trigger status of this subscription
  109 + *
  110 + * @return boolean the trigger status of this subscription
  111 + */
  112 + function getIsAlerted() {
  113 + return $this->bIsAlerted;
  114 + }
  115 +
  116 + /**
  117 + * Set the trigger status of the subscription
  118 + *
  119 + * @param boolean new trigger status
  120 + */
  121 + function setIsAlerted($iNewValue) {
  122 + $this->bIsAlerted = $iNewValue;
  123 + }
  124 +
  125 + /**
  126 + * Create the current document subscription in the database
  127 + *
  128 + * @return boolean true and set $this->iID with new primary key, false otherwise and set $_SESSION["errorMessage"]
  129 + */
  130 + function create() {
  131 + global $default, $lang_err_database;
  132 + $lang_err_object_exists;
  133 + //if the object has not already been stored
  134 + if ($this->iID < 0) {
  135 + $sql = $default->db;
  136 + if ($sql->query("INSERT INTO " . $default->owl_document_subscriptions_table . " (user_id, document_id) " .
  137 + "VALUES ($this->iUserID, $this->iDocumentID)")) {
  138 + $this->iID = $sql->insert_id();
  139 + return true;
  140 + } else {
  141 + $_SESSION["errorMessage"] = $lang_err_database;
  142 + }
  143 + } else {
  144 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iID . " table = document_subscriptions";
  145 + }
  146 + return false;
  147 + }
  148 +
  149 + /**
  150 + * Update the current document subscription values in the database
  151 + *
  152 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  153 + */
  154 + function update() {
  155 + global $default, $lang_err_database, $lang_err_object_key;
  156 + //can only update the object if it has already been stored
  157 + if ($this->iID >= 0) {
  158 + $sql = $default->db;
  159 + if ($sql->query("UPDATE " . $default->owl_document_subscriptions_table . " SET " .
  160 + "user_id = $this->iUserID, " .
  161 + "document_id = $this->iDocumentID " .
  162 + "datetime_alerted = '" . getCurrentDateTime() . "', " .
  163 + "is_alerted = $this->bIsAlerted " .
  164 + "WHERE id = " . $this->iID)) {
  165 + return true;
  166 + } else {
  167 + $_SESSION["errorMessage"] = $lang_err_database;
  168 + }
  169 + } else {
  170 + $_SESSION["errorMessage"] = $lang_err_object_key;
  171 + }
  172 + return false;
  173 + }
  174 +
  175 +
  176 + /**
  177 + * Delete the current object from the database
  178 + *
  179 + * @return boolean true and reset id to -1 on successful delete, false otherwise and set $_SESSION["errorMessage"]
  180 + */
  181 + function delete() {
  182 + global $default, $lang_err_database, $lang_err_object_key;
  183 + if ($this->iID >= 0) {
  184 + $sql = $default->db;
  185 + if ($sql->query("DELETE FROM " . $default->owl_document_subscriptions_table . " WHERE id = " . $this->iID)) {
  186 + $this->iID = -1;
  187 + return true;
  188 + } else {
  189 + $_SESSION["errorMessage"] = $lang_err_database;
  190 + }
  191 + } else {
  192 + $_SESSION["errorMessage"] = $lang_err_object_key;
  193 + }
  194 + return false;
  195 +
  196 + }
  197 +
  198 + /**
  199 + * Static function.
  200 + * Given a document subscription primary key will create
  201 + * a document subscription object and populate it with the corresponding
  202 + * database values
  203 + *
  204 + * @param integer primary key of document subscription to get
  205 + *
  206 + * @return object document subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]
  207 + */
  208 + function get($iDocumentSubscriptionID) {
  209 + global $default, $lang_err_object_not_exist, $lang_err_database;
  210 + $sql = $default->db;
  211 + if ($sql->query("SELECT * FROM " . $default->owl_document_subscriptions_table . " WHERE id = " . $iDocumentSubscriptionID)) {
  212 + if ($sql->next_record()) {
  213 + $oDocumentSubscription = & new DocumentSubscription($sql->f("document_id"), $sql->f("user_id"));
  214 + $oDocumentSubscription->iID = $iDocumentSubscriptionID;
  215 + return $oDocumentSubscription;
  216 + } else {
  217 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentSubscriptionID . " table = document_subscriptions";
  218 + }
  219 + } else {
  220 + $_SESSION["errorMessage"] = $lang_err_database;
  221 + }
  222 + return false;
  223 + }
  224 +
  225 + /**
  226 + * Static function.
  227 + * Given a document subscription's values will create
  228 + * a document subscription object and populate it with the corresponding
  229 + * primary key
  230 + *
  231 + * @param integer the document ID
  232 + * @param integer the user ID
  233 + * @return object document subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]
  234 + */
  235 + function getByIDs($iDocumentID, $iUserID) {
  236 + global $default, $lang_err_database, $lang_err_object_not_exist;
  237 + $sql = $default->db;
  238 + if ($sql->query("SELECT * FROM " . $default->owl_document_subscriptions_table . " " .
  239 + "WHERE document_id = $iDocumentID AND user_id = $iUserID")) {
  240 + if ($sql->next_record()) {
  241 + $oDocumentSubscription = & new DocumentSubscription($sql->f("document_id"), $sql->f("user_id"));
  242 + $oDocumentSubscription->iID = $sql->f("id");
  243 + return $oDocumentSubscription;
  244 + } else {
  245 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentSubscriptionID . " table = folder_subscriptions";
  246 + }
  247 + } else {
  248 + $_SESSION["errorMessage"] = $lang_err_database;
  249 + }
  250 + return false;
  251 + }
  252 +
  253 + /**
  254 + * Checks if a given document subscription already exists using the document and user ids
  255 + *
  256 + * @param integer the document ID
  257 + * @param integer the user ID
  258 + * @return true if the document subscription exists, false otherwise
  259 + */
  260 + function exists($iDocumentID, $iUserID) {
  261 + global $default, $lang_err_database;
  262 + $sql = $default->db;
  263 + if ($sql->query("SELECT id FROM " . $default->owl_document_subscriptions_table . " " .
  264 + "WHERE document_id = $iDocumentID AND user_id = $iUserID")) {
  265 + if ($sql->next_record()) {
  266 + return true;
  267 + }
  268 + } else {
  269 + $_SESSION["errorMessage"] = $lang_err_database;
  270 + }
  271 + return false;
41 } 272 }
42 -  
43 - /**  
44 - * Get the primary key of the current document subscription object  
45 - *  
46 - * @return integer primary key of document subscription  
47 - */  
48 - function getID() {  
49 - return $this->iID;  
50 - }  
51 -  
52 - /**  
53 - * Get the primary key of the document.  
54 - *  
55 - * @return integer primary key of document  
56 - */  
57 - function getDocumentID() {  
58 - return $this->iDocumentID;  
59 - }  
60 -  
61 - /**  
62 - * Set the document id  
63 - *  
64 - * @param integer new document primary key  
65 - */  
66 - function setDocumentID($iNewValue) {  
67 - $this->iDocumentID = $iNewValue;  
68 - }  
69 -  
70 - /**  
71 - * Get the primary key of the user  
72 - *  
73 - * @return integer primary key of user  
74 - */  
75 - function getUserID() {  
76 - return $this->iUserID;  
77 - }  
78 -  
79 - /**  
80 - * Set the user id  
81 - *  
82 - * @param integer new user primary key  
83 - */  
84 - function setUserID($iNewValue) {  
85 - $this->iUserID = $iNewValue;  
86 - }  
87 -  
88 - /**  
89 - * Create the current document subscription in the database  
90 - *  
91 - * @return boolean true and set $this->iID with new primary key, false otherwise and set $_SESSION["errorMessage"]  
92 - */  
93 - function create() {  
94 - global $default, $lang_err_database; $lang_err_object_exists;  
95 - //if the object has not already been stored  
96 - if ($this->iID < 0) {  
97 - $sql = $default->db;  
98 - $result = $sql->query("INSERT INTO " . $default->owl_document_subscriptions_table . " (user_id, document_id) " .  
99 - "VALUES ($this->iUserID, $this->iDocumentID)");  
100 - if ($result) {  
101 - $this->iID = $sql->insert_id();  
102 - return true;  
103 - }  
104 - $_SESSION["errorMessage"] = $lang_err_database;  
105 - return false;  
106 - }  
107 - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iID . " table = document_subscriptions";  
108 - return false;  
109 - }  
110 -  
111 - /**  
112 - * Update the current document subscription values in the database  
113 - *  
114 - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]  
115 - */  
116 - function update() {  
117 - global $default, $lang_err_database, $lang_err_object_key;  
118 - //can only update the object if it has already been stored  
119 - if ($this->iID >= 0) {  
120 - $sql = $default->db;  
121 - $result = $sql->query("UPDATE " . $default->owl_document_subscriptions_table . " SET " .  
122 - "user_id = $this->iUserID, " .  
123 - "document_id = $this->iDocumentID " .  
124 - "WHERE id = " . $this->iID);  
125 - if ($result) {  
126 - return true;  
127 - }  
128 - $_SESSION["errorMessage"] = $lang_err_database;  
129 - return false;  
130 - }  
131 - $_SESSION["errorMessage"] = $lang_err_object_key;  
132 - }  
133 -  
134 -  
135 - /**  
136 - * Delete the current object from the database  
137 - *  
138 - * @return boolean true and reset id to -1 on successful delete, false otherwise and set $_SESSION["errorMessage"]  
139 - */  
140 - function delete() {  
141 - global $default, $lang_err_database, $lang_err_object_key;  
142 - if ($this->iID >= 0) {  
143 - $sql = $default->db;  
144 - $result = $sql->query("DELETE FROM " . $default->owl_document_subscriptions_table . " WHERE id = " . $this->iID);  
145 - if ($result) {  
146 - $this->iID = -1;  
147 - return true;  
148 - }  
149 - $_SESSION["errorMessage"] = $lang_err_database;  
150 - return false;  
151 - }  
152 - $_SESSION["errorMessage"] = $lang_err_object_key;  
153 - return false;  
154 -  
155 - }  
156 -  
157 - /**  
158 - * Static function.  
159 - * Given a document subscription primary key will create  
160 - * a document subscription object and populate it with the corresponding  
161 - * database values  
162 - *  
163 - * @param integer primary key of document subscription to get  
164 - *  
165 - * @return object document subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]  
166 - */  
167 - function get($iDocumentSubscriptionID) {  
168 - global $default, $lang_err_object_not_exist;  
169 - $sql = $default->db;  
170 - $sql->query("SELECT * FROM " . $default->owl_document_subscriptions_table . " WHERE id = " . $iDocumentSubscriptionID);  
171 - if ($sql->next_record()) {  
172 - $oDocumentSubscription = & new DocumentSubscription($sql->f("document_id"), $sql->f("user_id"));  
173 - $oDocumentSubscription->iID = $iDocumentSubscriptionID;  
174 - return $oDocumentSubscription;  
175 - }  
176 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentSubscriptionID . " table = document_subscriptions";  
177 - return false;  
178 - }  
179 -  
180 - /**  
181 - * Static function.  
182 - * Given a document subscription's values will create  
183 - * a document subscription object and populate it with the corresponding  
184 - * primary key  
185 - *  
186 - * @param integer the document ID  
187 - * @param integer the user ID  
188 - * @return object document subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]  
189 - */  
190 - function getByIDs($iDocumentID, $iUserID) {  
191 - global $default, $lang_err_object_not_exist;  
192 - $sql = $default->db;  
193 - $sql->query("SELECT * FROM " . $default->owl_document_subscriptions_table . " " .  
194 - "WHERE document_id = $iDocumentID AND user_id = $iUserID");  
195 - if ($sql->next_record()) {  
196 - $oDocumentSubscription = & new DocumentSubscription($sql->f("document_id"), $sql->f("user_id"));  
197 - $oDocumentSubscription->iID = $sql->f("id");  
198 - return $oDocumentSubscription;  
199 - }  
200 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentSubscriptionID . " table = folder_subscriptions";  
201 - return false;  
202 - }  
203 -  
204 - /**  
205 - * Checks if a given document subscription already exists using the document and user ids  
206 - *  
207 - * @param integer the document ID  
208 - * @param integer the user ID  
209 - * @return true if the document subscription exists, false otherwise  
210 - */  
211 - function exists($iDocumentID, $iUserID) {  
212 - global $default;  
213 - $sql = $default->db;  
214 - $sql->query("SELECT id FROM " . $default->owl_document_subscriptions_table . " " .  
215 - "WHERE document_id = $iDocumentID AND user_id = $iUserID");  
216 - if ($sql->next_record()) {  
217 - return true;  
218 - }  
219 - return false;  
220 - }  
221 } 273 }
222 ?> 274 ?>
lib/subscriptions/FolderSubscription.inc
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * @package lib.subscriptions 13 * @package lib.subscriptions
14 */ 14 */
15 class FolderSubscription { 15 class FolderSubscription {
16 - 16 +
17 /** 17 /**
18 * Primary key 18 * Primary key
19 */ 19 */
@@ -26,7 +26,15 @@ class FolderSubscription { @@ -26,7 +26,15 @@ class FolderSubscription {
26 * The ID of the user subscribed to the folder 26 * The ID of the user subscribed to the folder
27 */ 27 */
28 var $iUserID; 28 var $iUserID;
29 - 29 + /**
  30 + * The time this subscription was triggered
  31 + */
  32 + var $dTimeAlerted;
  33 + /**
  34 + * Whether this subscription is triggered
  35 + */
  36 + var $bIsAlerted;
  37 +
30 /** 38 /**
31 * Creates a new folder subscription object 39 * Creates a new folder subscription object
32 * 40 *
@@ -34,191 +42,229 @@ class FolderSubscription { @@ -34,191 +42,229 @@ class FolderSubscription {
34 * @param integer the user ID 42 * @param integer the user ID
35 */ 43 */
36 function FolderSubscription($iFolderID, $iUserID) { 44 function FolderSubscription($iFolderID, $iUserID) {
37 - //id of -1 means that the object has not yet been stored in the database 45 + //id of -1 means that the object has not yet been stored in the database
38 $this->iID = -1; 46 $this->iID = -1;
39 $this->iFolderID = $iFolderID; 47 $this->iFolderID = $iFolderID;
40 $this->iUserID = $iUserID; 48 $this->iUserID = $iUserID;
  49 + $this->dTimeAlerted = getCurrentDateTime();
  50 + $this->bIsAlerted = false;
  51 + }
  52 +
  53 + /**
  54 + * Get the primary key of the current folder subscription object
  55 + *
  56 + * @return integer primary key of folder subscription
  57 + */
  58 + function getID() {
  59 + return $this->iID;
  60 + }
  61 +
  62 + /**
  63 + * Get the primary key of the folder.
  64 + *
  65 + * @return integer primary key of folder
  66 + */
  67 + function getFolderID() {
  68 + return $this->iFolderID;
  69 + }
  70 +
  71 + /**
  72 + * Set the folder id
  73 + *
  74 + * @param integer new folder primary key
  75 + */
  76 + function setFolderID($iNewValue) {
  77 + $this->iFolderID = $iNewValue;
41 } 78 }
42 -  
43 - /**  
44 - * Get the primary key of the current folder subscription object  
45 - *  
46 - * @return integer primary key of folder subscription  
47 - */  
48 - function getID() {  
49 - return $this->iID;  
50 - }  
51 -  
52 - /**  
53 - * Get the primary key of the folder.  
54 - *  
55 - * @return integer primary key of folder  
56 - */  
57 - function getFolderID() {  
58 - return $this->iFolderID;  
59 - }  
60 -  
61 - /**  
62 - * Set the folder id  
63 - *  
64 - * @param integer new folder primary key  
65 - */  
66 - function setFolderID($iNewValue) {  
67 - $this->iFolderID = $iNewValue;  
68 - }  
69 -  
70 - /**  
71 - * Get the primary key of the user  
72 - *  
73 - * @return integer primary key of user  
74 - */  
75 - function getUserID() {  
76 - return $this->iUserID;  
77 - }  
78 -  
79 - /**  
80 - * Set the user id  
81 - *  
82 - * @param integer new user primary key  
83 - */  
84 - function setUserID($iNewValue) {  
85 - $this->iUserID = $iNewValue;  
86 - }  
87 -  
88 - /**  
89 - * Create the current folder subscription in the database  
90 - *  
91 - * @return boolean true and set $this->iID with new primary key, false otherwise and set $_SESSION["errorMessage"]  
92 - */  
93 - function create() {  
94 - global $default, $lang_err_database; $lang_err_object_exists;  
95 - //if the object has not already been stored  
96 - if ($this->iID < 0) {  
97 - $sql = $default->db;  
98 - $result = $sql->query("INSERT INTO " . $default->owl_folder_subscriptions_table . " (user_id, folder_id) " .  
99 - "VALUES ($this->iUserID, $this->iFolderID)");  
100 - if ($result) {  
101 - $this->iID = $sql->insert_id(); 79 +
  80 + /**
  81 + * Get the primary key of the user
  82 + *
  83 + * @return integer primary key of user
  84 + */
  85 + function getUserID() {
  86 + return $this->iUserID;
  87 + }
  88 +
  89 + /**
  90 + * Set the user id
  91 + *
  92 + * @param integer new user primary key
  93 + */
  94 + function setUserID($iNewValue) {
  95 + $this->iUserID = $iNewValue;
  96 + }
  97 +
  98 + /**
  99 + * Get the time this document subscription was alerted
  100 + *
  101 + * @return string the date time the subscription alert was triggered
  102 + */
  103 + function getTimeAlerted() {
  104 + return $this->dTimeAlerted;
  105 + }
  106 +
  107 + /**
  108 + * Get the trigger status of this subscription
  109 + *
  110 + * @return boolean the trigger status of this subscription
  111 + */
  112 + function getIsAlerted() {
  113 + return $this->bIsAlerted;
  114 + }
  115 +
  116 + /**
  117 + * Set the trigger status of the subscription
  118 + *
  119 + * @param boolean new trigger status
  120 + */
  121 + function setIsAlerted($iNewValue) {
  122 + $this->bIsAlerted = $iNewValue;
  123 + }
  124 +
  125 + /**
  126 + * Create the current folder subscription in the database
  127 + *
  128 + * @return boolean true and set $this->iID with new primary key, false otherwise and set $_SESSION["errorMessage"]
  129 + */
  130 + function create() {
  131 + global $default, $lang_err_database;
  132 + $lang_err_object_exists;
  133 + //if the object has not already been stored
  134 + if ($this->iID < 0) {
  135 + $sql = $default->db;
  136 + if ($sql->query("INSERT INTO " . $default->owl_folder_subscriptions_table . " (user_id, folder_id) " .
  137 + "VALUES ($this->iUserID, $this->iFolderID)")) {
  138 + $this->iID = $sql->insert_id();
102 // TODO: now create subscriptions for all the documents in this folder 139 // TODO: now create subscriptions for all the documents in this folder
103 - return true;  
104 - }  
105 - $_SESSION["errorMessage"] = $lang_err_database;  
106 - return false;  
107 - }  
108 - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iID . " table = folder_subscriptions";  
109 - return false;  
110 - }  
111 -  
112 - /**  
113 - * Update the current folder subscription values in the database  
114 - *  
115 - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]  
116 - */  
117 - function update() {  
118 - global $default, $lang_err_database, $lang_err_object_key;  
119 - //can only update the object if it has already been stored  
120 - if ($this->iID >= 0) {  
121 - $sql = $default->db;  
122 - $result = $sql->query("UPDATE " . $default->owl_folder_subscriptions_table . " SET " .  
123 - "user_id = $this->iUserID, " .  
124 - "folder_id = $this->iFolderID " .  
125 - "WHERE id = " . $this->iID);  
126 - if ($result) {  
127 - return true;  
128 - }  
129 - $_SESSION["errorMessage"] = $lang_err_database;  
130 - return false;  
131 - }  
132 - $_SESSION["errorMessage"] = $lang_err_object_key;  
133 - }  
134 -  
135 -  
136 - /**  
137 - * Delete the current object from the database  
138 - *  
139 - * @return boolean true and reset id to -1 on successful delete, false otherwise and set $_SESSION["errorMessage"]  
140 - */  
141 - function delete() {  
142 - global $default, $lang_err_database, $lang_err_object_key;  
143 - if ($this->iID >= 0) {  
144 - $sql = $default->db;  
145 - $result = $sql->query("DELETE FROM " . $default->owl_folder_subscriptions_table . " WHERE id = " . $this->iID);  
146 - if ($result) {  
147 - $this->iID = -1; 140 + return true;
  141 + } else {
  142 + $_SESSION["errorMessage"] = $lang_err_database;
  143 + }
  144 +
  145 + } else {
  146 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iID . " table = folder_subscriptions";
  147 + }
  148 + return false;
  149 + }
  150 +
  151 + /**
  152 + * Update the current folder subscription values in the database
  153 + *
  154 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  155 + */
  156 + function update() {
  157 + global $default, $lang_err_database, $lang_err_object_key;
  158 + //can only update the object if it has already been stored
  159 + if ($this->iID >= 0) {
  160 + $sql = $default->db;
  161 + if ($sql->query("UPDATE " . $default->owl_folder_subscriptions_table . " SET " .
  162 + "user_id = $this->iUserID, " .
  163 + "folder_id = $this->iFolderID, " .
  164 + "datetime_alerted = '" . getCurrentDateTime() . "', " .
  165 + "is_alerted = $this->bIsAlerted " .
  166 + "WHERE id = " . $this->iID)) {
  167 + return true;
  168 + } else {
  169 + $_SESSION["errorMessage"] = $lang_err_database;
  170 + }
  171 + } else {
  172 + $_SESSION["errorMessage"] = $lang_err_object_key;
  173 + }
  174 + return false;
  175 + }
  176 +
  177 +
  178 + /**
  179 + * Delete the current object from the database
  180 + *
  181 + * @return boolean true and reset id to -1 on successful delete, false otherwise and set $_SESSION["errorMessage"]
  182 + */
  183 + function delete() {
  184 + global $default, $lang_err_database, $lang_err_object_key;
  185 + if ($this->iID >= 0) {
  186 + $sql = $default->db;
  187 + if ($sql->query("DELETE FROM " . $default->owl_folder_subscriptions_table . " WHERE id = " . $this->iID)) {
  188 + $this->iID = -1;
148 // TODO: remove all document subscriptions? 189 // TODO: remove all document subscriptions?
149 - return true;  
150 - }  
151 - $_SESSION["errorMessage"] = $lang_err_database;  
152 - return false;  
153 - }  
154 - $_SESSION["errorMessage"] = $lang_err_object_key;  
155 - return false;  
156 -  
157 - }  
158 -  
159 - /**  
160 - * Static function. 190 + return true;
  191 + } else {
  192 + $_SESSION["errorMessage"] = $lang_err_database;
  193 + }
  194 +
  195 + } else {
  196 + $_SESSION["errorMessage"] = $lang_err_object_key;
  197 + }
  198 + return false;
  199 +
  200 + }
  201 +
  202 + /**
  203 + * Static function.
161 * Given a folder subscription primary key will create 204 * Given a folder subscription primary key will create
162 * a folder subscription object and populate it with the corresponding 205 * a folder subscription object and populate it with the corresponding
163 * database values 206 * database values
164 * 207 *
165 * @param integer primary key of folder subscription to get 208 * @param integer primary key of folder subscription to get
166 - *  
167 * @return object folder subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"] 209 * @return object folder subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]
168 */ 210 */
169 - function get($iFolderSubscriptionID) {  
170 - global $default, $lang_err_object_not_exist;  
171 - $sql = $default->db;  
172 - $sql->query("SELECT * FROM " . $default->owl_folder_subscriptions_table . " WHERE id = " . $iFolderSubscriptionID);  
173 - if ($sql->next_record()) {  
174 - $oFolderSubscription = & new FolderSubscription($sql->f("folder_id"), $sql->f("user_id"));  
175 - $oFolderSubscription->iID = $iFolderSubscriptionID;  
176 - return $oFolderSubscription;  
177 - }  
178 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderSubscriptionID . " table = folder_subscriptions";  
179 - return false;  
180 - }  
181 -  
182 - /**  
183 - * Static function.  
184 - * Given a folder subscription's values will create  
185 - * a folder subscription object and populate it with the corresponding  
186 - * primary key  
187 - * 211 + function get($iFolderSubscriptionID) {
  212 + global $default, $lang_err_database, $lang_err_object_not_exist;
  213 + $sql = $default->db;
  214 + if ($sql->query("SELECT * FROM " . $default->owl_folder_subscriptions_table . " WHERE id = " . $iFolderSubscriptionID)) {
  215 + if ($sql->next_record()) {
  216 + $oFolderSubscription = & new FolderSubscription($sql->f("folder_id"), $sql->f("user_id"));
  217 + $oFolderSubscription->iID = $iFolderSubscriptionID;
  218 + return $oFolderSubscription;
  219 + } else {
  220 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderSubscriptionID . " table = folder_subscriptions";
  221 + }
  222 + } else {
  223 + $_SESSION["errorMessage"] = $lang_err_database;
  224 + }
  225 + return false;
  226 + }
  227 +
  228 + /**
  229 + * Static function.
  230 + * Given a folder subscription's values will create
  231 + * a folder subscription object and populate it with the corresponding
  232 + * primary key
  233 + *
188 * @param integer the folder ID 234 * @param integer the folder ID
189 * @param integer the user ID 235 * @param integer the user ID
190 - * @return object folder subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]  
191 - */  
192 - function getByIDs($iFolderID, $iUserID) {  
193 - global $default, $lang_err_object_not_exist;  
194 - $sql = $default->db;  
195 - $sql->query("SELECT * FROM " . $default->owl_folder_subscriptions_table . " " . 236 + * @return object folder subscription object on successful retrieval, false otherwise and set $_SESSION["errorMessage"]
  237 + */
  238 + function getByIDs($iFolderID, $iUserID) {
  239 + global $default, $lang_err_object_not_exist;
  240 + $sql = $default->db;
  241 + $sql->query("SELECT * FROM " . $default->owl_folder_subscriptions_table . " " .
196 "WHERE folder_id = $iFolderID AND user_id = $iUserID"); 242 "WHERE folder_id = $iFolderID AND user_id = $iUserID");
197 - if ($sql->next_record()) {  
198 - $oFolderSubscription = & new FolderSubscription($sql->f("folder_id"), $sql->f("user_id")); 243 + if ($sql->next_record()) {
  244 + $oFolderSubscription = & new FolderSubscription($sql->f("folder_id"), $sql->f("user_id"));
199 $oFolderSubscription->iID = $sql->f("id"); 245 $oFolderSubscription->iID = $sql->f("id");
200 - return $oFolderSubscription;  
201 - }  
202 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderSubscriptionID . " table = folder_subscriptions";  
203 - return false;  
204 - } 246 + return $oFolderSubscription;
  247 + }
  248 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderSubscriptionID . " table = folder_subscriptions";
  249 + return false;
  250 + }
205 251
206 - /** 252 + /**
207 * Checks if a given folder subscription already exists using the folder and user ids 253 * Checks if a given folder subscription already exists using the folder and user ids
208 - * 254 + *
209 * @param integer the folder ID 255 * @param integer the folder ID
210 * @param integer the user ID 256 * @param integer the user ID
211 * @return true if the folder subscription exists, false otherwise 257 * @return true if the folder subscription exists, false otherwise
212 */ 258 */
213 - function exists($iFolderID, $iUserID) {  
214 - global $default;  
215 - $sql = $default->db;  
216 - $sql->query("SELECT id FROM " . $default->owl_folder_subscriptions_table . " " . 259 + function exists($iFolderID, $iUserID) {
  260 + global $default;
  261 + $sql = $default->db;
  262 + $sql->query("SELECT id FROM " . $default->owl_folder_subscriptions_table . " " .
217 "WHERE folder_id = $iFolderID AND user_id = $iUserID"); 263 "WHERE folder_id = $iFolderID AND user_id = $iUserID");
218 - if ($sql->next_record()) {  
219 - return true;  
220 - }  
221 - return false;  
222 - } 264 + if ($sql->next_record()) {
  265 + return true;
  266 + }
  267 + return false;
  268 + }
223 } 269 }
224 ?> 270 ?>