You are here

public function PrivateMessageMapper::getUnreadThreadCount in Private Message 8.2

Same name and namespace in other branches
  1. 8 src/Mapper/PrivateMessageMapper.php \Drupal\private_message\Mapper\PrivateMessageMapper::getUnreadThreadCount()

Get the current user's unread thread count.

Retrieves the number of the current user's threads that have been updated since the last time this number was checked.

Parameters

int $uid: The user ID of the user whose count should be retrieved.

int $lastCheckTimestamp: A UNIX timestamp indicating the time after which to check.

Return value

int The number of threads updated since the given timestamp

Overrides PrivateMessageMapperInterface::getUnreadThreadCount

File

src/Mapper/PrivateMessageMapper.php, line 261

Class

PrivateMessageMapper
Interface for the Private Message Mapper class.

Namespace

Drupal\private_message\Mapper

Code

public function getUnreadThreadCount($uid, $lastCheckTimestamp) {
  return $this->database
    ->query('SELECT COUNT(DISTINCT thread.id) FROM {private_messages} AS message ' . 'JOIN {private_message_thread__private_messages} AS thread_message ' . 'ON message.id = thread_message.private_messages_target_id ' . 'JOIN {private_message_threads} AS thread ' . 'ON thread_message.entity_id = thread.id ' . 'JOIN {pm_thread_history} AS thread_history ' . 'ON thread_history.thread_id = thread.id AND thread_history.uid = :uid ' . 'JOIN {private_message_thread__members} AS thread_member ' . 'ON thread_member.entity_id = thread.id AND thread_member.members_target_id = :uid ' . 'WHERE thread.updated > :timestamp AND message.created > :timestamp AND message.owner <> :uid AND thread_history.access_timestamp < thread.updated ', [
    ':uid' => $uid,
    ':timestamp' => $lastCheckTimestamp,
  ])
    ->fetchField();
}