aboutsummaryrefslogtreecommitdiff
path: root/isis.php
blob: 66b3b7d0f589973c2ea0339f1b37caa587eb162d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
 * Database procedures.
 */

/**
 * Schema format example.
 */
$schema = array(
  'db'          => array(
    'name'      => 'dbname',
  ),
  'fields'      => array(
    'field_name'  => array(
      'id'        => 1,
      'size'      => 1000,
      'format'    => 'numeric',
      'repeat'    => TRUE,
      'subfields' => array(
        'a'       => 'test',
        'b'       => 'test2',
      ),
    ),
  ),
);

/**
 * Generic interface for reading Isis databases.
 */
interface IsisDb {
  // Constructor.
  public function __construct($schema);

  // Return field data for a given entry.
  public function fields($id);

  // Return subfield data for a given entry.
  public function subfields($id);

  // Read an entry.
  public function read($id);

  // Return number of rows in the database.
  public function rows();
}

/**
 * Malete implementation of IsisDb.
 */
class MaleteDb implements IsisDb {
  var $fdt;
  var $db;
  var $format;

  public function __construct($schema) {
    // Save db schema.
    $format = $schema;

    // Setup $fdt used by malete.
    foreach ($schema['fields'] as $field => $info) {
      $fdt[$field] = $info['id'];
    }

    // Open a database connection.
    $db = new Isis_Db($fdt, $schema['db']['name'], new Isis_Server());
  }

  public function fields($id == NULL) {
  }

  public function subfields($id == NULL) {
  }

  // TODO: put result into $schema format.
  public function read($id) {
    if (!is_numeric($id) {
      return FALSE;
    }
    return $this->$db->read($id);
  }

  public function rows() {
  }
}

?>