function support_subscribe_user in Support Ticketing System 7
Same name and namespace in other branches
- 6 support.module \support_subscribe_user()
Subscribe a user to a ticket.
5 calls to support_subscribe_user()
- support_comment_insert in ./
support.module - Implementation of hook_comment_insert().
- support_node_insert in ./
support.module - Implementation of hook_node_insert().
- _support_autosubscribe in ./
support.module - Autosubscribe users to new client ticket.
- _support_comment_insert_update2 in ./
support.module - _support_node_insert_update in ./
support.module - Common code for inserting or updating a support ticket
File
- ./
support.module, line 2008 - support.module
Code
function support_subscribe_user($nid, $uid, $subscribe = 1) {
$clid = db_query('SELECT client FROM {support_ticket} WHERE nid = :nid', array(
':nid' => $nid,
))
->fetchField();
$client = support_client_load($clid);
$account = user_load($uid);
if (support_access_clients($client, $account)) {
if ($subscribe) {
db_merge('support_assigned')
->key(array(
'nid' => $nid,
'uid' => $uid,
))
->execute();
}
else {
db_delete('support_assigned')
->condition('nid', $nid)
->condition('uid', $uid)
->execute();
}
}
else {
// If this user doesn't have permission to receive ticket updates,
// be sure they are unsubscribed.
db_delete('support_assigned')
->condition('nid', $nid)
->condition('uid', $uid)
->execute();
}
}