We are moving to Git Issues for bug tracking in future releases. During transition, content will be in both tools. If you'd like to file a new bug, please create an issue.

View | Details | Raw Unified | Return to bug 3922 | Differences between
and this patch

Collapse All | Expand All

(-)classes/core/PKPApplication.inc.php (+2 lines)
 Lines 186-191    Link Here 
186
			'CurrencyDAO' => 'currency.CurrencyDAO',
186
			'CurrencyDAO' => 'currency.CurrencyDAO',
187
			'HelpTocDAO' => 'help.HelpTocDAO',
187
			'HelpTocDAO' => 'help.HelpTocDAO',
188
			'HelpTopicDAO' => 'help.HelpTopicDAO',
188
			'HelpTopicDAO' => 'help.HelpTopicDAO',
189
			'NotificationDAO' => 'notification.NotificationDAO',
190
			'NotificationSettingsDAO' => 'notification.NotificationSettingsDAO',
189
			'ScheduledTaskDAO' => 'scheduledTask.ScheduledTaskDAO',
191
			'ScheduledTaskDAO' => 'scheduledTask.ScheduledTaskDAO',
190
			'SessionDAO' => 'session.SessionDAO',
192
			'SessionDAO' => 'session.SessionDAO',
191
			'SiteDAO' => 'site.SiteDAO',
193
			'SiteDAO' => 'site.SiteDAO',
(-)classes/notification/NotificationDAO.inc.php (+325 lines)
Added Link Here 
1
<?php
2
3
/**
4
 * @file classes/notification/NotificationDAO.inc.php
5
 *
6
 * Copyright (c) 2003-2008 John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
9
 * @class NotificationDAO
10
 * @ingroup notification
11
 * @see Notification
12
 *
13
 * @brief Operations for retrieving and modifying Notification objects.
14
 */
