You are here

function faq_ask_taxonomy_term_insert in FAQ_Ask 7

Implementation of hook_taxonomy_term_insert()

Parameters

object $term: Term object to be created

File

./faq_ask.module, line 1786
This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.

Code

function faq_ask_taxonomy_term_insert($term) {
  global $user;
  $default_expert = variable_get('faq_ask_default_expert', 1);

  // See if it's one of our vocabularies.
  $our_vocab = in_array($term->vid, variable_get('faq_ask_vocabularies', array()));

  // term: set default expert.
  if ($our_vocab) {
    db_insert('faq_expert')
      ->fields(array(
      'uid' => $default_expert,
      'tid' => $term->tid,
    ))
      ->execute();
    $inserted = count(db_select('faq_expert', 'fe')
      ->fields('fe', array(
      'uid',
    ))
      ->condition('tid', $term->tid)
      ->execute()
      ->fetchAll());
    if ($inserted == 0) {
      drupal_set_message(t('Attempt to assign expert failed.'), 'error');
    }
    else {
      drupal_set_message(t('Assigned expert @expert to @name (@tid).', array(
        '@expert' => $default_expert,
        '@name' => $term->name,
        '@tid' => $term->tid,
      )), 'status');
    }
  }
}