Revision 53f41060
Added by Lorna Morris over 11 years ago
7.x/modules/dwca_export_views/dwca_export_views.module | ||
---|---|---|
52 | 52 |
); |
53 | 53 |
|
54 | 54 |
foreach($allviews as $view){ |
55 |
// select only the views that are prefixed with dwca_export for the form |
|
55 | 56 |
if(substr($view->name, 0, 11) == 'dwca_export' && substr($view->name, 0, 23) != 'dwca_export_description'){ |
56 | 57 |
|
57 | 58 |
$dwca_filename = $view->name; |
... | ... | |
75 | 76 |
print_r(t('key ') . $key . t('key ') . $value); |
76 | 77 |
}*/ |
77 | 78 |
//$meta_string = file_get_contents('http://www.google.com/'); |
78 |
//drupal_set_message(t('The meta xml is ') . $meta_string);
|
|
79 |
//drupal_set_message(t('The meta - is ') . $meta_string);
|
|
79 | 80 |
//print_r($meta_string); |
80 | 81 |
return $views; |
81 | 82 |
} |
... | ... | |
106 | 107 |
|
107 | 108 |
//TODO create an array containing the terms for the core and each extension |
108 | 109 |
|
109 |
|
|
110 |
|
|
111 |
//create a 2D array so that each extension or view name points to an array of terms |
|
112 |
$meta_string = simplexml_load_file(drupal_get_path('module', 'dwca_export') . '/static/meta.xml'); |
|
113 |
//simplexml_load_string() |
|
114 |
//archive |
|
115 |
/////////////////////////echo $meta_string->getName() . "<br />"; |
|
116 |
|
|
117 |
$core_string = $meta_string->core->files->location[0]; |
|
118 |
$classification_view_name = "dwca_export_" . substr($core_string, 0, -4); |
|
119 |
echo $classification_view_name; |
|
120 |
|
|
121 |
$views = array(); |
|
122 |
//the first postion in the dwca is always the id and this doesn't point to a term so use the empty string |
|
123 |
$views[$classification_view_name][0] = ''; |
|
124 |
|
|
125 |
foreach($meta_string->core->field as $field) |
|
126 |
{ |
|
127 |
$term = (string)$field[@term]; |
|
128 |
|
|
129 |
//$views[$classification_view_name][$term_array] = array($term); |
|
130 |
$views[$classification_view_name][] = $term; |
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
} |
|
135 |
print_r(t('TEH VIEWS ARRAY') . $views["dwca_export_classification"][1] . t('end')); |
|
136 |
|
|
137 |
foreach($meta_string->extension as $extension) |
|
138 |
{ |
|
139 |
//echo $extension->files->location[0] . "\n"; |
|
140 |
$extension_string = $extension->files->location[0] . "\n"; |
|
141 |
|
|
142 |
$extension_view_name = "dwca_export_" . substr($extension_string, 0, -5); |
|
143 |
echo "The ext view name is:" . $extension_view_name . "\n"; |
|
144 |
$views[$extension_view_name][0] = ''; |
|
145 |
|
|
146 |
foreach($extension->field as $field) |
|
147 |
{ |
|
148 |
$term = (string)$field[@term]; |
|
149 |
$views[$extension_view_name][] = $term; |
|
150 |
//echo $field[@term] . "\n"; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
foreach($meta_string->children() as $child) |
|
155 |
{ |
|
156 |
// core or extension |
|
157 |
//echo $child->getName() . ": " . $child . "<br />"; |
|
158 |
|
|
159 |
//foreach($child->children() as $child2) |
|
160 |
//{ |
|
161 |
// core or extension |
|
162 |
//echo $child2->getName() . ": " . $child2 . "<br />"; |
|
163 |
//} |
|
164 |
|
|
165 |
|
|
166 |
} |
|
167 |
//$result = $meta_string->xpath("//archive/core/files/location"); |
|
168 |
//foreach ($result_array as ) |
|
110 |
$views = _dwca_export_views_meta_xml_map(); |
|
169 | 111 |
|
170 | 112 |
$count = 0; |
171 | 113 |
$savedvariables = variable_get('VIEWS_MAP'); |
... | ... | |
203 | 145 |
//display the field_keys as the names of each text box in this form |
204 | 146 |
//print_r($field_key . t(' FIELD LABEL') . $field_label); |
205 | 147 |
//drupal_set_message($field_key . t(' COUNT IS ZERO') . $field_label); |
148 |
|
|
149 |
drupal_set_message(t('value') . $value . t('value and field_index ') . $field_index); |
|
206 | 150 |
|
207 | 151 |
$form[$value][$field_key] = array( |
208 | 152 |
'#type' => 'textfield', |
... | ... | |
216 | 160 |
); |
217 | 161 |
|
218 | 162 |
$field_index++; |
163 |
} |
|
164 |
} |
|
165 |
$count++; |
|
166 |
return $form; |
|
167 |
} |
|
168 |
|
|
169 |
function _dwca_export_views_meta_xml_update($field_term_map){ |
|
170 |
|
|
171 |
//convert the field_term_map to an array of terms. The order of the terms corresponds to the |
|
172 |
//order in the meta.xml. We don't need the keys (view field names) |
|
173 |
|
|
174 |
$term_array = array(); |
|
175 |
|
|
176 |
foreach ($field_term_map as $key => $value) { |
|
177 |
$term_array[] = $value; |
|
178 |
} |
|
179 |
|
|
180 |
//check if the array size is the same as the number of fields in the meta.xml for either the |
|
181 |
//core or the particular extension |
|
182 |
|
|
183 |
//if the view has more fields than the default meta.xml we can add a node to the meta.xml |
|
184 |
|
|
185 |
//if the view has less fields we could either leave them blank e.g. <field index="21" term=""/> |
|
186 |
//or simply remove them |
|
187 |
|
|
188 |
$xml_file = drupal_get_path('module', 'dwca_export') . '/static/meta.xml'; |
|
189 |
$meta_string = simplexml_load_file($xml_file); |
|
190 |
|
|
191 |
$meta_string->core->files->location[0] = 'classification.txt'; |
|
192 |
|
|
193 |
$core_string = $meta_string->core->files->location[0]; |
|
194 |
$classification_view_name = "dwca_export_" . substr($core_string, 0, -4); |
|
195 |
//echo $classification_view_name; |
|
196 |
echo "Theclassviewnameis:" . $classification_view_name . "\n"; |
|
197 |
drupal_set_message(t(' THE class view name is ') . $classification_view_name); |
|
198 |
|
|
199 |
//the first postion in the dwca is always the id and this doesn't point to a term so use the empty string |
|
200 |
$views[$classification_view_name][0] = ''; |
|
201 |
|
|
202 |
//set the core node of the meta.xml with dwca_export_classifcation values from the form |
|
203 |
//currently we're relying on the order of fields in the view corresponding to the order of fields in the meta.xml |
|
204 |
|
|
205 |
//in the meta.xml id index="0" fields start at index 1 |
|
206 |
$index = 1; |
|
207 |
|
|
208 |
foreach($meta_string->core->field as $field) |
|
209 |
{ |
|
210 |
$term = (string)$field[@term]; |
|
211 |
drupal_set_message(t(' THE META STRING TERM IS ') . $term); |
|
212 |
$term = 'hello'; |
|
213 |
//$field[@term] = 'goodbye'; |
|
214 |
$field[@term] = $field_term_map['name_1']; |
|
215 |
$field[@term] = $term_array[$index]; |
|
216 |
$index++; |
|
217 |
//$views[$classification_view_name][] = $term; |
|
218 |
} |
|
219 |
|
|
220 |
foreach($meta_string->extension as $extension) |
|
221 |
{ |
|
222 |
//echo $extension->files->location[0] . "\n"; |
|
223 |
$extension_string = $extension->files->location[0] . "\n"; |
|
224 |
|
|
225 |
$extension_view_name = "dwca_export_" . substr($extension_string, 0, -5); |
|
226 |
//echo "The ext view name is:" . $classification_view_name . "\n"; |
|
227 |
drupal_set_message(t(' THE ext view name is ') . $extension_view_name); |
|
228 |
echo "Theclassviewnameis:" . $classification_view_name . "\n"; |
|
229 |
$views[$extension_view_name][0] = ''; |
|
230 |
|
|
231 |
foreach($extension->field as $field) |
|
232 |
{ |
|
233 |
$term = (string)$field[@term]; |
|
234 |
$views[$extension_view_name][] = $term; |
|
219 | 235 |
} |
220 |
|
|
221 | 236 |
} |
222 |
$count++; |
|
237 |
|
|
238 |
// Saving the whole modified XML to a new filename |
|
239 |
//$meta_string->asXml('updated.xml'); |
|
240 |
$meta_string->asXml($xml_file); |
|
223 | 241 |
|
224 |
return $form; |
|
242 |
drupal_set_message(t('UPDATE THE META XML file WITH THE VALUES COLLECTED: <pre>@result</pre>', array('@num' => 1, '@result' => print_r($field_term_map, TRUE)))); |
|
243 |
} |
|
244 |
|
|
245 |
//TODO Lorna - could we modify this method with a boolean to indicate whether we want to create the map or whether we want to modify the xml with values in the map |
|
246 |
function _dwca_export_views_meta_xml_map(){ |
|
247 |
|
|
248 |
//TODO: Should we store the map in the database so we don't need to keep reading in the XML file? |
|
249 |
//static $file_map; |
|
250 |
//if(!isset($file_map)){ |
|
251 |
//$file_map = variable_get(FILE_MAP); |
|
252 |
//} |
|
253 |
$views = array(); |
|
254 |
|
|
255 |
//create a 2D array so that each extension or view name points to an array of terms |
|
256 |
$meta_string = simplexml_load_file(drupal_get_path('module', 'dwca_export') . '/static/meta.xml'); |
|
257 |
//simplexml_load_string() |
|
258 |
|
|
259 |
$core_string = $meta_string->core->files->location[0]; |
|
260 |
$classification_view_name = "dwca_export_" . substr($core_string, 0, -4); |
|
261 |
echo $classification_view_name; |
|
262 |
|
|
263 |
//the first postion in the dwca is always the id and this doesn't point to a term so use the empty string |
|
264 |
$views[$classification_view_name][0] = ''; |
|
265 |
|
|
266 |
foreach($meta_string->core->field as $field) |
|
267 |
{ |
|
268 |
$term = (string)$field[@term]; |
|
269 |
|
|
270 |
//$views[$classification_view_name][$term_array] = array($term); |
|
271 |
$views[$classification_view_name][] = $term; |
|
272 |
|
|
273 |
} |
|
274 |
|
|
275 |
foreach($meta_string->extension as $extension) |
|
276 |
{ |
|
277 |
//echo $extension->files->location[0] . "\n"; |
|
278 |
$extension_string = $extension->files->location[0] . "\n"; |
|
279 |
|
|
280 |
$extension_view_name = "dwca_export_" . substr($extension_string, 0, -5); |
|
281 |
//echo "The ext view name is:" . $extension_view_name . "\n"; |
|
282 |
$views[$extension_view_name][0] = ''; |
|
283 |
|
|
284 |
foreach($extension->field as $field) |
|
285 |
{ |
|
286 |
$term = (string)$field[@term]; |
|
287 |
$views[$extension_view_name][] = $term; |
|
288 |
} |
|
289 |
} |
|
290 |
|
|
291 |
foreach($meta_string->children() as $child) |
|
292 |
{ |
|
293 |
// core or extension |
|
294 |
//echo $child->getName() . ": " . $child . "<br />"; |
|
295 |
|
|
296 |
//foreach($child->children() as $child2) |
|
297 |
//{ |
|
298 |
// core or extension |
|
299 |
//echo $child2->getName() . ": " . $child2 . "<br />"; |
|
300 |
//} |
|
301 |
|
|
302 |
|
|
303 |
} |
|
304 |
//$result = $meta_string->xpath("//archive/core/files/location"); |
|
305 |
//foreach ($result_array as ) |
|
306 |
|
|
307 |
return $views; |
|
225 | 308 |
} |
226 | 309 |
|
227 | 310 |
function dwca_export_views_wizard($form, &$form_state) { |
... | ... | |
385 | 468 |
unset($value['stored_values']['form_id']); |
386 | 469 |
unset($value['stored_values']['form_build_id']); |
387 | 470 |
unset($value['stored_values']['form_token']); |
471 |
|
|
472 |
|
|
473 |
//drupal_set_message(t('INFO COLLECTED @result'), array('@result' => print_r($value['stored_values'], TRUE))); |
|
474 |
|
|
388 | 475 |
|
389 | 476 |
// Now show all the values. |
390 |
drupal_set_message(t('Step @num collected the following values: <pre>@result</pre>', array('@num' => $index, '@result' => print_r($value['stored_values'], TRUE)))); |
|
477 |
if ($index == 2) { |
|
478 |
_dwca_export_views_meta_xml_update($value['stored_values']); |
|
479 |
//drupal_set_message(t('Step @num collected the following values: <pre>@result</pre>', array('@num' => $index, '@result' => print_r($value['stored_values'], TRUE)))); |
|
391 | 480 |
} |
392 | 481 |
} |
482 |
} |
|
393 | 483 |
|
394 | 484 |
|
Also available in: Unified diff
Added method to modify meta.xml based on user input.