summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2014-04-20 22:06:00 +0100
committerGreg Roach <fisharebest@gmail.com>2014-04-20 22:06:00 +0100
commit2113886d7d4ca0e636712bd16f6db8a78f716abf (patch)
tree82c0c3a2073f33dc1e4c04157b6cd8009e66eab8
parenta1083b5ea1ffdac84c8808a39edae4a600a9664d (diff)
downloadwebtrees-2113886d7d4ca0e636712bd16f6db8a78f716abf.tar.gz
webtrees-2113886d7d4ca0e636712bd16f6db8a78f716abf.tar.bz2
webtrees-2113886d7d4ca0e636712bd16f6db8a78f716abf.zip
Formatting of associates - #91
-rw-r--r--expand_view.php4
-rw-r--r--includes/functions/functions_print.php73
-rw-r--r--includes/functions/functions_print_facts.php4
3 files changed, 37 insertions, 44 deletions
diff --git a/expand_view.php b/expand_view.php
index d67fb96db5..1198e14755 100644
--- a/expand_view.php
+++ b/expand_view.php
@@ -72,9 +72,7 @@ foreach ($facts as $event) {
break;
case 'ASSO':
// Associates
- echo '<div><span class="details_label">', $event->getLabel(), '</span> ';
- print_asso_rela_record($event, $person);
- echo '</div>';
+ echo format_asso_rela_record($event);
break;
default:
// Simple version of print_fact()
diff --git a/includes/functions/functions_print.php b/includes/functions/functions_print.php
index 3958abca83..2f0cd0274f 100644
--- a/includes/functions/functions_print.php
+++ b/includes/functions/functions_print.php
@@ -536,70 +536,65 @@ function highlight_search_hits($string) {
}
// Print the associations from the associated individuals in $event to the individuals in $record
-function print_asso_rela_record(WT_Fact $event, WT_GedcomRecord $record) {
+function format_asso_rela_record(WT_Fact $event) {
global $SEARCH_SPIDER;
+ $parent = $event->getParent();
// To whom is this record an assocate?
- if ($record instanceof WT_Individual) {
+ if ($parent instanceof WT_Individual) {
// On an individual page, we just show links to the person
- $associates=array($record);
- } elseif ($record instanceof WT_Family) {
+ $associates = array($parent);
+ } elseif ($parent instanceof WT_Family) {
// On a family page, we show links to both spouses
- $associates=$record->getSpouses();
+ $associates = $parent->getSpouses();
} else {
// On other pages, it does not make sense to show associates
- return;
+ return '';
}
preg_match_all('/^1 ASSO @('.WT_REGEX_XREF.')@((\n[2-9].*)*)/', $event->getGedcom(), $amatches1, PREG_SET_ORDER);
preg_match_all('/\n2 _?ASSO @('.WT_REGEX_XREF.')@((\n[3-9].*)*)/', $event->getGedcom(), $amatches2, PREG_SET_ORDER);
+
+ $html = '';
// For each ASSO record
foreach (array_merge($amatches1, $amatches2) as $amatch) {
- $person=WT_Individual::getInstance($amatch[1]);
+ $person = WT_Individual::getInstance($amatch[1]);
if ($person) {
+ // Is there a "RELA" tag
if (preg_match('/\n[23] RELA (.+)/', $amatch[2], $rmatch)) {
- $rela=$rmatch[1];
+ // Use the supplied relationship as a label
+ $label = WT_Gedcom_Code_Rela::getValue($rmatch[1], $person);
} else {
- $rela='';
+ // Use a default label
+ $label = WT_Gedcom_Tag::getLabel('ASSO', $person);
}
- $html=array();
- foreach ($associates as $associate) {
- if ($associate) {
- if ($rela) {
- $label='<span class="rela_type">'.WT_Gedcom_Code_Rela::getValue($rela, $person).':&nbsp;</span>';
- $label_2='<span class="rela_name">'.get_associate_relationship_name($associate, $person).'</span>';
- } else {
- // Generate an automatic RELA
- $label='';
- $label_2='<span class="rela_name">'.get_associate_relationship_name($associate, $person).'</span>';
- }
- if (!$label && !$label_2) {
- $label=WT_I18N::translate('Relationships');
- $label_2='';
- }
- // For family records (e.g. MARR), identify the spouse with a sex icon
- if ($record instanceof WT_Family) {
- $label_2=$associate->getSexImage().$label_2;
+
+ $values = array('<a href="' . $person->getHtmlUrl() . '">' . $person->getFullName() . '</a>');
+ if (!$SEARCH_SPIDER) {
+ foreach ($associates as $associate) {
+ $relationship_name = get_associate_relationship_name($associate, $person);
+ if (!$relationship_name) {
+ $relationship_name = WT_Gedcom_Tag::getLabel('RELA');
}
- if ($SEARCH_SPIDER) {
- $html[]=$label_2; // Search engines cannot use the relationship chart.
- } else {
- $html[]='<a href="relationship.php?pid1='.$associate->getXref().'&amp;pid2='.$person->getXref().'&amp;ged='.WT_GEDURL.'">'.$label_2.'</a>';
+ if ($parent instanceof WT_Family) {
+ // For family ASSO records (e.g. MARR), identify the spouse with a sex icon
+ $relationship_name .= $associate->getSexImage();
}
+
+ $values[] = '<a href="relationship.php?pid1=' . $associate->getXref() . '&amp;pid2=' . $person->getXref() . '&amp;ged=' . WT_GEDURL . '">' . $relationship_name . '</a>';
}
}
- $html=array_unique($html);
- echo
- '<div class="fact_ASSO">',$label,
- implode(WT_I18N::$list_separator, $html),
- ' - ',
- '<a href="', $person->getHtmlUrl().'">', $person->getFullName(), '</a>';
- echo '</div>';
+ $value = implode(' — ', $values);
+
+ // Use same markup as WT_Gedcom_Tag::getLabelValue()
+ $asso = WT_I18N::translate('<span class="label">%1$s:</span> <span class="field" dir="auto">%2$s</span>', $label, $value);
} else {
- echo WT_Gedcom_Tag::getLabelValue('ASSO', '<span class="error">' . $amatch[1] . '</span>');
+ $asso = WT_Gedcom_Tag::getLabelValue('ASSO', '<span class="error">' . $amatch[1] . '</span>');
}
+ $html .= '<div class="fact_ASSO">' . $asso . '</div>';
}
+ return $html;
}
/**
diff --git a/includes/functions/functions_print_facts.php b/includes/functions/functions_print_facts.php
index a7f7f7f718..37d40ab60c 100644
--- a/includes/functions/functions_print_facts.php
+++ b/includes/functions/functions_print_facts.php
@@ -223,7 +223,7 @@ function print_fact(WT_Fact $fact, WT_GedcomRecord $record) {
echo '<div class="field"><a href="https://familysearch.org/search/tree/results#count=20&query=afn:', rawurlencode($fact->getValue()), '" target="new">', WT_Filter::escapeHtml($fact->getValue()), '</a></div>';
break;
case 'ASSO':
- // we handle this later, in print_asso_rela_record()
+ // we handle this later, in format_asso_rela_record()
break;
case 'EMAIL':
case 'EMAI':
@@ -333,7 +333,7 @@ function print_fact(WT_Fact $fact, WT_GedcomRecord $record) {
}
// Print the associates of this fact/event
- print_asso_rela_record($fact, $record);
+ echo format_asso_rela_record($fact);
// Print any other "2 XXXX" attributes, in the order in which they appear.
preg_match_all('/\n2 ('.WT_REGEX_TAG.') (.+)/', $fact->getGedcom(), $matches, PREG_SET_ORDER);