public function PrivateMessageMapper::getUpdatedInboxThreadIds in Private Message 8
Same name and namespace in other branches
- 8.2 src/Mapper/PrivateMessageMapper.php \Drupal\private_message\Mapper\PrivateMessageMapper::getUpdatedInboxThreadIds()
Retrieve a list of recently updated private message thread IDs.
The last updated timestamp will also be returned. If any ids are provided in $existingThreadIds, the IDs of all threads that have been updated since the oldest updated timestamp for the given thread IDs will be returned. Otherwise the number of IDs returned will be the number provided for $count.
Parameters
array $existingThreadIds: An array of thread IDs to be compared against.
int $count: The number of threads to return if no existing thread IDs were provided.
Return value
array An array, keyed by thread ID, with each element of the array containing an object with the following two properties:
- id: The thread ID
- updated: The timestamp at which the thread was last updated
Overrides PrivateMessageMapperInterface::getUpdatedInboxThreadIds
File
- src/
Mapper/ PrivateMessageMapper.php, line 198
Class
- PrivateMessageMapper
- Interface for the Private Message Mapper class.
Namespace
Drupal\private_message\MapperCode
public function getUpdatedInboxThreadIds(array $existingThreadIds, $count = FALSE) {
$query = 'SELECT DISTINCT(thread.id), updated ' . '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 ';
$vars = [
':uid' => $this->currentUser
->id(),
];
$order_by = 'ORDER BY thread.updated DESC';
if (count($existingThreadIds)) {
$query .= 'AND thread.updated >= (SELECT MIN(updated) FROM {private_message_threads} WHERE id IN (:ids[])) ';
$vars[':ids[]'] = $existingThreadIds;
return $this->database
->query($query . $order_by, $vars)
->fetchAllAssoc('id');
}
else {
return $this->database
->queryRange($query . $order_by, 0, $count, $vars)
->fetchAllAssoc('id');
}
}