You are here

public function PrivateMessageMapper::getFirstThreadIdForUser in Private Message 8.2

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

Retrieve the ID of the most recently updated thread for the given user.

Parameters

\Drupal\user\UserInterface $user: The user whose most recently updated thread should be retrieved.

Return value

int|bool The ID of the most recently updated thread the user is a member of if one exists, or FALSE if one doesn't.

Overrides PrivateMessageMapperInterface::getFirstThreadIdForUser

File

src/Mapper/PrivateMessageMapper.php, line 81

Class

PrivateMessageMapper
Interface for the Private Message Mapper class.

Namespace

Drupal\private_message\Mapper

Code

public function getFirstThreadIdForUser(UserInterface $user) {
  return $this->database
    ->queryRange('SELECT thread.id ' . 'FROM {private_message_threads} AS thread ' . 'JOIN {pm_thread_history} pm_thread_history ' . 'ON pm_thread_history.thread_id = thread.id AND pm_thread_history.uid = :history_uid ' . 'JOIN {private_message_thread__members} AS thread_member ' . 'ON thread_member.entity_id = thread.id AND thread_member.members_target_id = :uid ' . 'JOIN {private_message_thread__private_messages} AS thread_messages ' . 'ON thread_messages.entity_id = thread.id ' . 'JOIN {private_messages} AS messages ' . 'ON messages.id = thread_messages.private_messages_target_id ' . 'WHERE pm_thread_history.delete_timestamp <= messages.created ' . 'ORDER BY thread.updated DESC', 0, 1, [
    ':uid' => $user
      ->id(),
    ':history_uid' => $user
      ->id(),
  ])
    ->fetchField();
}