Skip to content

Commit

Permalink
Fix: #1192 - only first associate shown in events of close relatives
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Roach committed May 6, 2019
1 parent c452490 commit 907c110
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 107 deletions.
156 changes: 60 additions & 96 deletions app/GedcomRecord.php
Expand Up @@ -850,181 +850,145 @@ public function formatFirstMajorFact(array $facts, int $style): string
*
* @param string $link
*
* @return Individual[]
* @return Collection
*/
public function linkedIndividuals(string $link): array
public function linkedIndividuals(string $link): Collection
{
$rows = DB::table('individuals')
return DB::table('individuals')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 'i_file')->on('l_from', '=', 'i_id');
$join
->on('l_file', '=', 'i_file')
->on('l_from', '=', 'i_id');
})
->where('i_file', '=', $this->tree->id())
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['i_id AS xref', 'i_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Individual::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['individuals.*'])
->get()
->map(Individual::rowMapper())
->filter(self::accessFilter());
}

/**
* Find families linked to this record.
*
* @param string $link
*
* @return Family[]
* @return Collection
*/
public function linkedFamilies(string $link): array
public function linkedFamilies(string $link): Collection
{
$rows = DB::table('families')
return DB::table('families')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 'f_file')->on('l_from', '=', 'f_id');
$join
->on('l_file', '=', 'f_file')
->on('l_from', '=', 'f_id');
})
->where('f_file', '=', $this->tree->id())
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['f_id AS xref', 'f_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Family::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['families.*'])
->get()
->map(Family::rowMapper())
->filter(self::accessFilter());
}

/**
* Find sources linked to this record.
*
* @param string $link
*
* @return Source[]
* @return Collection
*/
public function linkedSources(string $link): array
public function linkedSources(string $link): Collection
{
$rows = DB::table('sources')
return DB::table('sources')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 's_file')->on('l_from', '=', 's_id');
$join
->on('l_file', '=', 's_file')
->on('l_from', '=', 's_id');
})
->where('s_file', '=', $this->tree->id())
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['s_id AS xref', 's_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Source::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['sources.*'])
->get()
->map(Source::rowMapper())
->filter(self::accessFilter());
}

/**
* Find media objects linked to this record.
*
* @param string $link
*
* @return Media[]
* @return Collection
*/
public function linkedMedia(string $link): array
public function linkedMedia(string $link): Collection
{
$rows = DB::table('media')
return DB::table('media')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 'm_file')->on('l_from', '=', 'm_id');
$join
->on('l_file', '=', 'm_file')
->on('l_from', '=', 'm_id');
})
->where('m_file', '=', $this->tree->id())
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['m_id AS xref', 'm_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Media::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['media.*'])
->get()
->map(Media::rowMapper())
->filter(self::accessFilter());
}

/**
* Find notes linked to this record.
*
* @param string $link
*
* @return Note[]
* @return Collection
*/
public function linkedNotes(string $link): array
public function linkedNotes(string $link): Collection
{
$rows = DB::table('other')
return DB::table('other')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 'o_file')->on('l_from', '=', 'o_id');
$join
->on('l_file', '=', 'o_file')
->on('l_from', '=', 'o_id');
})
->where('o_file', '=', $this->tree->id())
->where('o_type', '=', 'NOTE')
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['o_id AS xref', 'o_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Note::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['other.*'])
->get()
->map(Note::rowMapper())
->filter(self::accessFilter());
}

/**
* Find repositories linked to this record.
*
* @param string $link
*
* @return Repository[]
* @return Collection
*/
public function linkedRepositories(string $link): array
public function linkedRepositories(string $link): Collection
{
$rows = DB::table('other')
return DB::table('other')
->join('link', static function (JoinClause $join): void {
$join->on('l_file', '=', 'o_file')->on('l_from', '=', 'o_id');
$join
->on('l_file', '=', 'o_file')
->on('l_from', '=', 'o_id');
})
->where('o_file', '=', $this->tree->id())
->where('o_type', '=', 'REPO')
->where('l_type', '=', $link)
->where('l_to', '=', $this->xref)
->select(['o_id AS xref', 'o_gedcom AS gedcom'])
->get();

$list = [];
foreach ($rows as $row) {
$record = Repository::getInstance($row->xref, $this->tree, $row->gedcom);
if ($record->canShowName()) {
$list[] = $record;
}
}

return $list;
->select(['other.*'])
->get()
->map(Individual::rowMapper())
->filter(self::accessFilter());
}

/**
Expand Down
20 changes: 9 additions & 11 deletions app/Module/IndividualFactsTabModule.php
Expand Up @@ -17,6 +17,7 @@

namespace Fisharebest\Webtrees\Module;

use function array_merge;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\Fact;
Expand Down Expand Up @@ -472,19 +473,16 @@ private function associateFacts(Individual $person): array
$facts = [];

/** @var Individual[] $associates */
$associates = array_merge(
$person->linkedIndividuals('ASSO'),
$person->linkedIndividuals('_ASSO'),
$person->linkedFamilies('ASSO'),
$person->linkedFamilies('_ASSO')
);
$asso1 = $person->linkedIndividuals('ASSO');
$asso2 = $person->linkedIndividuals('_ASSO');
$asso3 = $person->linkedFamilies('ASSO');
$asso4 = $person->linkedFamilies('_ASSO');

$associates = $asso1->merge($asso2)->merge($asso3)->merge($asso4);

foreach ($associates as $associate) {
foreach ($associate->facts() as $fact) {
$arec = $fact->attribute('_ASSO');
if (!$arec) {
$arec = $fact->attribute('ASSO');
}
if ($arec && trim($arec, '@') === $person->xref()) {
if (preg_match('/\n\d _?ASSO @' . $person->xref() . '@/', $fact->gedcom())) {
// Extract the important details from the fact
$factrec = '1 ' . $fact->getTag();
if (preg_match('/\n2 DATE .*/', $fact->gedcom(), $match)) {
Expand Down

0 comments on commit 907c110

Please sign in to comment.