You are here

function privatemsg_filter_remove_tags in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_remove_tags()
  2. 7.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_remove_tags()
  3. 7 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_remove_tags()

Remove tag from one or multiple threads.

Parameters

$threads: A single thread id or an array of thread ids.

$tag_id: Id of the tag - set to NULL to remove all tags.

1 call to privatemsg_filter_remove_tags()
privatemsg_filter_form_submit in privatemsg_filter/privatemsg_filter.module
2 string references to 'privatemsg_filter_remove_tags'
privatemsg_filter_add_tag_submit in privatemsg_filter/privatemsg_filter.module
Form callback for adding a tag to threads.
privatemsg_filter_remove_tag_submit in privatemsg_filter/privatemsg_filter.module
Form callback for removing a tag to threads.

File

privatemsg_filter/privatemsg_filter.module, line 240
Allows users to tag private messages and to filter based upon those tags.

Code

function privatemsg_filter_remove_tags($threads, $tag_id = NULL, $account = NULL) {
  if (!is_array($threads)) {
    $threads = array(
      $threads,
    );
  }
  if (empty($account)) {
    global $user;
    $account = drupal_clone($user);
  }
  if (is_null($tag_id)) {

    // Delete all tag mapping.
    foreach ($threads as $thread) {
      db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d', $account->uid, $thread);
    }
  }
  else {

    // Delete tag mapping for the specified tag.
    foreach ($threads as $thread) {
      db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d AND tag_id = %d', $account->uid, $thread, $tag_id);
    }
  }
}