You are here

function certificate_can_access_certificate in Certificate 6

Same name and namespace in other branches
  1. 8.3 certificate.module \certificate_can_access_certificate()
  2. 6.2 certificate.module \certificate_can_access_certificate()
  3. 7.3 certificate.module \certificate_can_access_certificate()
  4. 7.2 certificate.module \certificate_can_access_certificate()
  5. 3.x certificate.module \certificate_can_access_certificate()

Check if a user can access a certificate for this node.

This function:

Return value

TRUE if certificate tab should show and be accessible. @return string (eval to true for Drupal's menu) if certificate tab should show but be denied with a message. @return FALSE if certificate tab should be hidden.

2 calls to certificate_can_access_certificate()
certificate_nodeapi in ./certificate.module
Implements hook_nodeapi.
certificate_node_certificate in ./certificate.pages.inc
Get certificate for a specific node.
1 string reference to 'certificate_can_access_certificate'
certificate_menu in ./certificate.module
Implementation of hook_menu().

File

./certificate.module, line 714
Certificate module.

Code

function certificate_can_access_certificate($node, &$account = NULL) {
  static $cert_access = array();
  if (!$account) {
    global $user;
    $account = $user;
  }
  if (!$account->uid) {
    return FALSE;
  }
  if (!isset($cert_access[$node->nid])) {
    $access = module_invoke_all('access_certificate', $node, $account);
    $cert_access[$node->nid] = $access;
  }
  else {
    $access = $cert_access[$node->nid];
  }
  foreach ($access as $item) {
    if ($item === TRUE) {

      // Something said the leaner should access the certificate.
      $found_true = TRUE;
    }
    if (is_string($item)) {

      // Something returned a string, return it (will show the menu, but error)
      return $item;
    }
    if ($item === FALSE) {
      $found_false = TRUE;
    }
  }
  if ($found_true) {
    if ($found_false) {

      // Found TRUE and FALSEs.
      return FALSE;
    }

    // Only found TRUE.
    return TRUE;
  }

  // All were false.
  return FALSE;
}