You are here

forena_query.module in Forena Reports 7.4

Same filename and directory in other branches
  1. 7.5 forena_query.module
  2. 7.3 forena_query.module

Provides the ability to create saved queries and to test sql data blocks.

File

forena_query.module
View source
<?php

/**
 * @file
 * Provides the ability to create saved queries
 * and to test sql data blocks.
 */

/**
 * Implementation of hook_menu.
 */
function forena_query_menu() {
  $items = array();
  $items['admin/structure/forena/data/add'] = array(
    'type' => MENU_CALLBACK,
    'title' => 'Create new SQL Query',
    'access arguments' => array(
      'build forena sql blocks',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'forena_query_create_block_form',
    ),
    'file' => 'forena_query.inc',
  );
  $items['admin/structure/forena/data/%/edit'] = array(
    'type' => MENU_CALLBACK,
    'title' => 'SQL Editor',
    'access callback' => 'forena_query_editor_access',
    'access arguments' => array(
      4,
      'create',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'forena_query_editor',
      4,
    ),
    'file' => 'forena_query.inc',
  );
  $items['admin/structure/forena/data/%/delete'] = array(
    'type' => MENU_CALLBACK,
    'title' => 'Delete/Revert Custom Data Query',
    'access callback' => 'forena_query_editor_access',
    'access arguments' => array(
      4,
      'delete',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'forena_query_delete_form',
      4,
    ),
    'file' => 'forena_query.inc',
  );
  $items['forena-query/table_autocomplete'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'build forena sql blocks',
    ),
    'page callback' => 'forena_query_autocomplete',
    'file' => 'forena_query.inc',
  );
  $items['forena-query/table_autocomplete_simple'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'build forena sql blocks',
    ),
    'page callback' => 'forena_query_autocomplete_simple',
    'file' => 'forena_query.inc',
  );
  return $items;
}

/**
 * Access function based on data b.
 * @param string $block_name
 *   Name of block to check access on.
 * @param string $action
 *   Determines type of block right to check.
 * @return boolean
 */
function forena_query_editor_access($block_name, $action = 'create') {
  $block_name = str_replace('.', '/', $block_name);
  @(list($provider, $block) = explode('/', $block_name));
  return user_access("access {$provider} data") && user_access("{$action} {$provider} blocks");
}

/**
 * Implementation of hook_permission.
 */
function forena_query_permission() {
  $perms = array(
    'build forena sql blocks' => array(
      'title' => 'Build Forena Data Blocks using SQL',
      'description' => 'Direct access to SQL should not be given without understanding of security ramifications',
    ),
    'forena data security' => array(
      'title' => 'Manage data security',
      'description' => 'Allows to create new data queries and alter security on saved queries.',
    ),
  );
  foreach (Frx::RepoMan()->repositories as $repos => $conf) {
    $name = $conf['title'] ? $conf['title'] : $repos;
    $perms['create ' . $repos . ' blocks'] = array(
      'title' => 'Create ' . $name . ' Data Blocks',
    );
    $perms['delete ' . $repos . ' blocks'] = array(
      'title' => 'Delete ' . $name . ' Data Blocks',
    );
  }
  return $perms;
}

/**
 * Implmentation of hook_requirements.
 * @param string $phase
 *   Phase of requirement check to perform.
 * @return array
 *   Requirements analysis.
 */
function forena_query_requirements($phase) {
  $requirements = array();
  switch ($phase) {
    case 'runtime':
      $writeable = is_writable(Frx::DataFile()->dir);
      if (!$writeable) {
        $requirements['fornea_writable'] = array(
          'title' => 'Forena Query Data Directory',
          'value' => Frx::DataFile()->dir,
          'severity' => REQUIREMENT_ERROR,
          'description' => t('The directory must be writable by the web user in order to create custom SQL data sources.') . t('Configure <a href="@private_path">private file system paths</a> or specificy a differnt <a href="@data_directory">data directory</a>."', array(
            '@private_path' => url('admin/config/media/file-system'),
            '@data_directory' => url('admin/config/content/forena'),
          )),
        );
      }
  }
  return $requirements;
}
function forena_query_forena_query_builders() {
  return array(
    'FrxQueryBuilder' => array(
      'class' => 'FrxQueryBuilder',
      'file' => 'builders/FrxQueryBuilder.inc',
    ),
  );
}

/**
 * Return permission as to whether the user can save data
 * in the repository.
 * @param string $repos
 *   Name of repository to check.
 * @return bool
 *   True implies user has access to data provided by the connection.
 */
function forena_query_access_repository($repos) {
  @(list($repos, $block) = @explode('/', $repos, 2));
  return user_access('create ' . $repos . ' blocks');
}

Functions

Namesort descending Description
forena_query_access_repository Return permission as to whether the user can save data in the repository.
forena_query_editor_access Access function based on data b.
forena_query_forena_query_builders
forena_query_menu Implementation of hook_menu.
forena_query_permission Implementation of hook_permission.
forena_query_requirements Implmentation of hook_requirements.