I'm attempting to create a simple php evaluation of the tac_lite grants (terms the user is allowed to view) that I can use for non-node material that is not regulated by tac_lite. The code below doesn't work however I got the idea from viewing the tac_lite module and was hopeful that it might help someone understand what I am trying to accomplish. Using Drupal 4.7
Faulty code:
global $user;
if ($grants->tid == 4)
{return TRUE;}
Below I pasted the functions from tac_lite for reference.
I'd appreciate any guidance that would help resolve my shortfall here.
// $Id: tac_lite.module,v 1.5 2006/05/03 17:15:19 yogadex Exp $
/**
* Return the term ids of terms this user is allowed to access
*
* Users are granted access to terms either because of who they are,
* or because of the roles they have.
*/
function _tac_lite_user_tids(&$account) {
$grants = array();
if (count($account->tac_lite)) {
// $account->tac_lite is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access
foreach ($account->tac_lite as $tids) {
if (count($tids))
$grants = array_merge($grants, $tids);
}
}
// add per-role grants in addition to per-user grants
$defaults = variable_get('tac_lite_default_grants', array());
foreach ($account->roles as $rid => $role_name) {
if (count($defaults[$rid])) {
foreach ($defaults[$rid] as $tids) {
if (count($tids))
$grants = array_merge($grants, $tids);
}
}
}
// grant id 0 is reserved for nodes which were not given a grant id when they were created. By adding 0 to the grant id, we let the user view those nodes.
// TODO: make this behavior configurable, to play nicely with other node_access modules which may be installed
$grants[] = 0;
return $grants;
}
function tac_lite_node_grants(&$account, &$op) {
// allow administrators to view all
// (relies on drupal's default entry in node_access table.)
if (user_access('administer_tac_lite'))
$all = array(0);
else
$all = array(-1);
$grants = _tac_lite_user_tids($account);
// TODO: differentiate between view, update, delete
return array('all' => $all, // this disables the default setting (view all)
'tac_lite' => $grants);
}