You are here

function forum_access_db_rewrite_sql in Forum Access 5

Same name and namespace in other branches
  1. 6 forum_access.module \forum_access_db_rewrite_sql()

Implementation of hook_db_rewrite_sql().

Because in order to restrict the visible forums, we have to rewrite the sql. This is because there isn't a node_access equivalent for taxonomy. There should be.

File

./forum_access.module, line 339
forum_access.module

Code

function forum_access_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
  if ($primary_field == 'tid' && !user_access('administer forums')) {
    global $user;
    $roles = _forum_access_get_roles($user);
    $sql['join'] = "LEFT JOIN {forum_access} fa ON {$primary_table}.tid = fa.tid\n                    LEFT JOIN {acl} acl_fa ON acl_fa.name = " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "{$primary_table}.tid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " AND acl_fa.module = 'forum_access'\n                    LEFT JOIN {acl_user} aclu_fa ON aclu_fa.acl_id = acl_fa.acl_id AND aclu_fa.uid = {$user->uid}";
    $sql['where'] = "(fa.grant_view >= 1 AND fa.rid IN ({$roles})) OR fa.tid IS NULL OR aclu_fa.uid = {$user->uid}";
    $sql['distinct'] = 1;
    return $sql;
  }
}