1
|
|
|
<?php |
2
|
|
|
include_once($this->code."stores/modules/mysql_compiler.php"); |
3
|
|
|
|
4
|
|
|
class mysql_workspaces_compiler extends mysql_compiler { |
5
|
|
|
|
6
|
|
|
public function __construct (&$store, $tbl_prefix="") { |
7
|
|
|
debug("mysql_workspaces_compiler($tbl_prefix)", "store"); |
8
|
|
|
$this->tbl_prefix=$tbl_prefix; |
9
|
|
|
$this->store=$store; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
// mysql specific compiler function |
13
|
|
|
protected function priv_sql_compile($tree) { |
14
|
|
|
$this->custom_ref = 0; |
15
|
|
|
$this->custom_id = 0; |
16
|
|
|
$this->used_tables=array(); |
17
|
|
|
$this->compile_tree($tree); |
18
|
|
|
$nodes=$this->tbl_prefix."nodes"; |
19
|
|
|
$objects=$this->tbl_prefix."objects"; |
20
|
|
|
$properties=$this->tbl_prefix."prop_"; |
21
|
|
|
$this->used_tables[$nodes]=$nodes; |
22
|
|
|
$this->used_tables[$objects]=$objects; |
23
|
|
View Code Duplication |
if ($this->join_target_properties) { |
|
|
|
|
24
|
|
|
$this->used_tables[$properties."references as target_reference"] = $properties."references as target_reference"; |
25
|
|
|
$this->used_tables["$nodes as target"] = "$nodes as target"; |
26
|
|
|
} |
27
|
|
|
@reset($this->used_tables); |
28
|
|
|
while (list($key, $val)=each($this->used_tables)) { |
29
|
|
|
if ($tables) { |
30
|
|
|
$tables.=", $key"; |
|
|
|
|
31
|
|
|
} else { |
32
|
|
|
$tables="$key"; |
33
|
|
|
} |
34
|
|
View Code Duplication |
if ($this->select_tables[$key]) { |
35
|
|
|
if ($this->join_target_properties[$key]) { |
36
|
|
|
$prop_dep.=" and $val.object=target.object "; |
|
|
|
|
37
|
|
|
} else { |
38
|
|
|
$prop_dep.=" and $val.object=$objects.id "; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$join = ""; |
44
|
|
|
if (is_array($this->nls_join)) { |
45
|
|
|
reset($this->nls_join); |
46
|
|
|
while (list($key, $value)=each($this->nls_join)) { |
|
|
|
|
47
|
|
|
$join .= $value; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
$query = " where $nodes.object=$objects.id $prop_dep"; |
54
|
|
|
$query .= " and $nodes.path like '".str_replace('_','\\_',AddSlashes($this->path))."%' "; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
$query_string_layers = ""; |
58
|
|
|
$layering = false; |
59
|
|
|
foreach ($this->layers as $lPath => $lId) { |
|
|
|
|
60
|
|
|
if ($lId) { |
61
|
|
|
$layering = true; |
62
|
|
|
if ($query_string_layers) { |
63
|
|
|
$query_string_layers .= " OR "; |
64
|
|
|
} |
65
|
|
|
$query_string_layers .= " ( $nodes.path like '".AddSlashes($lPath)."%' and $nodes.layer = ".((int)$lId)." ) "; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
if ($layering) { |
69
|
|
|
$query .= " and ( |
70
|
|
|
( $query_string_layers ) |
71
|
|
|
OR |
72
|
|
|
$nodes.layer = 0 |
73
|
|
|
and $nodes.id NOT IN ( |
74
|
|
|
select $nodes.id from $nodes where ( $query_string_layers ) |
75
|
|
|
) |
76
|
|
|
and $nodes.path NOT IN ( |
77
|
|
|
select $nodes.path from $nodes where ( $query_string_layers ) |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
"; |
81
|
|
|
} else { |
82
|
|
|
$query .= " and $nodes.layer = 0 "; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($this->where_s) { |
86
|
|
|
$query.=" and ( $this->where_s ) "; |
87
|
|
|
} |
88
|
|
|
if ($this->where_s_ext) { |
89
|
|
|
$query .= " and ($this->where_s_ext) "; |
90
|
|
|
} |
91
|
|
|
/* do target join */ |
92
|
|
|
if ($this->join_target_properties) { |
|
|
|
|
93
|
|
|
$query .= " and $objects.id = target_reference.object "; |
94
|
|
|
$query .= " and target.path = target_reference.AR_path "; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if ($this->orderby_s) { |
98
|
|
|
$orderby = " order by $this->orderby_s, $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
99
|
|
|
} else { |
100
|
|
|
$orderby = " order by $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$select_query = "select distinct($nodes.path), $nodes.id as nodeId, $nodes.layer as nodeLayer, $nodes.parent, $nodes.priority, "; |
104
|
|
|
$select_query .= "$objects.object, $objects.id, $objects.type, $objects.vtype, "; |
105
|
|
|
$select_query .= "UNIX_TIMESTAMP($objects.lastchanged) as lastchanged "; |
106
|
|
|
$select_query .= "from ($tables) $join $query "; |
107
|
|
|
$select_query .= $orderby." ".$this->limit_s; |
108
|
|
|
|
109
|
|
|
$count_query = "select count(distinct($objects.id)) as count from $tables ".$query; |
110
|
|
|
|
111
|
|
|
return array( |
112
|
|
|
"select_query" => $select_query, |
113
|
|
|
"count_query" => $count_query |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.