function privatemsg_thread_change_delete in Privatemsg 6
Same name and namespace in other branches
- 6.2 privatemsg.module \privatemsg_thread_change_delete()
- 7.2 privatemsg.module \privatemsg_thread_change_delete()
- 7 privatemsg.module \privatemsg_thread_change_delete()
Delete or restore one or multiple threads.
Parameters
$threads: Array with thread id's or a single thread id.
$delete: Indicates if the threads should be deleted or restored. 1 => delete, 0 => restore.
$account: User object for which the threads should be deleted, defaults to the current user.
1 string reference to 'privatemsg_thread_change_delete'
File
- ./
privatemsg.module, line 2467 - Allows users to send private messages to other users.
Code
function privatemsg_thread_change_delete($threads, $delete, $account = NULL) {
if (!is_array($threads)) {
$threads = array(
$threads,
);
}
if (empty($account)) {
global $user;
$account = drupal_clone($user);
}
// Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
$params = array_merge(array(
$delete,
$account->uid,
), $threads);
// Load all messages of those threads including the deleted.
$query = _privatemsg_assemble_query('messages', $threads, $account, TRUE);
$result = db_query($query['query']);
// Delete each message. We need to do that to trigger the delete hook.
while ($row = db_fetch_array($result)) {
privatemsg_message_change_delete($row['mid'], $delete, $account);
}
if ($delete) {
drupal_set_message(format_plural(count($threads), 'Deleted 1 thread.', 'Deleted @count threads.'));
}
else {
drupal_set_message(format_plural(count($threads), 'Restored 1 thread.', 'Restored @count threads.'));
}
}