-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboth.php
More file actions
92 lines (78 loc) · 1.71 KB
/
both.php
File metadata and controls
92 lines (78 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
function main() {
$fp = fopen(__FILE__ . '.csv', 'w');
foreach (table() as $row) {
fputcsv($fp, $row);
}
fclose($fp);
}
function table() {
return array_merge([headers()], body());
}
function headers() {
$total = total();
$first = "$total field instances in total";
return array_merge([$first], types());
}
function body() {
$rows = [];
foreach (fields() as $field) {
$rows[] = row($field);
}
return $rows;
}
function row($field) {
$cells = [$field];
foreach (types() as $type) {
$cells[] = (is_instance($field, $type) ? 'Y' : '');
}
return $cells;
}
function types() {
static $cache = false;
$cache = $cache ?: dimension('node_type', 'type', 'type_name');
return $cache;
}
function fields() {
return dimension('node_field', 'field_name');
}
function dimension($table, $field, $join = null) {
$join = $join ?: $field;
$field = "$table.$field";
$sql = "SELECT $field
FROM $table
INNER JOIN node_field_instance i ON $field = i.$join
GROUP BY $field
ORDER BY count(*) DESC, $field
";
return tbi_legacy_query($sql)->fetchCol();
}
function is_instance($field, $type) {
static $instances = false;
$instances = $instances ?: instances();
return isset($instances[$field][$type]);
}
function total() {
return results()->rowCount();
}
function instances() {
$instances = [];
while ($row = results()->fetchObject()) {
$instances[$row->field][$row->type] = true;
}
return $instances;
}
function results() {
static $cache = false;
$cache = $cache ?: query();
return $cache;
}
function query() {
$sql = SELECT
field_name AS field,
type_name AS type
FROM node_field_instance
';
return tbi_legacy_query($sql);
}
main();