/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to classes/cache/rawpoint.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/* 
 
4
    $limit > 0 - first <limit> elements
 
5
    $limit < 0 - last <limit> elements
 
6
*/
 
7
 
 
8
class RAWPoint implements Iterator {
 
9
 var $cache;
 
10
 var $ids;
 
11
 var $ivl;
 
12
 var $limit;
 
13
 
 
14
 var $res;
 
15
 var $key, $row;
 
16
 
 
17
 var $use_subseconds;
 
18
 var $postfix;
 
19
 
 
20
 function __construct(CACHEDB &$cache, MASK &$mask, INTERVAL &$ivl, $limit) {
 
21
    $this->cache = &$cache;
 
22
    $this->ids = &$mask->ids;
 
23
    $this->ivl = &$ivl;
 
24
    $this->limit = $limit;
 
25
 
 
26
    $this->use_subseconds = $cache->use_subseconds;
 
27
    $this->postfix = false;
 
28
 }
 
29
 
 
30
 function SetOption($option, $value) {
 
31
    $this->$option = $value;
 
32
 } 
 
33
 
 
34
 function SetOptions($options) {
 
35
    foreach ($options as $opt => &$value) {
 
36
        $this->$opt = $value;
 
37
    }
 
38
 }
 
39
 
 
40
 function rewind() {
 
41
    if (!$this->ids) throw new ADEIException("Internal application error (MASK should be created using CACHE call)");
 
42
 
 
43
    $list = "";
 
44
    foreach ($this->ids as $id) {
 
45
        $list .= "v$id AS v$id, ";
 
46
    }   
 
47
 
 
48
    $table = $this->cache->GetTableName(0, $this->postfix);
 
49
 
 
50
    $sql = $this->ivl->GetSQL($this->cache, $this->limit, $this->use_subseconds);
 
51
    $list .= $sql['list'];
 
52
    $cond = &$sql['cond'];
 
53
    $sort = &$sql['sort'];
 
54
    $limit = &$sql['limit'];
 
55
 
 
56
    $this->res = mysql_query("SELECT $list FROM `$table` $cond $sort $limit", $this->cache->dbh);
 
57
 
 
58
    if (!$this->res)
 
59
        throw new ADEIException("SELECT request '$list $cond $sort $limit'  on CACHE table '$table' is failed...");
 
60
 
 
61
    $this->next();
 
62
 }
 
63
 
 
64
 function current() {
 
65
    return $this->row;
 
66
 }
 
67
 
 
68
 function key() {
 
69
    return $this->key;
 
70
 }
 
71
 
 
72
 function next() {
 
73
    $this->row = mysql_fetch_row($this->res);
 
74
    if ($this->row) {
 
75
 
 
76
        $lastkey = sizeof($this->row) - 1;
 
77
        if ($this->use_subseconds) {
 
78
            $ns = $this->row[$lastkey];
 
79
            
 
80
            $extra = (9 - strlen($ns));
 
81
            if ($extra) $ns = str_repeat('0', $extra) . $ns;
 
82
                
 
83
            $this->key = $this->row[$lastkey-1] . ".$ns";
 
84
            unset($this->row[$lastkey]);
 
85
            unset($this->row[$lastkey-1]);
 
86
        } else {
 
87
            $this->key = $this->row[$lastkey];
 
88
            unset($this->row[$lastkey]);
 
89
        }
 
90
    } else {
 
91
        $this->key = false;
 
92
        mysql_free_result($this->res);
 
93
    }
 
94
 }
 
95
 
 
96
 function valid() {
 
97
    return $this->row?true:false;
 
98
 }
 
99
}
 
100
 
 
101
?>
 
 
b'\\ No newline at end of file'