1
|
|
|
<?php |
|
|
|
|
2
|
|
|
include_once($this->code."stores/modules/mysql_compiler.php"); |
3
|
|
|
|
4
|
|
|
class mysql_workspaces_compiler extends mysql_compiler { |
5
|
|
|
|
6
|
47 |
|
public function __construct (&$store, $tbl_prefix="") { |
7
|
47 |
|
debug("mysql_workspaces_compiler($tbl_prefix)", "store"); |
8
|
47 |
|
$this->tbl_prefix=$tbl_prefix; |
9
|
47 |
|
$this->store=$store; |
10
|
47 |
|
} |
11
|
|
|
|
12
|
|
|
// mysql specific compiler function |
13
|
47 |
|
protected function priv_sql_compile($tree) { |
14
|
47 |
|
$this->custom_ref = 0; |
15
|
47 |
|
$this->custom_id = 0; |
16
|
47 |
|
$this->used_tables=""; |
17
|
47 |
|
$this->compile_tree($tree); |
18
|
47 |
|
$nodes=$this->tbl_prefix."nodes"; |
19
|
47 |
|
$objects=$this->tbl_prefix."objects"; |
20
|
47 |
|
$properties=$this->tbl_prefix."prop_"; |
21
|
47 |
|
$this->used_tables[$nodes]=$nodes; |
22
|
47 |
|
$this->used_tables[$objects]=$objects; |
23
|
47 |
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
|
47 |
|
@reset($this->used_tables); |
|
|
|
|
28
|
47 |
|
while (list($key, $val)=each($this->used_tables)) { |
29
|
47 |
|
if ($tables) { |
30
|
47 |
|
$tables.=", $key"; |
|
|
|
|
31
|
47 |
|
} else { |
32
|
47 |
|
$tables="$key"; |
33
|
|
|
} |
34
|
47 |
View Code Duplication |
if ($this->select_tables[$key]) { |
35
|
46 |
|
if ($this->join_target_properties[$key]) { |
36
|
|
|
$prop_dep.=" and $val.object=target.object "; |
|
|
|
|
37
|
|
|
} else { |
38
|
46 |
|
$prop_dep.=" and $val.object=$objects.id "; |
39
|
|
|
} |
40
|
46 |
|
} |
41
|
47 |
|
} |
42
|
|
|
|
43
|
47 |
|
$join = ""; |
44
|
47 |
|
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
|
47 |
|
$query = " where $nodes.object=$objects.id $prop_dep"; |
54
|
47 |
|
$query .= " and $nodes.path like '".str_replace('_','\\_',AddSlashes($this->path))."%' "; |
55
|
|
|
|
56
|
|
|
|
57
|
47 |
|
$query_string_layers = ""; |
58
|
47 |
|
$layering = false; |
59
|
47 |
|
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
|
47 |
|
} |
68
|
47 |
|
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
|
47 |
|
$query .= " and $nodes.layer = 0 "; |
83
|
|
|
} |
84
|
|
|
|
85
|
47 |
|
if ($this->where_s) { |
86
|
47 |
|
$query.=" and ( $this->where_s ) "; |
87
|
47 |
|
} |
88
|
47 |
|
if ($this->where_s_ext) { |
89
|
|
|
$query .= " and ($this->where_s_ext) "; |
90
|
|
|
} |
91
|
|
|
/* do target join */ |
92
|
47 |
|
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
|
47 |
|
if ($this->orderby_s) { |
98
|
|
|
$orderby = " order by $this->orderby_s, $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
99
|
|
|
} else { |
100
|
47 |
|
$orderby = " order by $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
101
|
|
|
} |
102
|
|
|
|
103
|
47 |
|
$select_query = "select distinct($nodes.path), $nodes.id as nodeId, $nodes.layer as nodeLayer, $nodes.parent, $nodes.priority, "; |
104
|
47 |
|
$select_query .= "$objects.object, $objects.id, $objects.type, $objects.vtype, "; |
105
|
47 |
|
$select_query .= "UNIX_TIMESTAMP($objects.lastchanged) as lastchanged "; |
106
|
47 |
|
$select_query .= "from ($tables) $join $query "; |
107
|
47 |
|
$select_query .= $orderby." ".$this->limit_s; |
108
|
|
|
|
109
|
47 |
|
$count_query = "select count(distinct($objects.id)) as count from $tables ".$query; |
110
|
|
|
|
111
|
|
|
return array( |
112
|
47 |
|
"select_query" => $select_query, |
113
|
|
|
"count_query" => $count_query |
114
|
47 |
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.