15
16
// $Id: NotificationDAO.inc.php,v 1.19 2008/11/05 00:46:39 mcrider Exp $
17
18
import('notification.Notification');
19
20
class NotificationDAO extends DAO {
21
	/**
22
	 * Constructor.
23
	 */
24
	function NotificationDAO() {
25
		parent::DAO();
26
	}
27
	
28
	/**
29
	 * Retrieve Notification by notification id
30
	 * @param $notificationId int
31
	 * @return Notification object
32
	 */
33
	function &getNotificationById($notificationId) {
34
		$result =& $this->retrieve(
35
			'SELECT * FROM notifications WHERE notification_id = ?', (int) $notificationId
36
		);
37
	
38
		$notification =& $this->_returnNotificationFromRow($result->GetRowAssoc(false));
39
	
40
		$result->Close();
41
		unset($result);
42
	
43
		return $notification;
44
	}	
45
	
46
	/**
47
	 * Retrieve Notifications by user id
48
	 * @param $userId int
49
	 * @return Notification objects array
50
	 */
51
	function &getNotificationsByUserId($userId) {
52
		$application =& PKPApplication::getApplication();
53
		$productName = $application->getName();
54
		$context =& Request::getContext();
55
		$contextId = $context->getId();
56
		
57
		$notifications = array();
58
	
59
		$result =& $this->retrieve(
60
			'SELECT * FROM notifications WHERE user_id = ? AND product = ? AND context = ? ORDER BY date_created DESC',	
61
			array((int) $userId, $productName, (int) $contextId)
62
		);
63
	
64
		$returner = new DAOResultFactory($result, $this, '_returnNotificationFromRow');
65
		
66
		return $returner;
67
	}
68
	
69
	/**
70
	 * Retrieve Notifications by notification id
71
	 * @param $notificationId int
72
	 * @return boolean
73
	 */
74
	function setDateRead($notificationId) {
75
		$returner = $this->update(
76
			sprintf('UPDATE notifications
77
				SET date_read = %s
78
				WHERE notification_id = ?',
79
				$this->datetimeToDB(date('Y-m-d H:i:s'))),
80
			(int) $notificationId
81
		);
82
83
		return $returner;
84
	}
85
	
86
	/**
87
	 * Creates and returns an notification object from a row
88
	 * @param $row array
89
	 * @return Notification object
90
	 */
91
	function &_returnNotificationFromRow($row) {
92
		$notification = new Notification();
93
		$notification->setNotificationId($row['notification_id']);
94
		$notification->setUserId($row['user_id']);
95
		$notification->setDateCreated($row['date_created']);
96
		$notification->setDateRead($row['date_read']);
97
		$notification->setContents($row['contents']);
98
		$notification->setParam($row['param']);
99
		$notification->setLocation($row['location']);
100
		$notification->setIsLocalized($row['is_localized']);
101
		$notification->setContext($row['context']);
102
		$notification->setAssocType($row['assoc_type']);
103
		
104
		HookRegistry::call('NotificationDAO::_returnNotificationFromRow', array(&$notification, &$row));
105
	
106
		return $notification;
107
	}
108
	
109
	/**
110
	 * Inserts a new notification into notifications table
111
	 * @param Notification object
112
	 * @return int Notification Id 
113
	 */
114
	function insertNotification(&$notification) {
115
		$application =& PKPApplication::getApplication();
116
		$productName = $application->getName();
117
		
118
		if ($this->notificationAlreadyExists($notification)) {
119
			return 0;
120
		}
121
		
122
		$notificationSettingsDao =& DAORegistry::getDAO('NotificationSettingsDAO');
123
		$notificationSettings = $notificationSettingsDao->getNotificationSettings($notification->getUserId());
124
		$notificationEmailSettings = $notificationSettingsDao->getNotificationEmailSettings($notification->getUserId());
125
		
126
		if(in_array($notification->getAssocType(), $notificationEmailSettings)) {
127
			$this->sendNotificationEmail($notification);
128
		}
129
		
130
		if(!in_array($notification->getAssocType(), $notificationSettings)) {
131
			$this->update(
132
				sprintf('INSERT INTO notifications
133
					(user_id, date_created, contents, param, location, is_localized, context, product, assoc_type)
134
					VALUES
135
					(?, %s, ?, ?, ?, ?, ?, ?, ?)',
136
					$this->datetimeToDB(date('Y-m-d H:i:s'))),
137
				array(
138
					(int) $notification->getUserId(),
139
					$notification->getContents(),
140
					$notification->getParam(),
141
					$notification->getLocation(),
142
					(int) $notification->getIsLocalized(),
143
					(int) $notification->getContext(),
144
					$productName,
145
					(int) $notification->getAssocType(),
146
				)
147
			);
148
		
149
			$notification->setNotificationId($this->getInsertNotificationId());
150
			return $notification->getNotificationId();
151
		} else return 0;
152
	}
153
	
154
	/**
155
	 * Delete Notification by notification id
156
	 * @param $notificationId int
157
	 * @return boolean
158
	 */
159
	function deleteNotificationById($notificationId, $userId = null) {
160
		$params = array($notificationId);
161
		if (isset($userId)) $params[] = $userId;
162
	
163
		return $this->update('DELETE FROM notifications WHERE notification_id = ?' . (isset($userId) ? ' AND user_id = ?' : ''), 
164
			$params
165
		);
166
	}	
167
168
	/**
169
	 * Check if the same notification was added in the last hour
170
	 * Will prevent multiple notifications to show up in a user's feed e.g.
171
	 * if a user edits a submission multiple times in a short time span
172
	 * @param notification object
173
	 * @return boolean
174
	 */
175
	function notificationAlreadyExists(&$notification) {
176
		$application =& PKPApplication::getApplication();
177
		$productName = $application->getName();
178
		$context =& Request::getContext();
179
		$contextId = $context->getId();
180
			
181
		$result =& $this->retrieve(
182
			'SELECT date_created FROM notifications WHERE user_id = ? AND contents = ? AND product = ? AND assoc_type = ? AND context = ?',
183
			array(
184
					(int) $notification->getUserId(),
185
					$notification->getContents(),
186
					$productName,
187
					(int) $notification->getAssocType(),
188
					(int) $contextId
189
				)
190
		);
191
		
192
		$date = isset($result->fields[0]) ? $result->fields[0] : 0;
193
		
194
		if ($date == 0) {
195
			return false;
196
		} else {
197
			$timeDiff = strtotime($date) - time();
198
			if ($timeDiff < 3600) { // 1 hour (in seconds)
199
				return true;
200
			} else return false;
201
		}
202
	}
203
204
	/**
205
	 * Get the ID of the last inserted notification
206
	 * @return int
207
	 */
208
	function getInsertNotificationId() {
209
		return $this->getInsertId('notifications', 'notification_id');
210
	}
211
	
212
	/**
213
	 * Get the number of unread messages for a user
214
	 * @param $userId int
215
	 * @return int
216
	 */
217
	function getUnreadNotificationCount($userId) {
218
		$application =& PKPApplication::getApplication();
219
		$productName = $application->getName();
220
		$context =& Request::getContext();
221
		$contextId = $context->getId();
222
		
223
		$result =& $this->retrieve(
224
			'SELECT count(*) FROM notifications WHERE user_id = ? AND date_read IS NULL AND product = ? AND context = ?',
225
			array((int) $userId, $productName, (int) $contextId)
226
		);
227
228
		$returner = $result->fields[0];
229
230
		$result->Close();
231
		unset($result);
232
233
		return $returner;
234
	}
235
	
236
	/**
237
	 * Get the number of read messages for a user
238
	 * @param $userId int
239
	 * @return int
240
	 */
241
	function getReadNotificationCount($userId) {
242
		$application =& PKPApplication::getApplication();
243
		$productName = $application->getName();
244
		$context =& Request::getContext();
245
		$contextId = $context->getId();
246
		
247
		$result =& $this->retrieve(
248
			'SELECT count(*) FROM notifications WHERE user_id = ? AND date_read IS NOT NULL AND product = ? AND context = ?',
249
			array((int) $userId, $productName, (int) $contextId)
250
		);
251
252
		$returner = $result->fields[0];
253
254
		$result->Close();
255
		unset($result);
256
257
		return $returner;
258
	}
259
260
	/**
261
	 * Send an email to a user regarding the notification
262
	 * @param $notification object Notification
263
	 */
264
	function sendNotificationEmail($notification) {
265
		$userId = $notification->getUserId();
266
		$userDao =& DAORegistry::getDAO('UserDAO');
267
		$user = $userDao->getUser($userId);
268
		
269
		if ($notification->getIsLocalized()) {
270
			$params = array('param' => $notification->getParam());
271
			$notificationContents = Locale::translate($notification->getContents(), $params);
272
		} else {
273
			$notificationContents = $notification->getContents();
274
		}
275
		
276
		import('mail.MailTemplate');
277
		$site =& Request::getSite();
278
		$mail = new MailTemplate('NOTIFICATION');
279
		$mail->setFrom($site->getSiteContactEmail(), $site->getSiteContactName());
280
		$mail->assignParams(array(
281
			'notificationContents' => $notificationContents,
282
			'url' => $notification->getLocation(),
283
			'siteTitle' => $site->getSiteTitle()
284
		));
285
		$mail->addRecipient($user->getEmail(), $user->getFullName());
286
		$mail->send();
287
	}	
288
	
289
	/**
290
	 * Send an update to all users on the mailing list
291
	 * @param $notification object Notification
292
	 */
293
	function sendToMailingList($notification) {
294
		$notificationSettingsDao =& DAORegistry::getDAO('NotificationSettingsDAO');
295
		$mailList = $notificationSettingsDao->getMailList();
296
		
297
		foreach ($mailList as $email) {
298
			if ($notification->getIsLocalized()) {
299
				$params = array('param' => $notification->getParam());
300
				$notificationContents = Locale::translate($notification->getContents(), $params);
301
			} else {
302
				$notificationContents = $notification->getContents();
303
			}
304
			
305
			import('mail.MailTemplate');
306
			$journal =& Request::getJournal();
307
			$site =& Request::getSite();
308
			
309
			$mail = new MailTemplate('NOTIFICATION_MAILLIST');
310
			$mail->setFrom($site->getSiteContactEmail(), $site->getSiteContactName());
311
			$mail->assignParams(array(
312
				'notificationContents' => $notificationContents,
313
				'url' => $notification->getLocation(),
314
				'siteTitle' => $journal->getJournalTitle(),
315
				'unsubscribeLink' => Request::url(null, 'notification', 'unsubscribeMailList')
316
			));
317
			$mail->addRecipient($email);
318
			$mail->send();
319
		}
320
		
321
		
322
	}	
323
}
324
325
?>
(-)classes/notification/NotificationSettingsDAO.inc.php (+453 lines)
Added Link Here 
1
<?php
2
3
/**
4
 * @file classes/notification/NotificationSettingsDAODAO.inc.php
5
 *
6
 * Copyright (c) 2003-2008 John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
9
 * @class NotificationSettingsDAO
10
 * @ingroup notification
11
 * @see Notification
12
 *
13
 * @brief Operations for retrieving and modifying user's notification settings.
14
 */
