You are here

function DataManager::blockAccess in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/DataManager.php \Drupal\forena\DataManager::blockAccess()

Check access control using the block in a data block. In this case public assess returns true.

@pararm $cache Allow caching of block access check

Parameters

string $block: Repository block used to test access

string $path: xpath to user right within xml data.

string $access: Access to test

Return value

boolean

File

src/DataManager.php, line 341
DataManager.inc Enter description here ... @author davidmetzler

Class

DataManager

Namespace

Drupal\forena

Code

function blockAccess($block, $path, $access, $cache = TRUE) {

  // PUBLIC always returns true.
  if ($access == 'PUBLIC') {
    return TRUE;
  }
  if (!isset($_SESSION['forena_access'])) {
    $_SESSION['forena_access'] = array();
  }
  if ($cache && isset($_SESSION['forena_access'][$block])) {
    $rights = $_SESSION['forena_access'][$block];
  }
  else {
    $rights = array();

    // Get the block from the repository
    $this->dataSvc
      ->push(array(), 'frx-block-access');
    $data = $this
      ->data($block);
    $this->dataSvc
      ->pop();
    if ($data) {
      if (!$path) {
        $path = '*/*';
      }
      $nodes = $data
        ->xpath($path);
      if ($nodes) {
        foreach ($nodes as $node) {
          $rights[] = (string) $node;
        }
      }
      $_SESSION['forena_access'][$block] = $rights;
    }
  }
  foreach ($rights as $right) {
    if ($access == $right) {
      return TRUE;
    }
  }
  return FALSE;
}