function get_data_array() { global $dataFile, $dataCols, $fields, $lists, $docsCount, $biosCount; if (($handle = fopen($dataFile, "r")) === FALSE) { return array(); } $results = array(); $i = 0; while (($cols = fgetcsv($handle, 0, "\t")) !== FALSE) { $glData = array(); $row = array(); if ($cols && $cols[1]) { foreach ($cols as $key => $val) { $val = trim($val, '"'); $val = trim($val); $row[$key] = $val; $entityField = $dataCols[$key]; if ($entityField) { $ent = $entityField["ent"]; $list_code = $entityField['list_code']; $type = $entityField['field_type']; $mlt = trim($entityField['is_repeat']) == 'Y' || trim($entityField['is_repeat']) == 'y' ? true : false; if ($list_code == 39) { if ($val == "M") { $val == "Hombre"; } elseif ($val == "F") { $val == "Mujer"; } } if ($list_code && !$lists[$list_code]) { $options = array(); $data_array = MtFieldWrapper::getMTList($list_code); $size = count($data_array); for ($i = 0; $i < $size; $i++) { $options[$data_array[$i]['vocab_number']] = strtolower($data_array[$i]['label']); } $lists[$list_code] = $options; } if ($list_code) { if ($mlt) { $val2 = explode(";", $val); $val = array(); foreach ($val2 as $v) { $vocab_number = array_search(strtolower($v), $lists[$list_code]); if ($vocab_number) { $val[] = $vocab_number; } } } else { $vocab_number = array_search(strtolower($val), $lists[$list_code]); if ($vocab_number) { $val = $vocab_number; } else { $val = null; } } } if ($type == "date") { if ($val) { $d = date_create_from_format("m/d/Y", $val); if ($d) { $val = date_format($d, 'Y-m-d'); } else { $val = null; } } else { $val = null; } } elseif ($type == "location") { $val2 = explode(",", $val); //$row[$entityField['field_name'] . "_latitude"] = -floatval($val2[0]); //$row[$entityField['field_name'] . "_longitude"] = -floatval($val2[1]); $glData[$ent][$entityField['field_name'] . "_latitude"] = -floatval($val2[0]); $glData[$ent][$entityField['field_name'] . "_longitude"] = -floatval($val2[1]); $val = null; } elseif ($type == "radio") { if ($val == "NO") { $val = "n"; } elseif ($val == "SÍ") { $val = "y"; } else { $val = null; } } if ($val) { //$row[$entityField['field_name']] = $val; $glData[$ent][$entityField['field_name']] = $val; } } } //var_dump($glData);exit; $browse = new Browse(); $rows = $browse->ExecuteQuery("select event_record_number as id from event where event_title='" . $glData['event']['event_title'] . "'"); if ($rows && $rows[0]['id']) { $event = new Event(); $event->LoadFromRecordNumber($rows[0]['id']); $event->LoadRelationships(); } else { continue; } if ($event->supporting_documents) { $supporting_documents = $event->supporting_documents; } else { $supporting_documents = array(); } for ($j = 1; $j <= $docsCount; $j++) { if ($glData["supporting_docs_meta" . $j]) { if (!$glData["supporting_docs_meta" . $j]['title']) { continue; } $document_form = document_form('new'); unset($document_form['doc_id']); $supporting_docs = new SupportingDocs(); $supporting_docs_meta = new SupportingDocsMeta(); $type = null; $doc_uuid = shn_create_uuid('doc'); $supporting_docs->doc_id = $doc_uuid; $supporting_docs_meta->doc_id = $doc_uuid; $supporting_docs->uri = ''; form_objects($document_form, $supporting_docs, $glData["supporting_docs_meta" . $j]); form_objects($document_form, $supporting_docs_meta, $glData["supporting_docs_meta" . $j]); $supporting_docs_meta->format = $type; $supporting_docs->Save(); $supporting_docs_meta->SaveAll(); $supporting_documents[] = $doc_uuid; } } if ($supporting_documents) { $event->supporting_documents = $supporting_documents; $event->SaveDocs(); } } $results[] = $row; $i++; } return $results; }