You are here

function privatemsg_filter_remove_tags in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_remove_tags()
  2. 6 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_remove_tags()
  3. 7.2 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
Form builder function, display a form to modify tags on a thread.
3 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_privatemsg_thread_operations in privatemsg_filter/privatemsg_filter.module
Form callback for removing 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 249
Allows users to tag private messages and to filter based upon those tags.

Code

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

    //Delete all tag mapping - all except for the inbox tag if it exists.
    db_delete('pm_tags_index')
      ->condition('uid', $account->uid)
      ->condition('thread_id', $threads)
      ->condition('tag_id', variable_get('privatemsg_filter_inbox_tag', ''), '<>')
      ->execute();
  }
  else {
    if (!is_array($tag_ids)) {
      $tag_ids = array(
        $tag_ids,
      );
    }

    //Delete tag mapping for the specified tag.
    db_delete('pm_tags_index')
      ->condition('uid', $account->uid)
      ->condition('thread_id', $threads)
      ->condition('tag_id', $tag_ids)
      ->execute();
  }
}