You are here

function _support_autoassign in Support Ticketing System 7

Same name and namespace in other branches
  1. 6 support.module \_support_autoassign()

Return an autoassigned user for a given client.

3 calls to _support_autoassign()
support_save_message in ./support.module
Save the message.
_support_status_form_attach in ./support.module
Generate form for adding update to ticket. Enhances comment_form adding a ticket status bar.
_support_subscribe_form_attach in ./support.module
Provide option to subscribe/unsubscribe from ticket notification emails.

File

./support.module, line 3803
support.module

Code

function _support_autoassign($clid, $uid = 0) {
  static $autoassign = array();
  if ($clid && !isset($autoassign[$clid])) {
    $name = null;
    if (isset($clid)) {
      $name = db_query('SELECT autoassign FROM {support_client} WHERE clid = :clid', array(
        ':clid' => $clid,
      ))
        ->fetchField();
    }
    switch ($name) {
      case '<nobody>':
        $autoassign[$clid] = 0;
        break;
      case '<creator>':
        $autoassign[$clid] = $uid;
        break;
      default:

        // no per-client auto-assign, or an invalid auto-assign
        $accounts = user_load_multiple(array(), array(
          'name' => trim($name),
        ));
        $account = array_shift($accounts);
        if (empty($account) || !$account->uid) {
          $assign = variable_get('support_autoassign_ticket', '<nobody>');
          switch ($assign) {
            case '<nobody>':
              $autoassign[$clid] = 0;
              break;
            case '<creator>':
              $autoassign[$clid] = $uid;
              break;
            default:
              $accounts = user_load_multiple(array(), array(
                'name' => trim($assign),
              ));
              $account = array_shift($accounts);
              if (empty($account) || !$account->uid) {
                $autoassign[$clid] = 0;
              }
              else {
                $autoassign[$clid] = $account->uid;
              }
              break;
          }
        }
        else {
          $autoassign[$clid] = $account->uid;
        }
    }
  }
  return !empty($clid) ? $autoassign[$clid] : 0;
}