You are here

public function DataManager::__construct in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/DataManager.php \Drupal\forena\DataManager::__construct()
1 method overrides DataManager::__construct()
TestingDataManager::__construct in tests/src/Unit/Mock/TestingDataManager.php
Create object for testing

File

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

Class

DataManager

Namespace

Drupal\forena

Code

public function __construct() {
  global $_forena_repositories;

  // Initialize services
  $app = AppService::instance();
  $this->dataSvc = new DataContext();
  $this->dataSvc
    ->setContext('site', $app->siteContext);

  // Empty repository so we need to initialize
  // Build the default sample one
  $providers = array();

  // Load the repository list from the global settings.php file.
  if ($_forena_repositories) {
    $providers = $_forena_repositories;
  }
  $this->drivers = $app
    ->getDriverPlugins();
  $data = AppService::instance()
    ->getForenaProviders();
  foreach ($data as $module => $provider) {
    if (isset($provider['data'])) {
      $providers = array_merge($providers, $provider['data']);
    }
  }

  // Retrieve the repositories defined in the database;
  $results = db_query('SELECT * FROM {forena_repositories}');
  foreach ($results as $r) {
    if ($r->config) {
      $new_r = unserialize($r->config);
    }
    else {
      $new_r = array();
    }
    $r_name = $r->repository;
    if (is_array(@$providers[$r_name])) {
      $new_r = array_merge($new_r, $providers[$r_name]);
    }
    else {
      $new_r['source'] = 'user';
    }
    $new_r['title'] = $r->title;
    $new_r['enabled'] = $r->enabled;
    $providers[$r_name] = $new_r;
  }
  if ($_forena_repositories) {
    array_merge($providers, $_forena_repositories);
  }
  \Drupal::moduleHandler()
    ->alter('forena_data_provider', $providers);
  $this->repositories = $providers;
}