FrxDrupal.inc 2.05 KB
Newer Older
1
<?php
metzlerd's avatar
metzlerd committed
2
3
4
5
6
7
8
// $Id$
/**
 * @file
 * Provides data blocks for native drupal connections using the default 
 * drupal connections.
 *
 */
9
class frxDrupal extends FrxDataEngine {
metzlerd's avatar
metzlerd committed
10
  /**
11
12
	 * Implements hooks into the drupal applications
	 */
metzlerd's avatar
metzlerd committed
13
  private $te;  
14
15
16
  private $db;
  private $block_path; 
  
17
  /**
18
   * Object constructor
19
   *
20
21
   * @param unknown_type $uri Database connection string.
   * @param string $repos_path Path to location of data block definitions
22
   */
23
24
25
26
27
  public function __construct($conf, $repos_path) {
    parent::__construct($conf, $repos_path);
     
    // Set up the stuff required to translate. 
    $this->block_path = $repos_path; 
metzlerd's avatar
metzlerd committed
28
    $this->te = new FrxSyntaxEngine(FRX_SQL_TOKEN, ':', $this); 
29
  }
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  /**
   * 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(), $subQuery='') {
    // Load the block from the file

    $filename = $this->block_path .'/'. $block_name . '.sql';  
    $block = forena_load_block_file($filename); 
    $xml =''; 
    if ($block['source'] && $this->access($block['access'])) { 
      $sql = $block['source']; 
metzlerd's avatar
metzlerd committed
45
      $sql = $this->te->replace($sql, $params);
46
47
48
49
50
51
      $rs = db_query($sql); 
      $xml = new SimpleXMLElement('<table/>'); 
      while ($data = db_fetch_object($rs)) { 

          $row_node = $xml->addChild('row'); 
          
metzlerd's avatar
metzlerd committed
52
          foreach ($data as $key => $value) {
53
54
            $row_node->addChild($key, htmlspecialchars($value)); 
            //$row_node->$key = $value; 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
          }
      }
        
    }

    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) { 
metzlerd's avatar
metzlerd committed
73
    $value =  "'". db_escape_string($value) ."'"; 
74
75
76
    return $value; 
  }
  
77
}