function privatemsg_thread_change_status in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg.module \privatemsg_thread_change_status()
- 7.2 privatemsg.module \privatemsg_thread_change_status()
- 7 privatemsg.module \privatemsg_thread_change_status()
Marks one or multiple threads as (un)read.
Parameters
$threads: Array with thread id's or a single thread id.
$status: Either PRIVATEMSG_READ or PRIVATEMSG_UNREAD, sets the new status.
$account: User object for which the threads should be deleted, defaults to the current user.
2 string references to 'privatemsg_thread_change_status'
- hook_privatemsg_thread_operations in ./
privatemsg.api.php - Expose operations/actions which can be executed on threads.
- privatemsg_privatemsg_thread_operations in ./
privatemsg.module - Implements hook_privatemsg_thread_operations().
File
- ./
privatemsg.module, line 2184 - Allows users to send private messages to other users.
Code
function privatemsg_thread_change_status($threads, $status, $account = NULL) {
if (!is_array($threads)) {
$threads = array(
$threads,
);
}
if (empty($account)) {
global $user;
$account = drupal_clone($user);
}
// Merge status and uid with the exising thread list.
$params = array_merge(array(
$status,
$account->uid,
), $threads);
// Record which messages will change status.
$changed = array();
$result = db_query("SELECT mid FROM {pm_index} WHERE is_new <> %d AND recipient = %d and type IN ('user', 'hidden') AND thread_id IN (" . db_placeholders($threads) . ')', $params);
while ($row = db_fetch_object($result)) {
$changed[] = $row->mid;
}
// Update the status of the threads.
db_query("UPDATE {pm_index} SET is_new = %d WHERE recipient = %d and type IN ('user', 'hidden') AND thread_id IN (" . db_placeholders($threads) . ')', $params);
// Allow modules to respond to the status changes.
foreach ($changed as $mid) {
module_invoke_all('privatemsg_message_status_changed', $mid, $status, $account);
}
if ($status == PRIVATEMSG_UNREAD) {
drupal_set_message(format_plural(count($threads), 'Marked 1 thread as unread.', 'Marked @count threads as unread.'));
}
else {
drupal_set_message(format_plural(count($threads), 'Marked 1 thread as read.', 'Marked @count threads as read.'));
}
}