public function process(&$person_id, &$row_lines) { $ret = true; // every loop: update counter and start with empty record $this->persons->loadEmpty(); $this->persons->set('app_id', $this->app_id); $this->persons->set('id', $person_id); $event1Type = 'none'; $event2Type = 'none'; $event3Type = 'none'; $firstTimeNameTag = true; // admin settings $this->indLiving = true; unset($this->birthYear); unset($this->deathYear); // check whether a record exists with person id if ($this->persons->load()) { // record exists: existing record will be updated $ind_update = true; } else { // record does not exists: new record will be inserted $ind_update = false; } // spouses $spouseCounter = 0; // initialize names, events, notes, documents, citations, relations, spouses for this person // names $retdelete = $this->person_names->deleteNames($person_id); $this->person_names->loadEmpty(); $this->person_names->set('app_id', $this->app_id); $this->person_names->set('person_id', $person_id); $this->namePersonCounter = 0; $retdelete = $this->person_events->deleteEvents($person_id); $this->person_events->loadEmpty(); $this->person_events->set('app_id', $this->app_id); $this->person_events->set('person_id', $person_id); $this->eventPersonCounter = 0; // notes $retdelete = $this->person_notes->deleteNotes($person_id); $this->person_notes->loadEmpty(); $this->person_notes->set('app_id', $this->app_id); $this->person_notes->set('person_id', $person_id); $this->notePersonCounter = 0; // documents $retdelete = $this->person_docs_1->deleteDocuments($person_id); $this->documentPersonCounter = 0; // sources $retdelete = $this->person_citations->deletePersonCitations($person_id); $this->person_citations->loadEmpty(); $this->person_citations->set('app_id', $this->app_id); $this->person_citations->set('person_id_1', $person_id); $this->person_citations->set('person_id_2', 'EMPTY'); $this->citationPersonCounter = 0; // logs $this->logs->set('object_id', $person_id); // loop through lines related to the person foreach ($row_lines as $row_line_num => $row_line) { switch ($row_line['level']) { case "1": // set $information to be used for level 2 info $information = $row_line['tag']; switch ($information) { case "NAME": $event1Type = 'personName'; // extract first name and family name $names = explode("/", $row_line['value'], 3); if (!isset($names[0])) { $names[0] = null; } else { $names[0] = trim($names[0]); } if (!isset($names[1])) { $names[1] = null; } else { $names[1] = trim($names[1]); } if ($firstTimeNameTag) { // The first time the NAME tag is read -> this is the main name! if ($this->patronymSetting == 9) { // extract patronym from name field using patronymString-separation $tmpName = explode($this->patronymString, $names[0], 3); if (!isset($tmpName[0])) { $tmpName[0] = null; } else { $tmpName[0] = trim($tmpName[0]); } if (!isset($tmpName[1])) { $tmpName[1] = null; } else { $tmpName[1] = trim($tmpName[1]); } $this->persons->set('firstName', $tmpName[0]); $this->persons->set('patronym', $tmpName[1]); } else { $this->persons->set('firstName', $names[0]); } // set the familyName and namePreposition jt_names::setFamilyName($names[1], $this->persons, $this->familynameSetting); $firstTimeNameTag = false; } else { // concurrent NAME tags -> This are "also known as" names. $information = 'AKA'; if ($ret) { $ret = $this->setPersonName($information, $names[0] . ' ' . $names[1]); } } break; case "SEX": $event1Type = 'none'; $this->persons->set('sex', $row_line['value']); break; case "FAMS": $event1Type = 'none'; // FAMS is the family this person is a spouse // in this family a spouse can be found $spouseCounter++; if ($ret) { $ret = $this->spouse($person_id, rtrim(ltrim($row_line['value'], '@'), '@'), $spouseCounter); } break; case "FAMC": $event1Type = 'familyChild'; $family_id = trim($row_line['value'], '@'); break; case "BIRT": // do nothing // do nothing case "CHR": // do nothing // do nothing case "DEAT": if ($information == 'DEAT') { $this->indLiving = false; } case "BURI": if ($information == 'BURI') { $this->indLiving = false; } case "CREM": if ($information == 'CREM') { $this->indLiving = false; } //case "ADOP": // do nothing //case "ADOP": // do nothing case "BAPM": // do nothing // do nothing case "BARM": // do nothing // do nothing case "BASM": // do nothing // do nothing case "BLES": // do nothing // do nothing case "CHRA": // do nothing // do nothing case "CONF": // do nothing // do nothing case "FCOM": // do nothing // do nothing case "NATU": // do nothing // do nothing case "EMIG": // do nothing // do nothing case "IMMI": // do nothing // do nothing case "GRAD": // do nothing // do nothing case "RETI": // do nothing // do nothing case "EVEN": // do nothing // do nothing case "CAST": // do nothing // do nothing case "DSCR": // do nothing // do nothing case "EDUC": // do nothing // do nothing case "NATI": // do nothing // do nothing case "OCCU": // do nothing // do nothing case "RELI": // do nothing // do nothing case "RESI": // do nothing // do nothing case "_BRTM": if ($information == '_BRTM') { $information = 'BRTM'; } case "CIRC": if ($information == 'CIRC') { $information = 'BRTM'; } case "_YART": if ($information == '_YART') { $information = 'YART'; $this->indLiving = false; } case "TITL": $event1Type = 'personEvent'; if ($ret) { $ret = $this->setPersonEvent($information, $row_line['value']); } break; case "SOUR": // Source for person $event1Type = 'personSource'; $sourceKey = $this->getSourceKey($row_line['value']); if ($ret) { $ret = $this->setPersonCitation('person', $sourceKey); } if ($ret) { $this->persons->set('indCitation', true); } break; case "NOTE": // Note for person $event1Type = 'personNote'; if ($ret) { $ret = $this->setPersonNote('person', $row_line['value']); } if ($ret) { $this->persons->set('indNote', true); } break; case "OBJE": // Document for person $event1Type = 'personDocument'; if ($ret) { $ret = $this->setDocument($person_id, null, $row_line['value']); } break; case "CHAN": // changeDateTime $event1Type = 'changeDateTime'; break; default: $event1Type = 'none'; break; } break; case "2": if ($information == 'NAME' || $information == 'AKA') { // case "2": if ($information == 'NAME') { $nameTag = $row_line['tag']; switch ($nameTag) { case "GIVN": // do nothing // do nothing case "SURN": // do nothing // do nothing case "NICK": // do nothing // do nothing case "_ADPN": if ($nameTag == '_ADPN') { $nameTag = 'ADPN'; } case "_AKA": if ($nameTag == '_AKA') { $nameTag = 'AKA'; } case "_AKAN": if ($nameTag == '_AKAN') { $nameTag = 'AKA'; } case "_CALL": if ($nameTag == '_CALL') { $nameTag = 'AKA'; } case "AKA": // do nothing // do nothing case "_BIRN": if ($nameTag == '_BIRN') { $nameTag = 'BIRN'; } case "_CENN": if ($nameTag == '_CENN') { $nameTag = 'CENN'; } case "_CURN": if ($nameTag == '_CURN') { $nameTag = 'CURN'; } case "_FKAN": if ($nameTag == '_FKAN') { $nameTag = 'FRKA'; } case "_FRKA": if ($nameTag == '_FRKA') { $nameTag = 'FRKA'; } case "_HEBN": if ($nameTag == '_HEBN') { $nameTag = 'HEBN'; } case "_INDN": if ($nameTag == '_INDN') { $nameTag = 'INDG'; } case "_INDG": if ($nameTag == '_INDG') { $nameTag = 'INDG'; } case "_MARN": if ($nameTag == '_MARN') { $nameTag = 'MARN'; } case "_MARNM": if ($nameTag == '_MARNM') { $nameTag = 'MARN'; } case "_OTHN": if ($nameTag == '_OTHN') { $nameTag = 'OTHN'; } case "_RELN": if ($nameTag == '_RELN') { $nameTag = 'RELN'; } case "NAMR": if ($nameTag == 'NAMR') { $nameTag = 'RELN'; } $event2Type = 'personName'; if ($ret) { $ret = $this->setPersonName($nameTag, $row_line['value']); } break; case "_PATR": if ($this->patronymSetting == 2) { $this->persons->set('patronym', $row_line['value']); } break; case "NPFX": $this->persons->set('prefix', $row_line['value']); break; case "NSFX": $this->persons->set('suffix', $row_line['value']); break; default: $event2Type = 'none'; break; } } switch ($row_line['tag']) { case "DATE": // all events $event2Type = 'none'; if ($event1Type == 'personEvent') { $this->person_events->set('eventDate', $row_line['value']); switch ($information) { case "BIRT": // do nothing // do nothing case "CHR": // do nothing // do nothing case "BRTM": // do nothing // do nothing case "BAPM": // do nothing if (!isset($this->birthYear)) { $this->birthYear = (int) substr(trim($row_line['value']), -4); } case "BARM": // do nothing // do nothing case "BASM": // do nothing // do nothing case "BLES": // do nothing // do nothing case "CHRA": // do nothing $eventYear = (int) substr(trim($row_line['value']), -4); if ($eventYear < $this->offsetYear) { $this->indLiving = false; } break; case "DEAT": // do nothing // do nothing case "BURI": // do nothing // do nothing case "CREM": // do nothing if (!isset($this->deathYear)) { $this->deathYear = (int) substr(trim($row_line['value']), -4); } break; default: break; } } else { if ($event1Type == 'changeDateTime') { $this->logs->setChangeDateTime(trim($row_line['value'])); } } break; case "PLAC": $event2Type = 'none'; if ($event1Type == 'personEvent') { $this->person_events->set('location', $row_line['value']); } break; case "TYPE": // all other events $event2Type = 'none'; if ($event1Type == 'personEvent') { $this->person_events->set('type', $row_line['value']); } break; case "PAGE": $event2Type = 'none'; if ($event1Type == 'personSource') { $this->person_citations->set('page', $row_line['value']); } break; case "QUAY": $event2Type = 'none'; if ($event1Type == 'personSource') { $this->person_citations->set('dataQuality', $row_line['value']); } break; case "FORM": $event2Type = 'none'; if ($event1Type == 'personDocument') { $this->documents->set('fileformat', $row_line['value']); } break; case "FILE": $event2Type = 'none'; if ($event1Type == 'personDocument') { $this->documents->set('file', $row_line['value']); } break; case "TITL": $event2Type = 'none'; if ($event1Type == 'personDocument') { $this->documents->set('title', $row_line['value']); } break; case "NOTE": if ($event1Type == 'personSource') { // do nothing for right now $event2Type = 'none'; $this->person_citations->set('note', $row_line['value']); } else { if ($event1Type == 'personDocument') { $event2Type = 'none'; // try to strip @ and save in local value $tmpValue = ltrim(rtrim($row_line['value'], '@'), '@'); if ($row_line['value'] != $tmpValue) { // @ are stripped and local value is therefore different than value // this is an note_id $this->documents->set('note_id', $tmpValue); } else { // stripping had no effect. values are identical // this is a real note $this->documents->set('note', $row_line['value']); } } else { // Note for event $event2Type = 'personNote'; if ($ret) { $ret = $this->setPersonNote($event1Type, $row_line['value']); } if ($event1Type == 'personEvent') { if ($ret) { $this->person_events->set('indNote', true); } } } } break; case "SOUR": // collect all sources for this person $event2Type = 'personSource'; if ($ret and $event1Type != 'none') { $sourceKey = $this->getSourceKey($row_line['value']); $ret = $this->setPersonCitation($event1Type, $sourceKey); if ($event1Type == 'personEvent') { if ($ret) { $this->person_events->set('indCitation', true); } if ($ret) { $this->persons->set('indCitation', true); } } else { if ($event1Type == 'personNote') { if ($ret) { $this->person_notes->set('indCitation', true); } if ($ret) { $this->persons->set('indCitation', true); } } else { if ($event1Type == 'personDocument' and $this->docsFromGedcom) { if ($ret) { $this->documents->set('indCitation', true); } if ($ret) { $this->persons->set('indCitation', true); } } } } } break; case "ADOP": // Adopted child - don't know how this tag is used // Adopted child - don't know how this tag is used case "FOST": // Foster child - don't know how this tag is used $row_line['value'] = $row_line['tag'] == 'ADOP' ? 'adopted' : 'foster'; // continue // continue case "PEDI": if ($event1Type == 'familyChild') { $this->keepChild($person_id, $family_id, $row_line['value']); unset($family_id); } break; case "CHAN": // changeDateTime $event2Type = 'changeDateTime'; break; default: break; } break; case "3": switch ($row_line['tag']) { case "DATE": $event3Type = 'none'; if ($information == 'NAME' and $event2Type == 'personName') { $this->person_names->set('eventDate', $row_line['value']); } else { if ($event2Type == 'changeDateTime') { $this->logs->setChangeDateTime(trim($row_line['value'])); } } break; case "PAGE": $event3Type = 'none'; if ($event2Type == 'personSource') { $this->person_citations->set('page', $row_line['value']); } break; case "QUAY": $event3Type = 'none'; if ($event2Type == 'personSource') { $this->person_citations->set('dataQuality', $row_line['value']); } break; case "TEXT": $event3Type = 'none'; if ($event1Type == 'personSource') { $this->person_citations->set('quotation', $row_line['value']); } break; case "NOTE": if ($event2Type == 'personSource') { $event3Type = 'none'; $this->person_citations->set('note', $row_line['value']); } else { $event3Type = 'personNote'; if ($ret) { $ret = $this->setPersonNote($event2Type, $row_line['value']); } if ($event2Type == 'personName') { if ($ret) { $this->person_names->set('indNote', true); } } } break; // new level for source // new level for source case "SOUR": // collect all sources for this person $event3Type = 'personSource'; if ($ret and $event2Type != 'none') { $sourceKey = $this->getSourceKey($row_line['value']); $ret = $this->setPersonCitation($event2Type, $sourceKey); if ($event2Type == 'personName') { if ($ret) { $this->person_names->set('indCitation', true); } if ($ret) { $this->persons->set('indCitation', true); } } else { if ($event2Type == 'personNote') { if ($ret) { $this->person_notes->set('indCitation', true); } if ($ret) { $this->persons->set('indCitation', true); } } } } break; case "CHAN": // changeDateTime $event3Type = 'changeDateTime'; break; default: break; } break; case "4": switch ($row_line['tag']) { case "DATE": if ($event3Type == 'changeDateTime') { $this->logs->setChangeDateTime(trim($row_line['value'])); } break; case "PAGE": if ($event3Type == 'personSource') { $this->person_citations->set('page', $row_line['value']); } break; case "QUAY": if ($event3Type == 'personSource') { $this->person_citations->set('dataQuality', $row_line['value']); } break; case "TEXT": if ($event2Type == 'personSource') { $this->person_citations->set('quotation', $row_line['value']); } break; case "NOTE": if ($event3Type == 'personSource') { $this->person_citations->set('note', $row_line['value']); } break; default: break; } break; case "5": switch ($row_line['tag']) { case "TEXT": if ($event3Type == 'personSource') { $this->person_citations->set('quotation', $row_line['value']); } break; default: break; } break; default: break; } // end of level switch } // end of loop throuth lines related to person if (!$ind_update) { // insert new record for admin table if ($ret) { $ret = $this->admin_person(); } } // store record if ($ret) { $ret = $this->persons->store(); } // update last person name if ($ret) { $ret = $this->setPersonName(null, null); } // update last person event if ($ret) { $ret = $this->setPersonEvent(null, null); } // update last person note if ($ret) { $ret = $this->setPersonNote(null, null); } // update last person citation if ($ret) { $ret = $this->setPersonCitation('none', null); } // update last person document if ($ret) { $ret = $this->setDocument(null, null, null); } // log update if ($ret) { $ret = $this->logs->logChangeDateTime(); } // if insert or update went ok, continue with next source; else stop if (!$ret) { $this->application->enqueueMessage(JText::sprintf('JTGEDCOM_MESSAGE_NOSUCPERSON', $person_id), 'notice'); } return $ret; }