function update_family_links($person, $options) { RP_Dao_Factory::get_rp_indi_fam_dao($this->credentials->prefix)->delete_by_indi($person->id, $this->batch_id); if (isset($options['editMode'])) { RP_Dao_Factory::get_rp_fam_child_dao($this->credentials->prefix)->delete_by_child($person->id, $person->batch_id); RP_Dao_Factory::get_rp_fam_dao($this->credentials->prefix)->delete_spouse($person->id, $person->batch_id); } $this->transaction->commit_no_close(); if (isset($options['editMode']) && isset($person->parental)) { $familyRecord = $person->parental; $familyRecord->batch_id = $person->batch_id; if ($familyRecord->id == '-1') { $familyRecord->id = null; $familyRecord->batch_id = $person->batch_id; $familyRecord->children[] = $person->id; $this->add_fam($familyRecord, $options); } else { // I am updating husband or wife if (isset($familyRecord->husband) && !empty($familyRecord->husband)) { RP_Dao_Factory::get_rp_fam_dao($this->credentials->prefix)->update_spouse1($familyRecord); } else { if (isset($familyRecord->wife) && !empty($familyRecord->wife)) { RP_Dao_Factory::get_rp_fam_dao($this->credentials->prefix)->update_spouse2($familyRecord); } } } } foreach ($person->spouse_family_links as $spousal) { $link = new RP_Indi_Fam(); $link->indi_id = $person->id; $link->indi_batch_id = $this->batch_id; $link->fam_id = $spousal->family_id; $link->fam_batch_id = $this->batch_id; $link->link_type = 'S'; try { RP_Dao_Factory::get_rp_indi_fam_dao($this->credentials->prefix)->insert($link); if (isset($options['editMode'])) { $family = new RP_Family_Record(); $family->id = $spousal->family_id; $family->batch_id = $this->batch_id; if ($spousal->spouse_seq == 2) { $family->husband = $person->id; $family->wife = $spousal->spouse_id; } else { $family->husband = $spousal->spouse_id; $family->wife = $person->id; } $famId = $this->add_fam($family, $options); if ($spousal->family_id == null) { $person->newFams = $famId; } } } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); echo $e->getMessage(); throw $e; } } foreach ($person->child_family_links as $child) { $link = new RP_Indi_Fam(); $link->indi_id = $person->id; $link->indi_batch_id = $this->batch_id; $link->fam_id = $child->family_id; $link->fam_batch_id = $this->batch_id; $link->link_type = 'C'; $link->link_status = $child->linkage_status; $link->pedigree = $child->linkage_type; try { RP_Dao_Factory::get_rp_indi_fam_dao($this->credentials->prefix)->insert($link); if (isset($options['editMode'])) { $family = new RP_Family_Record(); $family->id = $child->family_id; $family->batch_id = $this->batch_id; $family->children[] = $person->id; $this->update_children($family, $options); } } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); echo $e->getMessage(); throw $e; } } }