|
@@ -21,18 +21,24 @@ class MessageManager
|
|
|
public static function getCountNewMessages()
|
|
|
{
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE);
|
|
|
- if (!api_get_user_id()) {
|
|
|
+ $userId = api_get_user_id();
|
|
|
+ if (empty($userId)) {
|
|
|
return false;
|
|
|
}
|
|
|
- $sql = "SELECT COUNT(id) as count
|
|
|
- FROM $table
|
|
|
- WHERE
|
|
|
- user_receiver_id=" . api_get_user_id() . " AND
|
|
|
- msg_status=" . MESSAGE_STATUS_UNREAD;
|
|
|
- $result = Database::query($sql);
|
|
|
- $row = Database::fetch_assoc($result);
|
|
|
|
|
|
- return $row['count'];
|
|
|
+ static $count;
|
|
|
+ if (!isset($count)) {
|
|
|
+ $sql = "SELECT COUNT(id) as count
|
|
|
+ FROM $table
|
|
|
+ WHERE
|
|
|
+ user_receiver_id=".api_get_user_id()." AND
|
|
|
+ msg_status = ".MESSAGE_STATUS_UNREAD;
|
|
|
+ $result = Database::query($sql);
|
|
|
+ $row = Database::fetch_assoc($result);
|
|
|
+ $count = $row['count'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $count;
|
|
|
}
|
|
|
|
|
|
/**
|