From 186d7d67a2bf41bdb9ebc29fb872830e305a4938 Mon Sep 17 00:00:00 2001 From: Mathieu RASSE Date: Wed, 19 Jun 2013 11:46:59 +0200 Subject: [PATCH 1/2] MongoDB Support --- Model/Notification.php | 32 ++++++++++++++++++++---------- View/Elements/NotificationItem.ctp | 8 +++++--- webroot/js/notifications.js | 6 ++---- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Model/Notification.php b/Model/Notification.php index 6cf5e8c..79d699e 100644 --- a/Model/Notification.php +++ b/Model/Notification.php @@ -64,24 +64,34 @@ function markAllRead($userId) { function getCount($userId) { $options = array( - 'conditions' => array( - $this->alias . '.is_read' => 0, - $this->alias . '.user_id' => $userId - ) + 'conditions' => array('is_read' => 0), + 'conditions' => array('user_id' => $userId), ); return $this->find('count', $options); } function getList($userId, $limit = 10, $only_new = true) { - $conditions[] = array($this->alias . '.user_id' => $userId); if ($only_new) { - $conditions[] = array($this->alias . '.is_read' => 0); + $options = array( + 'conditions' => array('is_read' => 0), + 'conditions' => array('user_id' => $userId), + 'limit' => $limit, + 'order' => array( + 'is_read' => 'asc', + 'created' => 'desc' + ), + ); + } else { + $options = array( + 'conditions' => array('user_id' => $userId), + 'limit' => $limit, + 'order' => array( + 'is_read' => 'asc', + 'created' => 'desc' + ), + ); } - $options = array( - 'conditions' => $conditions, - 'limit' => $limit, - 'order' => array($this->alias . '.is_read' => 'asc', $this->alias . '.created' => 'desc'), - ); + return $this->find('all', $options); } diff --git a/View/Elements/NotificationItem.ctp b/View/Elements/NotificationItem.ctp index d5b6936..a969f94 100644 --- a/View/Elements/NotificationItem.ctp +++ b/View/Elements/NotificationItem.ctp @@ -1,7 +1,9 @@ Time->timeAgoInWords($notification['Notification']['created']); -$data['sender'] = $notification['Sender']['name']; +$data['time'] = $this->Time->timeAgoInWords($notification['Notification']['created']->sec); +if (isset($notification['Sender']['name'])) { + $data['sender'] = $notification['Sender']['name']; +} $data['message'] = ""; if (isset($notification['Sender']['name'])) { @@ -12,7 +14,7 @@ if (isset($notification['Notification']['message'])) { $data['message'] = "{$data['message']}{$notification['Notification']['message']}"; } -if ($notification['Notification']['is_read']) { +if (isset($notification['Notification']['is_read']) && $notification['Notification']['is_read']) { $data['is_read'] = ''; } else { $data['is_read'] = 'unread'; diff --git a/webroot/js/notifications.js b/webroot/js/notifications.js index 0877c9b..7d90f75 100644 --- a/webroot/js/notifications.js +++ b/webroot/js/notifications.js @@ -40,8 +40,7 @@ function countNotifications(userid) { var base_url = count_url; var url = base_url + "/" + userid; $.ajax({ - url: url, - cache: false + url: url }).done(function(result) { setNotificationCounter(result); }); @@ -66,8 +65,7 @@ function getNotificationList(userid) { var url = list_url + "/" + userid; $.ajax({ - url: url, - cache: false + url: url }).done(function(result) { setNotificationItems(result); From c6b1a88237d1d5008cfa72e692e028ccdc9224f8 Mon Sep 17 00:00:00 2001 From: Mathieu RASSE Date: Wed, 19 Jun 2013 12:55:54 +0200 Subject: [PATCH 2/2] Gestion des senders --- Model/Notification.php | 15 +++++++++++---- View/Elements/NotificationItem.ctp | 13 +++++++------ View/Elements/NotificationList.ctp | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Model/Notification.php b/Model/Notification.php index 79d699e..440dd24 100644 --- a/Model/Notification.php +++ b/Model/Notification.php @@ -1,6 +1,6 @@ find('all', $options); + $newNotifs = $this->find('all', $options); + $notifications = array(); + foreach ($newNotifs as $notification) { + if ($notification['Notification']['sender_id'] != null) { + $notification['Sender'] = $this->User->read(null, $notification['Notification']['sender_id']); + + } + $notifications[] = $notification; + } + return $notifications; } } diff --git a/View/Elements/NotificationItem.ctp b/View/Elements/NotificationItem.ctp index a969f94..df3ce37 100644 --- a/View/Elements/NotificationItem.ctp +++ b/View/Elements/NotificationItem.ctp @@ -1,13 +1,14 @@ Time->timeAgoInWords($notification['Notification']['created']->sec); -if (isset($notification['Sender']['name'])) { - $data['sender'] = $notification['Sender']['name']; + +if (isset($notification['Sender']['User']['username'])) { + $data['sender'] = $notification['Sender']['User']['username']; } $data['message'] = ""; -if (isset($notification['Sender']['name'])) { - $data['message'] = "{$notification['Sender']['name']} "; +if (isset($notification['Sender']['User']['username'])) { + $data['message'] = "{$notification['Sender']['User']['username']} "; } if (isset($notification['Notification']['message'])) { @@ -20,8 +21,8 @@ if (isset($notification['Notification']['is_read']) && $notification['Notificati $data['is_read'] = 'unread'; } -if (isset($notification['Sender']['email'])) { - $email = md5(strtolower(trim($notification['Sender']['email']))); +if (isset($notification['Sender']['User']['email'])) { + $email = md5(strtolower(trim($notification['Sender']['User']['email']))); } else { $email = md5(strtolower(trim(AuthComponent::user('email')))); } diff --git a/View/Elements/NotificationList.ctp b/View/Elements/NotificationList.ctp index bb32758..e17ce91 100644 --- a/View/Elements/NotificationList.ctp +++ b/View/Elements/NotificationList.ctp @@ -6,7 +6,7 @@ ?>
  • -

    No notifications

    +

    Aucune notification