function privatemsg_filter_add_tags in Privatemsg 6
Same name and namespace in other branches
- 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_add_tags()
- 7.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_add_tags()
- 7 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_add_tags()
Tag one or multiple threads with a tag.
Parameters
$threads: A single thread id or an array of thread ids.
$tag_id: Id of the tag.
1 call to privatemsg_filter_add_tags()
- privatemsg_filter_form_submit in privatemsg_filter/
privatemsg_filter.module
2 string references to 'privatemsg_filter_add_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 214 - Allows users to tag private messages and to filter based upon those tags.
Code
function privatemsg_filter_add_tags($threads, $tag_id, $account = NULL) {
if (!is_array($threads)) {
$threads = array(
$threads,
);
}
if (empty($account)) {
global $user;
$account = drupal_clone($user);
}
foreach ($threads as $thread) {
// Make sure that we don't add a tag to a thread twice,
// only insert if there is no such tag yet.
if (db_result(db_query('SELECT COUNT(*) FROM {pm_tags_index} WHERE tag_id = %d AND (uid = %d AND thread_id = %d)', $tag_id, $account->uid, $thread)) == 0) {
db_query('INSERT INTO {pm_tags_index} (tag_id, uid, thread_id) VALUES (%d, %d, %d)', $tag_id, $account->uid, $thread);
}
}
}