You are here

function taxonomy_access_taxonomy in Taxonomy Access Control 5

Same name and namespace in other branches
  1. 5.2 taxonomy_access.module \taxonomy_access_taxonomy()
  2. 6 taxonomy_access.module \taxonomy_access_taxonomy()

Implementation of hook_taxonomy Hook_taxonomy is called when changes are made to the taxonomy structure

File

./taxonomy_access.module, line 427
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_taxonomy($op, $type, $array = NULL) {
  if ($type == 'term') {
    switch ($op) {
      case 'update':

        // don't do anything, nothing on our end has changed
        break;
      case 'insert':

        // add new default entries for the new category, don't have to touch node_access since no posts are in there yet
        foreach (user_roles() as $rid => $role) {
          $grants = db_fetch_object(db_query('SELECT * FROM {term_access_defaults} WHERE vid = %d AND rid= %d', $array['vid'], $rid));
          db_query('DELETE FROM {term_access} WHERE tid = %d AND rid = %d', $array['tid'], $rid);
          db_query('INSERT INTO {term_access} VALUES (%d, %d, %d, %d, %d, %d, %d)', $array['tid'], $rid, $grants->grant_view, $grants->grant_update, $grants->grant_delete, $grants->grant_create, $grants->grant_list);
        }
        break;
      case 'delete':

        // delete everything from term_access and node_access
        db_query('DELETE FROM {term_access} WHERE tid = %d', $array['tid']);
        node_access_rebuild();
        break;
    }
  }
  if ($type == 'vocabulary') {
    switch ($op) {
      case 'update':

        // don't do anything, nothing on our end has changed
        break;
      case 'insert':

        // add default values for the new vocabulary to table 'term_access_defaults'
        foreach (user_roles() as $rid => $role) {
          db_query('DELETE FROM {term_access_defaults} WHERE vid = %d AND rid = %d', $array['vid'], $rid);
          db_query('INSERT INTO {term_access_defaults} VALUES (%d, %d, %d, %d, %d, %d, %d)', _taxonomy_access_defaults($array['vid'], $rid));
        }
        break;
      case 'delete':

        // delete vocabulary from table 'term_access_defaults'
        db_query('DELETE FROM {term_access_defaults} WHERE vid = %d', $array['vid']);
        break;
    }
  }
  return;
}