You are here

function tft_taxonomy_access_load_term_grant in Taxonomy File Tree 7.2

Helper function to load a specific grant for a term.

Parameters

string $op:

int $tid:

int $rid:

Return value

int|null

2 calls to tft_taxonomy_access_load_term_grant()
tft_taxonomy_access_access_form in modules/tft_taxonomy_access/tft_taxonomy_access.module
Form callback: access control form.
tft_taxonomy_access_tft_term_access in modules/tft_taxonomy_access/tft_taxonomy_access.module
Implements hook_tft_term_access().

File

modules/tft_taxonomy_access/tft_taxonomy_access.module, line 228
Taxonomy Access integration.

Code

function tft_taxonomy_access_load_term_grant($op, $tid, $rid) {
  $term = taxonomy_term_load($tid);
  $vid = variable_get('tft_vocabulary_vid', 0);
  if ($term->vid != $vid) {
    return NULL;
  }
  $default_grants = db_query('SELECT * FROM {taxonomy_access_default} WHERE rid = :rid', array(
    ':rid' => $rid,
  ))
    ->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
  $grants = db_query('SELECT * FROM {taxonomy_access_term} WHERE rid = :rid AND tid = :tid', array(
    ':rid' => $rid,
    ':tid' => $tid,
  ))
    ->fetchAllAssoc('tid', PDO::FETCH_ASSOC);
  $default_grants = !empty($default_grants[$vid]) ? $default_grants[$vid] : $default_grants[0];
  $default_grant = in_array($default_grants["grant_{$op}"], array(
    0,
    2,
  )) ? 0 : 1;
  return !empty($grants[$tid]["grant_{$op}"]) ? in_array($grants[$tid]["grant_{$op}"], array(
    0,
    2,
  )) ? 0 : 1 : $default_grant;
}