diff --git a/Model/Notification.php b/Model/Notification.php index 6cf5e8c..440dd24 100644 --- a/Model/Notification.php +++ b/Model/Notification.php @@ -1,6 +1,6 @@ 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); + $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 d5b6936..df3ce37 100644 --- a/View/Elements/NotificationItem.ctp +++ b/View/Elements/NotificationItem.ctp @@ -1,25 +1,28 @@ Time->timeAgoInWords($notification['Notification']['created']); -$data['sender'] = $notification['Sender']['name']; +$data['time'] = $this->Time->timeAgoInWords($notification['Notification']['created']->sec); + +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'])) { $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'; } -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

  • 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);