|
@@ -45,6 +45,15 @@ function head() {
|
45
|
45
|
return $html;
|
46
|
46
|
}
|
47
|
47
|
|
|
48
|
+function displayColumn($columns) {
|
|
49
|
+ $names = array('name','title','description');
|
|
50
|
+ foreach ($names as $name) {
|
|
51
|
+ if (isset($columns[$name])) return $columns[$name];
|
|
52
|
+ }
|
|
53
|
+ return false;
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+
|
48
|
57
|
function referenceText($subject,$data,$field,$id,$definition) {
|
49
|
58
|
$properties = properties($subject,$definition);
|
50
|
59
|
$references = references($subject,$properties);
|
|
@@ -52,19 +61,25 @@ function referenceText($subject,$data,$field,$id,$definition) {
|
52
|
61
|
$primaryKey = primaryKey($subject,$properties);
|
53
|
62
|
|
54
|
63
|
$indices = array_flip($data[$subject]['columns']);
|
|
64
|
+ $displayColumn = displayColumn($indices);
|
|
65
|
+
|
55
|
66
|
$records = $data[$subject]['records'];
|
56
|
67
|
foreach ($records as $record) {
|
57
|
68
|
if ($record[$indices[$field]]==$id) {
|
58
|
|
- $text = '';
|
59
|
|
- $first = true;
|
60
|
|
- foreach ($record as $i=>$value) {
|
61
|
|
- if (!$references[$i] && $i!=$primaryKey) {
|
62
|
|
- if (!$first) $text.= ' - ';
|
63
|
|
- $text.= $value;
|
64
|
|
- $first = false;
|
65
|
|
- }
|
66
|
|
- }
|
67
|
|
- return $text;
|
|
69
|
+ if ($displayColumn===false) {
|
|
70
|
+ $text = '';
|
|
71
|
+ $first = true;
|
|
72
|
+ foreach ($record as $i=>$value) {
|
|
73
|
+ if (!$references[$i] && $i!=$primaryKey) {
|
|
74
|
+ if (!$first) $text.= ' - ';
|
|
75
|
+ $text.= $value;
|
|
76
|
+ $first = false;
|
|
77
|
+ }
|
|
78
|
+ }
|
|
79
|
+ return $text;
|
|
80
|
+ } else {
|
|
81
|
+ return $record[$indices[$displayColumn]];
|
|
82
|
+ }
|
68
|
83
|
}
|
69
|
84
|
}
|
70
|
85
|
return '?';
|
|
@@ -102,16 +117,16 @@ function listRecords($apiUrl,$subject,$field,$id,$definition) {
|
102
|
117
|
$html.= '</tr>';
|
103
|
118
|
foreach ($data[$subject]['records'] as $record) {
|
104
|
119
|
$html.= '<tr>';
|
105
|
|
- foreach ($record as $i=>$field) {
|
|
120
|
+ foreach ($record as $i=>$value) {
|
106
|
121
|
if ($references[$i]) {
|
107
|
122
|
$html.= '<td>';
|
108
|
|
- $href = '?action=list&subject='.$references[$i][0].'&field='.$references[$i][1].'&id='.$id;
|
|
123
|
+ $href = '?action=list&subject='.$references[$i][0].'&field='.$references[$i][1].'&id='.$value;
|
109
|
124
|
$html.= '<a href="'.$href.'">';
|
110
|
|
- $html.= referenceText($references[$i][0],$data,$references[$i][1],$field,$definition);
|
|
125
|
+ $html.= referenceText($references[$i][0],$data,$references[$i][1],$value,$definition);
|
111
|
126
|
$html.= '</a>';
|
112
|
127
|
$html.= '</td>';
|
113
|
128
|
} else {
|
114
|
|
- $html.= '<td>'.$field.'</td>';
|
|
129
|
+ $html.= '<td>'.$value.'</td>';
|
115
|
130
|
}
|
116
|
131
|
}
|
117
|
132
|
$html.= '<td>';
|
|
@@ -139,18 +154,26 @@ function selectSubject($apiUrl,$subject,$name,$value,$definition) {
|
139
|
154
|
$primaryKey = primaryKey($subject,$properties);
|
140
|
155
|
|
141
|
156
|
$data = apiCall('GET',$apiUrl.'/'.$subject);
|
142
|
|
- $html = '<select class="form-control">';
|
|
157
|
+
|
|
158
|
+ $indices = array_flip($data[$subject]['columns']);
|
|
159
|
+ $displayColumn = displayColumn($indices);
|
|
160
|
+
|
|
161
|
+ $html = '<select class="form-control">';
|
143
|
162
|
foreach ($data[$subject]['records'] as $record) {
|
144
|
|
- $text = '';
|
145
|
|
- $first = true;
|
146
|
|
- foreach ($record as $i=>$field) {
|
147
|
|
- if (!$references[$i] && $i!=$primaryKey) {
|
148
|
|
- if (!$first) $text.= ' - ';
|
149
|
|
- $text.= $field;
|
150
|
|
- $first = false;
|
151
|
|
- }
|
152
|
|
- }
|
153
|
|
- $html.= '<option value="'.$record[$primaryKey].'">'.$text.'</option>';
|
|
163
|
+ if ($displayColumn===false) {
|
|
164
|
+ $text = '';
|
|
165
|
+ $first = true;
|
|
166
|
+ foreach ($record as $i=>$field) {
|
|
167
|
+ if (!$references[$i] && $i!=$primaryKey) {
|
|
168
|
+ if (!$first) $text.= ' - ';
|
|
169
|
+ $text.= $field;
|
|
170
|
+ $first = false;
|
|
171
|
+ }
|
|
172
|
+ }
|
|
173
|
+ $html.= '<option value="'.$record[$primaryKey].'">'.$text.'</option>';
|
|
174
|
+ } else {
|
|
175
|
+ $html.= '<option value="'.$record[$primaryKey].'">'.$record[$displayColumn].'</option>';
|
|
176
|
+ }
|
154
|
177
|
}
|
155
|
178
|
$html.= '</select>';
|
156
|
179
|
return $html;
|