Using Execute PHP to set Permissions in TAC
require_once(drupal_get_path('module', 'taxonomy_access') . "/taxonomy_access_admin.inc");
function tgtbn($name) {
$db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) = LOWER('%s')", 't', 'tid'), trim($name));
$result = array();
while ($term = db_fetch_array($db_result)) {
$result[] = $term;
}
return $result;
}
$srch_name = "".$author->name."-".$node->title."";
$roles = _user_roles();
$role_id = array_search($srch_name, $roles);
if(!is_numeric($role_id)){echo "role id is not a number";}
echo $srch_name;
$taxonomy_term = tgtbn($srch_name);
if(!isset($taxonomy_term[0]['tid'])){echo "taxonomy_term is not a number"; print_r($taxonomy_term);}
$grants = array();
$grants['view'] = 1;
$grants['update'] = 1;
$grants['delete'] = 1;
$grants['create'] = 1;
$grants['list'] = 1;
$tf = taxonomy_access_grant_update($taxonomy_term[0]['tid'], $role_id, $grants);
if($tf == false){echo "grant_update didnt work"; var_dump($tf);}The echo's are for debugging purposes, the error i am getting is from the taxonomy section, the output is:
test mentor-starship building array(0) {} taxonomy_term is not a number Array() grant_update didnt work bool(false)
for some reason the taxonomy_get_term_by_name($name) wont work even if i include the module in the code, i renamed the function and pasted into the action however, it still wont work, it is returning 0, is there something in rules that disallows database calls? it doesnt seem so because the _user_roles() function works just fine.
i know the rest of the code works however i am unable to get the term id so far, if anyone has an idea as to why this is, let me know. i will post the answer here if nobody can figure it out, just in case someone else is having this issue.
-=Levi=-


require_once(drupal_get_path(
require_once(drupal_get_path('module', 'taxonomy_access') . "/taxonomy_access_admin.inc");
function tgtbn($name)
{
$dres = db_query("SELECT t.tid, t.* FROM term_data as t WHERE LOWER(t.name) = LOWER('".trim($name)."')");
$trm = db_fetch_array($dres);
$tid1 = $trm['tid'];
return $tid1;
}
$srch_name = "".$author->name."-".$node->title."";
$roles = _user_roles();
$role_id = array_search($srch_name, $roles);
$tx_t = tgtbn($srch_name);
$grants = array();
$grants['view'] = 1;
$grants['update'] = 1;
$grants['delete'] = 1;
$grants['create'] = 1;
$grants['list'] = 1;
$tf = taxonomy_access_grant_update($tx_t, $role_id, $grants);
I just rewrote the query a little, since the term is generated right before this action is run, there is only one tid i need, so i changed the query to reflect that and the array, and changed the variable names (thinking maybe they were being reassigned?) and that seemed to do the trick. btw, you cannot output arrays in a var_dump or a print_r in the action code, so if i wanted to see the array that was being outputted, it would just show Array(), kinda jinky, thinking maybe some error checking for the execute php would be very useful, since i barely use any of the default actions, and i imagine if anyone needed some complex actions they would need error checking as well. just a thought. great module though, very useful and helpful, thanks a bunch for making it.
-=Levi=-
Hey Nice work there Levi
I've just been trying to find out how to get tac working with rules, so you have given me a starting point. I've just created a module for tac rules tonight, and seems to be working fine. So will give it some more testing then release it..
It lets you choose the role, term, and grants as an action..
Thanks,
Cameron