You are here

class FrxDrupal in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 plugins/FrxDrupal.inc \FrxDrupal
  2. 6 plugins/FrxDrupal.inc \FrxDrupal
  3. 7.2 plugins/FrxDrupal.inc \FrxDrupal
  4. 7.3 plugins/FrxDrupal.inc \FrxDrupal
  5. 7.4 plugins/FrxDrupal.inc \FrxDrupal

@file Provides data blocks for native drupal connections using the default drupal connections.

Hierarchy

Expanded class hierarchy of FrxDrupal

2 string references to 'FrxDrupal'
forena_forena_plugins in ./forena.module
Self register plugins with forena.
settings.php in repos/drupal/settings.php

File

plugins/FrxDrupal.inc, line 9
Provides data blocks for native drupal connections using the default drupal connections.

View source
class FrxDrupal extends FrxDataProvider {

  /**
   * Implements hooks into the drupal applications
   */
  private $db;

  /**
   * Object constructor
   *
   * @param unknown_type $uri Database connection string.
   * @param string $repos_path Path to location of data block definitions
   */
  public function __construct($conf, $repos_path) {
    parent::__construct($conf, $repos_path);

    // Set up the stuff required to translate.
    $this->te = new FrxSyntaxEngine(FRX_SQL_TOKEN, ':', $this);
  }

  /**
   * Get data based on file data block in the repository.
   *
   * @param String $block_name
   * @param Array $parm_data
   * @param Query $subQuery
   */
  public function data($block_name, $params = array(), $clause = '') {

    // Load the block from the file
    $block = $this
      ->load_block($block_name, $clause);
    $xml = '';
    if ($block['source'] && $this
      ->access($block['access'])) {
      $sql = $block['source'];
      if ($clause) {
        $sql = 'SELECT * FROM (' . trim($sql, ' ;') . ') forena_table ' . $clause;
      }
      $sql = $this->te
        ->replace($sql, $params);
      $rs = db_query($sql);
      $xml = new SimpleXMLElement('<table/>');
      foreach ($rs as $data) {
        $row_node = $xml
          ->addChild('row');
        foreach ($data as $key => $value) {
          $row_node
            ->addChild($key, htmlspecialchars($value));

          //$row_node->$key = $value;
        }
      }
    }
    return $xml;
  }

  /**
   * Implement custom SQL formatter to make sure that strings are properly escaped.
   * Ideally we'd replace this with something that handles prepared statements, but it
   * wouldn't work for
   *
   * @param unknown_type $value
   * @param unknown_type $key
   * @param unknown_type $data
   */
  public function format($value, $key, $data) {
    $db = Database::getConnection('default');
    if ($db) {
      if ($value == '') {
        $value = 'NULL';
      }
      else {
        $value = $db
          ->quote($value);
      }
    }
    return $value;
  }

  /**
   * @section
   * Formatters
   * Below here are formatting types
   */
  public function formats() {
    $formats = array(
      'drupal_filter' => 'Drupal Input Filter',
    );
    return $formats;
  }
  public function drupal_filter($nid, $format) {
    $node = node_load($nid, NULL, TRUE);
    if (!$node) {
      return 'N/A';
    }
    if (strcasecmp($format, 'teaser') == 0 || !$format) {
      $bool = TRUE;
    }
    else {
      $bool = FALSE;
    }

    //If true, render the teaser

    //else render the body
    $node = node_prepare($node, $bool);
    if ($bool) {
      return $node->teaser;
    }
    return $node->body;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDataProvider::$block_ext public property
FrxDataProvider::$block_path public property
FrxDataProvider::$comment_prefix public property
FrxDataProvider::$comment_suffix public property
FrxDataProvider::$conf public property
FrxDataProvider::$te protected property
FrxDataProvider::access public function Implements the basic default security check of calling an access method.
FrxDataProvider::list_blocks public function Find all the blocks matching a provided search string
FrxDataProvider::load_block public function Default block load Loads the data block based on the block name from the file system. The classes that are derived from this will set the block_ext property, which in most cases is .sql but might be something different. The load of the block file…
FrxDrupal::$db private property * Implements hooks into the drupal applications
FrxDrupal::data public function Get data based on file data block in the repository.
FrxDrupal::drupal_filter public function
FrxDrupal::format public function Implement custom SQL formatter to make sure that strings are properly escaped. Ideally we'd replace this with something that handles prepared statements, but it wouldn't work for
FrxDrupal::formats public function @section Formatters Below here are formatting types
FrxDrupal::__construct public function Object constructor Overrides FrxDataProvider::__construct