public function PrivateMessageService::getThreadsForUser in Private Message 8.2
Same name and namespace in other branches
- 8 src/Service/PrivateMessageService.php \Drupal\private_message\Service\PrivateMessageService::getThreadsForUser()
Retrieve private message threads for a given user.
Parameters
int $count: The number of threads to retrieve.
int $timestamp: A timestamp relative to which only threads with an earlier timestamp should be returned.
Return value
array An array with two keys:
- threads: an array of \Drupal\private_message\Entity\PrivateMessageThread
- next_exists: a boolean indicating whether any more private message threads exist after the last one
Overrides PrivateMessageServiceInterface::getThreadsForUser
File
- src/
Service/ PrivateMessageService.php, line 146
Class
- PrivateMessageService
- The Private Message service for the private message module.
Namespace
Drupal\private_message\ServiceCode
public function getThreadsForUser($count, $timestamp = FALSE) {
$return = [
'threads' => [],
'next_exists' => FALSE,
];
$user = $this->userManager
->load($this->currentUser
->id());
$thread_ids = $this->mapper
->getThreadIdsForUser($user, $count, $timestamp);
if (count($thread_ids)) {
$threads = $this->pmThreadManager
->loadMultiple($thread_ids);
if (count($threads)) {
$last_thread = end($threads);
$last_timestamp = $last_thread
->get('updated')->value;
$return['next_exists'] = $this->mapper
->checkForNextThread($user, $last_timestamp);
$return['threads'] = $threads;
}
}
return $return;
}