You are here

function privatemsg_thread_change_delete in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_thread_change_delete()
  2. 6 privatemsg.module \privatemsg_thread_change_delete()
  3. 7.2 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 account for which the delete action should be carried out - Set to NULL to delete for all users.

1 string reference to 'privatemsg_thread_change_delete'
privatemsg_privatemsg_thread_operations in ./privatemsg.module
Implements hook_privatemsg_thread_operations().

File

./privatemsg.module, line 2267
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 = clone $user;
  }

  // Load all messages of those threads including the deleted.
  $query = _privatemsg_assemble_query('messages', $threads, $account, TRUE);

  // Delete each message. We need to do that to trigger the delete hook.
  foreach ($query
    ->execute() as $row) {
    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.'));
  }
}