function taxonomy_access_grant_update in Taxonomy Access Control 5.2
Same name and namespace in other branches
- 5 taxonomy_access.module \taxonomy_access_grant_update()
Updates permissions for a role for a term
Parameters
$tid: The term to add the permission for.
$rid: The role id to add the permission for.
$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_update()
File
- ./
taxonomy_access_admin.inc, line 348 - Administrative interface for taxonomy access control.
Code
function taxonomy_access_grant_update($tid, $rid = null, $grants = null) {
if (!isset($tid) or !is_numeric($rid)) {
return FALSE;
}
$args = array();
$ta_sql = "INSERT INTO {term_access} (tid";
$ta_sql_values = " VALUES (%d";
$args[] = $tid;
if (isset($rid)) {
$ta_sql .= ",rid";
$ta_sql_values .= ",%d";
$args[] = $rid;
}
$sql = "";
if (isset($grants)) {
foreach ($grants as $perm => $value) {
$sql .= ',' . db_escape_table("grant_{$perm}");
$ta_sql_values .= ',%d';
$args[] = is_array($value) ? $value[0] : $value;
}
$sql .= ")";
$ta_sql_values .= ")";
}
else {
$sql .= ")";
$ta_sql_values .= ")";
}
$ta_sql .= $sql . $ta_sql_values;
// issue #167977 - klance
$affected_nodes = _taxonomy_access_get_nodes_for_term($tid);
db_query("DELETE FROM {term_access} WHERE tid=%d AND rid=%d", $tid, $rid);
db_query($ta_sql, $args);
// insert into term_access
// issue #167977 - klance
_taxonomy_access_node_access_update($affected_nodes);
}