You are here

function DataManager::blockAccess in Forena Reports 7.5

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

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

Parameters

$block Repository block used to test access:

$path xpath to user right within xml data.:

$access Access to test:

Return value

boolean

File

src/DataManager.php, line 324
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
    $frxData = Frx::Data();
    $frxData
      ->push(array(), 'frx-block-access');
    $data = Frx::DataManager()
      ->data($block);
    $frxData
      ->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;
}