/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to classes/readers/cachereader.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
class CACHEReader extends READER {
 
4
 var $cache;
 
5
 
 
6
 function __construct(&$props, CACHEDB &$cache = NULL) {
 
7
    parent::__construct($props);
 
8
    if ($cache) $this->cache = &$cache;
 
9
    else {
 
10
        if ($props instanceof SOURCERequest)
 
11
            $this->cache = new CACHEDB($props);
 
12
        else
 
13
            $this->cache = NULL;
 
14
    }
 
15
 }
 
16
 
 
17
 function GetGroupInfo(LOGGROUP &$grp = NULL, $flags = 0) {
 
18
    $groups = array();
 
19
 
 
20
    $res = $this->cache->ListCachedGroups();
 
21
    foreach ($res as $gid) {
 
22
        if (($grp)&&(strcmp($grp->gid, $gid))) continue;
 
23
 
 
24
        $groups[$gid] = array(
 
25
            'gid' => $gid,
 
26
            'name' => $gid
 
27
        );
 
28
 
 
29
        if ($flags&READER::NEED_INFO) {
 
30
            $postfix = $this->cache->GetCachePostfix($gid);
 
31
            
 
32
            $flags = 0;
 
33
            if ($flags&READER::NEED_COUNT) $flags |= CACHEDB::NEED_COUNT;
 
34
            $info = $this->cache->GetCacheInfo($postfix, $flags);
 
35
 
 
36
            if (!$info)
 
37
                throw new ADEIException(translate("The CACHE for group (%s) is empty", $grp->gid));
 
38
 
 
39
            foreach ($info as $key => &$value) {
 
40
                $groups[$gid][$key] = $value;
 
41
            }
 
42
            
 
43
            if ($flags&READER::NEED_ITEMINFO) {
 
44
                $groups[$gid]['items'] = $this->cache->GetCacheItemList($postfix);
 
45
            }
 
46
        }
 
47
    }
 
48
 
 
49
    return $grp?$groups[$grp->gid]:$groups;
 
50
 }
 
51
 
 
52
 function GetItemList(LOGGROUP &$grp = NULL, MASK &$mask = NULL, $flags = 0) {
 
53
    $grp = $this->CheckGroup($grp);
 
54
 
 
55
    $postfix = $this->cache->GetCachePostfix($grp->gid);
 
56
    if (!$mask) $mask = $this->CreateMask($grp);
 
57
 
 
58
    return $this->cache->GetCacheItemList($postfix, $mask, 0);
 
59
 }
 
60
 
 
61
 function GetData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
 
62
    $grp = $this->CheckGroup($grp);
 
63
 
 
64
    $postfix = $this->cache->GetCachePostfix($grp->gid);
 
65
 
 
66
    $ivl = $this->CreateInterval($grp);
 
67
    $ivl->Limit($from, $to);
 
68
 
 
69
    $mask = NULL;
 
70
 
 
71
    return $this->cache->GetCachePoints($postfix, $mask, $ivl, CACHEDB::TYPE_ALL);
 
72
 }
 
73
 
 
74
 function HaveData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
 
75
    $grp = $this->CheckGroup($grp);
 
76
 
 
77
    $postfix = $this->cache->GetCachePostfix($grp->gid);
 
78
 
 
79
    $ivl = $this->CreateInterval($grp);
 
80
    $ivl->Limit($from, $to);
 
81
 
 
82
    $mask = NULL;
 
83
 
 
84
    $points = $this->cache->GetCachePoints($postfix, $mask, $ivl, CACHEDB::TYPE_ALL, 1);
 
85
 
 
86
    $points->rewind();
 
87
    return $points->valid();
 
88
 }
 
89
}
 
90
 
 
91
?>
 
 
b'\\ No newline at end of file'