You are here

function taxonomy_access_grant_vocab_update in Taxonomy Access Control 5

Updates permissions for a role for all the terms in a vocabulary

Parameters

$vid: The vocabulary to search for terms to add the permission for.

$role: The role to add the permission to. Can be the name or the role id or blank for all term permissions.

$grants: A hash of the grants in the form of $grants['perm'] = boolean A value of 1 will grant the permission for this user and term.

1 call to taxonomy_access_grant_vocab_update()
_taxonomy_access_permissions_form_submit in ./taxonomy_access_admin.inc
Saves the category permissions matrix for choosen user role, after editing.

File

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

Code

function taxonomy_access_grant_vocab_update($vid, $rid = null, $edit = null) {
  $tree = taxonomy_get_tree($vid);
  $grant_types = array(
    'view',
    'update',
    'delete',
    'create',
    'list',
  );
  $vgrants = $edit[$vid]['vocab'];
  $grants = array();
  foreach ($tree as $term) {
    foreach ($grant_types as $grant) {
      if (in_array($vgrants[$grant], array(
        0,
        1,
        2,
      ))) {
        $grants[$grant] = $vgrants[$grant];
      }
      else {
        $grants[$grant] = $edit[$term->vid]['term'][$term->tid][$grant];
      }
    }
    taxonomy_access_grant_update($term->tid, $rid, $grants);
  }
}