15
16
// $Id: NotificationSettingsDAO.inc.php,v 1.19 2008/11/05 00:46:39 mcrider Exp $
17
18
class NotificationSettingsDAO extends DAO {
19
	/**
20
	 * Constructor.
21
	 */
22
	function NotificationSettingsDAO() {
23
		parent::DAO();
24
	}
25
	
26
	/**
27
	 * Retrieve Notifications settings by user id
28
	 * Returns an array of notification types that the user
29
	 * does NOT want to be notified of
30
	 * @param $userId int
31
	 * @return array
32
	 */
33
	function &getNotificationSettings($userId) {
34
		$application =& PKPApplication::getApplication();
35
		$productName = $application->getName();
36
		$context =& Request::getContext();
37
		$contextId = $context->getId();
38
		
39
		$notificationSettings = array();
40
	
41
		$result =& $this->retrieve(
42
			'SELECT setting_value FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
43
				array((int) $userId, $productName, 'notify', (int) $contextId)
44
		);
45
	
46
		while (!$result->EOF) {
47
			$row = $result->GetRowAssoc(false);
48
			$notificationSettings[] = (int) $row['setting_value'];
49
			$result->moveNext();
50
		}
51
52
		$result->Close();
53
		unset($result);
54
		
55
		return $notificationSettings;
56
	}
57
	
58
	/**
59
	 * Retrieve Notifications email settings by user id
60
	 * Returns an array of notification types that the user
61
	 * DOES want to be emailed about
62
	 * @param $userId int
63
	 * @return array
64
	 */
65
	function &getNotificationEmailSettings($userId) {
66
		$application =& PKPApplication::getApplication();
67
		$productName = $application->getName();
68
		$context =& Request::getContext();
69
		$contextId = $context->getId();
70
		
71
		$emailSettings = array();
72
	
73
		$result =& $this->retrieve(
74
			'SELECT setting_value FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
75
				array((int) $userId, $productName, 'email', (int) $contextId)
76
		);
77
	
78
		while (!$result->EOF) {
79
			$row = $result->GetRowAssoc(false);
80
			$emailSettings[] = (int) $row['setting_value'];
81
			$result->moveNext();
82
		}
83
84
		$result->Close();
85
		unset($result);
86
		
87
		return $emailSettings;
88
	}
89
	
90
	/**
91
	 * Update a user's notification settings
92
	 * @param $notificationSettings array
93
	 * @param $userId int
94
	 */
95
	function updateNotificationSettings($notificationSettings, $userId) {
96
		$application =& PKPApplication::getApplication();
97
		$productName = $application->getName();
98
		$context =& Request::getContext();
99
		$contextId = $context->getId();		
100
		
101
		// Delete old settings first, then insert new settings
102
		$this->update('DELETE FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
103
			array((int) $userId, $productName, 'notify', (int) $contextId));
104
	
105
		for ($i=0; $i<count($notificationSettings); $i++) {
106
			$this->update(
107
				'INSERT INTO notification_settings
108
					(setting_name, setting_value, user_id, product, context)
109
					VALUES
110
					(?, ?, ?, ?, ?)',
111
				array(
112
					"notify",
113
					$notificationSettings[$i],
114
					(int) $userId,
115
					$productName,
116
					(int) $contextId
117
				)
118
			);
119
		}
120
	}
121
	
122
	/**
123
	 * Update a user's notification email settings
124
	 * @param $notificationEmailSettings array
125
	 * @param $userId int
126
	 */
127
	function updateNotificationEmailSettings($emailSettings, $userId) {
128
		$application =& PKPApplication::getApplication();
129
		$productName = $application->getName();
130
		$context =& Request::getContext();
131
		$contextId = $context->getId();
132
		
133
		// Delete old settings first, then insert new settings
134
		$this->update('DELETE FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
135
			array($userId, $productName, 'email', $contextId));
136
	
137
		for ($i=0; $i<count($emailSettings); $i++) {
138
			$this->update(
139
				'INSERT INTO notification_settings
140
					(setting_name, setting_value, user_id, product, context)
141
					VALUES
142
					(?, ?, ?, ?, ?)',
143
				array(
144
					"email",
145
					$emailSettings[$i],
146
					(int) $userId,
147
					$productName,
148
					(int) $contextId
149
				)
150
			);
151
		}
152
	}
153
	
154
	/**
155
	 * Gets a user id by an RSS token value
156
	 * @param $token int
157
	 * @return int
158
	 */
159
	function getUserIdByRSSToken($token) {
160
		$application =& PKPApplication::getApplication();
161
		$productName = $application->getName();
162
		$context =& Request::getContext();
163
		$contextId = $context->getId();
164
	
165
		$result =& $this->retrieve(
166
			'SELECT user_id FROM notification_settings WHERE setting_value = ? AND setting_name = ? AND product = ? AND context = ?',
167
				array($token, 'token', $productName, (int) $contextId)
168
		);
169
170
		$row = $result->GetRowAssoc(false);
171
		$userId = $row['user_id'];
172
173
		$result->Close();
174
		unset($result);
175
		
176
		return $userId;
177
	}
178
179
	/**
180
	 * Gets an RSS token for a user id
181
	 * @param $userId int
182
	 * @return int
183
	 */
184
	function getRSSTokenByUserId($userId) {
185
		$application =& PKPApplication::getApplication();
186
		$productName = $application->getName();
187
		$context =& Request::getContext();
188
		$contextId = $context->getId();
189
	
190
		$result =& $this->retrieve(
191
			'SELECT setting_value FROM notification_settings WHERE user_id = ? AND setting_name = ? AND product = ? AND context = ?',
192
				array((int) $userId, 'token', $productName, (int) $contextId)
193
		);
194
195
		$row = $result->GetRowAssoc(false);
196
		$userId = $row['setting_value'];
197
198
		$result->Close();
199
		unset($result);
200
		
201
		return $userId;
202
	}
203
204
	/**
205
	 * Generates and inserts a new token for a user's RSS feed
206
	 * @param $userId int
207
	 * @return int
208
	 */
209
	function insertNewRSSToken($userId) {
210
		$application =& PKPApplication::getApplication();
211
		$productName = $application->getName();
212
		$context =& Request::getContext();
213
		$contextId = $context->getId();
214
		
215
		$token = uniqid(rand());
216
	
217
		$this->update(
218
			'INSERT INTO notification_settings
219
				(setting_name, setting_value, user_id, product, context)
220
				VALUES
221
				(?, ?, ?, ?, ?)',
222
			array(
223
				'token',
224
				$token,
225
				(int) $userId,
226
				$productName,
227
				(int) $contextId
228
			)
229
		);
230
231
		return $token;
232
	}
233
	
234
	/**
235
	 * Generates an access key for the guest user and adds them to the settings table
236
	 * @param $userId int
237
	 * @return int
238
	 */
239
	function subscribeGuest($email) {
240
		$application =& PKPApplication::getApplication();
241
		$productName = $application->getName();
242
		$context =& Request::getContext();
243
		$contextId = $context->getId();
244
245
		// Check that the email doesn't already exist
246
		$result =& $this->retrieve(
247
			'SELECT * FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
248
			array(
249
				'mailList',
250
				$email,
251
				$productName,
252
				(int) $contextId
253
			)
254
		);
255
256
		if ($result->RecordCount() != 0) {
257
			return false;
258
		} else {		
259
			$this->update(
260
				'INSERT INTO notification_settings
261
					(setting_name, setting_value, user_id, product, context)
262
					VALUES
263
					(?, ?, ?, ?, ?)',
264
				array(
265
					'mailListUncomfirmed',
266
					$email,
267
					0,
268
					$productName,
269
					(int) $contextId
270
				)
271
			);
272
		}	
273
274
		// Get assoc_id into notification_settings table, also used as user_id for access key
275
		$assocId = $this->getInsertNotificationSettingId();
276
277
		import('security.AccessKeyManager');
278
		$accessKeyManager = new AccessKeyManager();
279
280
		$password = $accessKeyManager->createKey('MailListContext', $assocId, $assocId, 10000);
281
		return $password;
282
	}
283
	
284
	
285
	
286
	/**
287
	 * Removes an email address and associated access key from email notifications
288
	 * @param $email string
289
	 * @param $password string
290
	 * @return boolean
291
	 */
292
	function unsubscribeGuest($email, $password) {
293
		$application =& PKPApplication::getApplication();
294
		$productName = $application->getName();
295
		$context =& Request::getContext();
296
		$contextId = $context->getId();
297
		
298
		$result =& $this->retrieve(
299
			'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND product = ? AND context = ?',
300
			array(
301
				'mailList',
302
				$productName,
303
				(int) $contextId
304
			)
305
		);
306
307
		$row = $result->GetRowAssoc(false);
308
		$userId = (int) $row['setting_id'];
309
310
		$result->Close();
311
		unset($result);
312
313
		import('security.AccessKeyManager');
314
		$accessKeyManager = new AccessKeyManager();
315
		$accessKeyHash = AccessKeyManager::generateKeyHash($password);
316
		$accessKey = $accessKeyManager->validateKey('MailListContext', $userId, $accessKeyHash);
317
318
		if ($accessKey) {
319
			$this->update(
320
				'DELETE FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
321
				array(
322
					'mailList',
323
					$email,
324
					$productName,
325
					(int) $contextId
326
				)
327
			);
328
			$accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
329
			$accessKeyDao->deleteAccessKey($accessKey);
330
			return true;
331
		} else return false;	
332
	}
333
	
334
	/**
335
	 * Gets the setting id for a maillist member (to access the accompanying access key)
336
	 * @return array
337
	 */
338
	function getMailListSettingId($email, $settingName = 'mailListUncomfirmed') {
339
		$application =& PKPApplication::getApplication();
340
		$productName = $application->getName();
341
		$context =& Request::getContext();
342
		$contextId = $context->getId();	
343
		
344
		$result =& $this->retrieve(
345
			'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
346
			array(
347
				$settingName,
348
				$email,
349
				$productName,
350
				(int) $contextId
351
			)
352
		);
353
		
354
		$row = $result->GetRowAssoc(false);
355
		$settingId = (int) $row['setting_id'];
356
		
357
		return $settingId;
358
	}
359
	
360
	/**
361
	 * Update the notification settings table to confirm the mailing list subscription
362
	 * @return boolean
363
	 */
364
	function confirmMailListSubscription($settingId) {
365
		return $this->update(
366
			'UPDATE notification_settings SET setting_name = ? WHERE setting_id = ?',
367
			array('mailList', (int) $settingId)
368
		);
369
	}
370
371
	/**
372
	 * Gets a list of email addresses of users subscribed to the mailing list
373
	 * @return array
374
	 */
375
	function getMailList() {
376
		$application =& PKPApplication::getApplication();
377
		$productName = $application->getName();
378
		$context =& Request::getContext();
379
		$contextId = $context->getId();
380
		$mailList = array();
381
		
382
		$result =& $this->retrieve(
383
			'SELECT setting_value FROM notification_settings WHERE setting_name = ? AND product = ? AND context = ?',
384
			array(
385
				'mailList',
386
				$productName,
387
				(int) $contextId
388
			)
389
		);
390
391
		while (!$result->EOF) {
392
			$row = $result->GetRowAssoc(false);
393
			$mailList[] = $row['setting_value'];
394
			$result->moveNext();
395
		}
396
397
		$result->Close();
398
		unset($result);
399
		
400
		return $mailList;
401
	}
402
403
	/**
404
	 * Generates and inserts a new password for a mailing list user
405
	 * @param $email string
406
	 * @return string
407
	 */
408
	function resetPassword($email) {
409
		$application =& PKPApplication::getApplication();
410
		$productName = $application->getName();
411
		$context =& Request::getContext();
412
		$contextId = $context->getId();
413
		
414
		$result =& $this->retrieve(
415
			'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
416
			array(
417
				'mailList',
418
				$email,
419
				$productName,
420
				(int) $contextId
421
			)
422
		);
423
424
		$row = $result->GetRowAssoc(false);
425
		$settingId = $row['setting_id'];
426
427
		$result->Close();
428
		unset($result);
429
430
		$accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
431
		$accessKey = $accessKeyDao->getAccessKeyByUserId('MailListContext', $settingId);
432
433
		if ($accessKey) {
434
			$key = Validation::generatePassword();
435
			$accessKey->setKeyHash(md5($key));
436
			
437
			$accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
438
			$accessKeyDao->updateAccessKey($accessKey);
439
			return $key;
440
		} else return false;
441
	}
442
443
	/**
444
	 * Get the ID of the last inserted notification
445
	 * @return int
446
	 */
447
	function getInsertNotificationSettingId() {
448
		return $this->getInsertId('notification_settings', 'setting_id');
449
	}
450
451
}
452
453
?>
(-)classes/notification/PKPNotification.inc.php (+49 lines)
Added Link Here 
1
<?php
2
3
/**
4
 * @file classes/notification/Notification.inc.php
5
 *
6
 * Copyright (c) 2003-2008 John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
9
 * @class Notification
10
 * @ingroup notification
11
 * @see NotificationDAO
12
 * @brief Class for Notification.
13
 */
14
15
// $Id: Notification.inc.php,v 1.10 2008/07/01 01:16:09 asmecher Exp $
16
17
import('notification.NotificationDAO');
18
19
class PKPNotification extends DataObject {
20
21
	/**
22
	 * Constructor.
23
	 */
24
	function PKPNotification() {
25
		parent::DataObject();
26
	}
27
	
28
	/**
29
	 * Create a new notification with the specified arguments and insert into DB
30
	 * This is a static method
31
	 * @param $userId int
32
	 * @param $contents string
33
	 * @param $param string
34
	 * @param $location string
35
	 * @param $isLocalized bool
36
	 * @param $assocType int
37
	 * @param $assocId int
38
	 * @return Notification object
39
	 */
40
	function createNotification($userId, $contents, $param, $location, $isLocalized, $assocType) {
41
		$notification = new Notification();
42
		$context =& Request::getContext();
43
		$contextId = $context->getId();
44
45
		$notification->setUserId($userId);
46
		$notification->setContents($contents);
47
		$notification->setParam($param);
48
		$notification->setLocation($location);
49
		$notification->setIsLoca

Return to bug 3922