00001 <?php
00002
00015
00016
00017
00018 class NotificationStatusDAO extends DAO {
00019 function &getJournalNotifications($userId) {
00020 $returner = array();
00021
00022 $result = &$this->retrieve(
00023 'SELECT j.journal_id AS journal_id, n.journal_id AS notification FROM journals j LEFT JOIN notification_status n ON j.journal_id = n.journal_id AND n.user_id = ? ORDER BY j.seq',
00024 $userId
00025 );
00026
00027 while (!$result->EOF) {
00028 $row = &$result->GetRowAssoc(false);
00029 $returner[$row['journal_id']] = $row['notification'];
00030 $result->moveNext();
00031 }
00032
00033 $result->Close();
00034 unset($result);
00035
00036 return $returner;
00037 }
00038
00045 function setJournalNotifications($journalId, $userId, $notificationStatus) {
00046 return $this->update(
00047 ($notificationStatus?'INSERT INTO notification_status (user_id, journal_id) VALUES (?, ?)':
00048 'DELETE FROM notification_status WHERE user_id = ? AND journal_id = ?'),
00049 array($userId, $journalId)
00050 );
00051 }
00052
00057 function deleteNotificationStatusByJournal($journalId) {
00058 return $this->update(
00059 'DELETE FROM notification_status WHERE journal_id = ?', $journalId
00060 );
00061 }
00062
00067 function deleteNotificationStatusByUserId($userId) {
00068 return $this->update(
00069 'DELETE FROM notification_status WHERE user_id = ?', $userId
00070 );
00071 }
00072
00078 function &getNotifiableUsersByJournalId($journalId) {
00079 $userDao = &DAORegistry::getDAO('UserDAO');
00080
00081 $result = &$this->retrieve(
00082 'SELECT u.* FROM users u, notification_status n WHERE u.user_id = n.user_id AND n.journal_id = ?',
00083 $journalId
00084 );
00085
00086 $returner = &new DAOResultFactory($result, $userDao, '_returnUserFromRow');
00087 return $returner;
00088 }
00089
00095 function getNotifiableUsersCount($journalId) {
00096 $userDao = &DAORegistry::getDAO('UserDAO');
00097
00098 $result = &$this->retrieve(
00099 'SELECT count(*) FROM notification_status n WHERE n.journal_id = ?',
00100 $journalId
00101 );
00102
00103 $returner = $result->fields[0];
00104
00105 $result->Close();
00106 unset($result);
00107
00108 return $returner;
00109 }
00110 }
00111
00112 ?>