You are here

function acl_node_access_explain in ACL 7

Same name and namespace in other branches
  1. 8 acl.module \acl_node_access_explain()
  2. 5 acl.module \acl_node_access_explain()
  3. 6 acl.module \acl_node_access_explain()

Implements hook_node_access_explain().

File

./acl.module, line 340
An API module providing by-user access control lists.

Code

function acl_node_access_explain($row) {
  static $interpretations = array();
  if ($row->realm == 'acl') {
    if (!isset($interpretations[$row->gid])) {
      $acl = db_query("SELECT * FROM {acl} WHERE acl_id = :acl_id", array(
        'acl_id' => $row->gid,
      ))
        ->fetchObject();
      $acl->tag = '?';
      if (!isset($acl->name)) {
        $acl->tag = $acl->number;
      }
      elseif (!isset($acl->number)) {
        $acl->tag = $acl->name;
      }
      else {
        $acl->tag = $acl->name . '-' . $acl->number;
      }
      foreach (user_load_multiple(acl_get_uids($row->gid)) as $account) {
        $usernames[] = _acl_format_username($account);
      }
      if (isset($usernames)) {
        $usernames = implode(', ', $usernames);
        $interpretations[$row->gid] = _acl_get_explanation("{$acl->module}/{$acl->tag}: {$usernames}", $acl->acl_id, $acl->module, $acl->name, $acl->number, $usernames);
      }
      elseif ($row->gid == 0) {
        $result = db_query("SELECT an.acl_id, a.module, a.name FROM {acl_node} an JOIN {acl} a ON an.acl_id = a.acl_id LEFT JOIN {acl_user} au ON a.acl_id = au.acl_id WHERE an.nid = :nid AND au.uid IS NULL", array(
          'nid' => $row->nid,
        ));
        foreach ($result as $acl) {
          $rows[] = _acl_get_explanation("{$acl->acl_id}: {$acl->module}/{$acl->tag}", $acl->acl_id, $acl->module, $acl->name, $acl->number);
        }
        if (!empty($rows)) {
          return implode('<br />', $rows);
        }
        return 'No access via ACL.';
      }
      else {
        $interpretations[$row->gid] = _acl_get_explanation("{$acl->module}/{$acl->tag}: no users!", $acl->acl_id, $acl->module, $acl->name, $acl->number);
      }
    }
    return $interpretations[$row->gid];
  }
}