public function PrivateMessageMapper::getUpdatedInboxThreadIds in Private Message 8.2
Same name and namespace in other branches
- 8 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 208
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 thread_member ' . 'ON thread_member.entity_id = thread.id AND thread_member.members_target_id = :uid ' . '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__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 ';
$vars = [
':uid' => $this->currentUser
->id(),
':history_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');
}
}