function taxonomy_access_grant_update in Taxonomy Access Control 5
Same name and namespace in other branches
- 5.2 taxonomy_access_admin.inc \taxonomy_access_grant_update()
Updates permissions for a role for a term
Parameters
$tid: The term 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.
2 calls to taxonomy_access_grant_update()
- taxonomy_access_grant_vocab_update in ./
taxonomy_access.module - Updates permissions for a role for all the terms in a vocabulary
- _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 219 - Allows administrators to specify how each category (in the taxonomy) can be used by various roles.
Code
function taxonomy_access_grant_update($tid, $role = null, $grants = null) {
if (!isset($tid)) {
return FALSE;
}
if (isset($role) && !is_numeric($role)) {
$role = db_result(db_query("SELECT rid FROM {role} WHERE name='{$role}'"));
}
$ta_sql = "INSERT INTO {term_access} (tid";
$ta_sql_values = " VALUES ({$tid}";
if (isset($role)) {
$ta_sql .= ",rid";
$ta_sql_values .= ",{$role}";
}
$sql = "";
if (isset($grants)) {
foreach ($grants as $perm => $value) {
$sql .= ",grant_{$perm}";
$ta_sql_values .= is_array($value) ? "," . $value[0] : ",{$value}";
}
$sql .= ")";
$ta_sql_values .= ")";
}
else {
$sql .= ")";
$ta_sql_values .= ")";
}
$ta_sql .= $sql . $ta_sql_values;
db_query("DELETE FROM {term_access} WHERE tid=%d AND rid=%d", $tid, isset($role) ? $role : 0);
db_query($ta_sql);
// insert into term_access
}