You are here

public function PrivateMessageMapper::checkForNextThread in Private Message 8

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

Check if a thread exists after with an ID greater than the given thread ID.

Parameters

\Drupal\user\UserInterface $user: The user for whom to check.

int $timestamp: The timestamp to check against.

Return value

bool TRUE if a previous thread exists, FALSE if one doesn't.

Overrides PrivateMessageMapperInterface::checkForNextThread

File

src/Mapper/PrivateMessageMapper.php, line 134

Class

PrivateMessageMapper
Interface for the Private Message Mapper class.

Namespace

Drupal\private_message\Mapper

Code

public function checkForNextThread(UserInterface $user, $timestamp) {
  $query = 'SELECT DISTINCT(thread.id) ' . 'FROM {private_message_threads} AS thread ' . 'JOIN {private_message_thread__members} AS member ' . 'ON member.entity_id = thread.id AND 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 ' . 'JOIN {private_message_thread__last_delete_time} AS message_delete_time ' . 'ON message_delete_time.entity_id = thread.id ' . 'JOIN {pm_thread_delete_time} as owner_delete_time ' . 'ON owner_delete_time.id = message_delete_time.last_delete_time_target_id ' . 'WHERE owner_delete_time.delete_time <= messages.created ' . 'AND thread.updated < :timestamp';
  $vars = [
    ':uid' => $user
      ->id(),
    ':timestamp' => $timestamp,
  ];
  return (bool) $this->database
    ->queryRange($query, 0, 1, $vars)
    ->fetchField();
}