/adei/trunk

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

« back to all changes in this revision

Viewing changes to classes/filters/itemfilter.php

  • Committer: Suren A. Chilingaryan
  • Date: 2019-10-09 21:31:25 UTC
  • Revision ID: csa@suren.me-20191009213125-hf6ddjp9smzowwla
Enable ITEMFilter with both masking and non-masking READERs

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 var $skip;
8
8
 var $filter;
9
9
 var $indexes;
10
 
 
11
 
 var $check_masked;
12
 
 
 
10
 var $indexes_full;
 
11
 var $indexes_masked;
 
12
 
13
13
 function __construct(READER $rdr, LOGGROUP $grp, DATAFilter $filter, &$opts = NULL) {
14
14
    if ($rdr instanceof CACHEReader) $this->skip = true;
15
15
    else {
24
24
                throw new ADEIException(translate("Unsupported item filter is configured: \"%s\"", $filter_class));
25
25
        }
26
26
            
 
27
 
27
28
        $this->filter = new $filter_class($opts);
28
29
        
29
30
        $mask = $filter->GetItemMask();
30
31
        
31
 
        if (($mask)&&(!$mask->IsFull())) $this->check_masked = true;
32
 
        else $this->check_masked = false;
33
 
        
34
32
        if (isset($opts['item_mask'])) {
35
 
 
36
 
            $this->indexes = array();
37
33
            $key = array(); $re = array();
38
34
            if (is_array($opts['item_mask'])) {
39
35
                if (is_array($opts['item_mask'][0])) {
42
38
                    $checks = array($opts['item_mask']);
43
39
                }
44
40
            } else {
45
 
                $re = $opts['item_mask'];
46
 
                if ($mask) {
47
 
                    $checks = false; 
48
 
                    $i = 0;
49
 
                    foreach ($mask->ids as $id) {
50
 
                        if (preg_match($re, $id)) $this->indexes[$i] = $id;
51
 
                        $i++;
52
 
                    }
53
 
                } else {
54
 
                    $checks = array(array(
55
 
                        "key" => id,
56
 
                        "items" => $re
57
 
                    ));
58
 
                }
 
41
                    // Just a regexp of numeric ids
 
42
                $checks = $opts['item_mask'];
59
43
            }
60
44
 
 
45
            $this->indexes_masked = array();
 
46
            $this->indexes_full = array();
 
47
 
61
48
            if ($checks) {
62
 
                $items = $rdr->GetItemList($grp, ($mask?$mask:new MASK()));
63
 
                $i = 0;
 
49
                $skip_full = false;
 
50
                if (is_array($checks)) {
 
51
                    $items = $rdr->GetItemList($grp, new MASK());
 
52
                } else {
 
53
 
 
54
                    if (($opts['masking_reader'])&&($mask)&&(!$mask->IsFull())) {
 
55
                        $skip_full = true;
 
56
                        $items = $mask->GetIDs();
 
57
                    } else {
 
58
                        $items = range(0, $rdr->GetGroupSize($grp) - 1);
 
59
                    }
 
60
                }
 
61
 
 
62
                $i = 0; $j = 0;
64
63
                foreach ($items as &$item) {
65
 
                    $matched = true;
66
 
                    foreach ($checks as $check) {
67
 
                        if (!preg_match($check['items'], $item[$check['key']])) {
68
 
                            $matched = false;
69
 
                            break;
 
64
                    if (is_array($checks)) {
 
65
                        $id = $item["id"];
 
66
 
 
67
                        $matched = true;
 
68
                        foreach ($checks as $check) {
 
69
                            if (!preg_match($check['items'], $item[$check['key']])) {
 
70
                                $matched = false;
 
71
                                break;
 
72
                            }
70
73
                        }
71
 
                    }
72
 
                    if ($matched) $this->indexes[$i] = $item["id"];
 
74
                    } else {
 
75
                        $id = $item;
 
76
                        $matched = preg_match($checks, $item);
 
77
                    }
 
78
    
 
79
                    if ((!$mask)||($mask->Check($i))) {
 
80
                        if ($matched) $this->indexes_masked[$j] = $id;
 
81
                        $j++;
 
82
                    }
 
83
                    if ($matched) $this->indexes_full[$i] = $id;
73
84
                    $i++;
74
85
                }
 
86
                
 
87
                if ($skip_full) {
 
88
                    $this->indexes_masked = $this->indexes_full;
 
89
                    $this->indexes_full = false;
 
90
                }
75
91
            }
76
 
        } else if (($mask)&&(!$mask->IsFull())) {
77
 
            $this->indexes = $mask->ids;
78
92
        } else {
79
 
            $this->indexes = range(0, $rdr->GetGroupSize($grp) - 1);
 
93
                // Avoid calling GetGroupSize (involves requires to Source Database)
 
94
            if (($opts['masking_reader'])&&($mask)&&(!$mask->IsFull())) {
 
95
                $this->index_full = false;
 
96
                $this->indexes_masked = $mask->GetIDs();
 
97
            } else {
 
98
                $this->indexes_full = range(0, $rdr->GetGroupSize($grp) - 1);
 
99
                if (($mask)&&(!$mask->IsFull())) $this->indexes_masked = $mask->ids;
 
100
                else $this->indexes_masked = $this->indexes_full;
 
101
            }
80
102
        }
81
103
    }
82
104
 }
84
106
 function Start(&$data) {
85
107
    if ($this->skip) return;
86
108
 
87
 
    if (($this->check_masked)&&(!$data['masked']))
88
 
        throw new ADEIException(translate("ITEMFilter can't be executed on unmasked data..."));
 
109
    if ($data['masked']) {
 
110
        if ($this->indexes_masked === false)
 
111
            throw new ADEIException(translate("ITEMFilter is not configured for masked data..."));
 
112
        $this->indexes = $this->indexes_masked;
 
113
    } else {
 
114
        if ($this->indexes_full === false)
 
115
            throw new ADEIException(translate("ITEMFilter is not configured for unmasked data..."));
 
116
        $this->indexes = $this->indexes_full;
 
117
    }
 
118
 
89
119
 }
90
120
 
91
121
 function ProcessVector(&$data, &$time, &$values) {