Code Duplication    Length = 23-25 lines in 6 locations

app/GedcomRecord.php 6 locations

@@ 829-853 (lines=25) @@
826
	 *
827
	 * @return Individual[]
828
	 */
829
	public function linkedIndividuals($link) {
830
		$rows = Database::prepare(
831
			"SELECT i_id AS xref, i_gedcom AS gedcom" .
832
			" FROM `##individuals`" .
833
			" JOIN `##link` ON i_file = l_file AND i_id = l_from" .
834
			" LEFT JOIN `##name` ON i_file = n_file AND i_id = n_id AND n_num = 0" .
835
			" WHERE i_file = :tree_id AND l_type = :link AND l_to = :xref" .
836
			" ORDER BY n_sort COLLATE :collation"
837
		)->execute([
838
			'tree_id'   => $this->tree->getTreeId(),
839
			'link'      => $link,
840
			'xref'      => $this->xref,
841
			'collation' => I18N::collation(),
842
		])->fetchAll();
843
844
		$list = [];
845
		foreach ($rows as $row) {
846
			$record = Individual::getInstance($row->xref, $this->tree, $row->gedcom);
847
			if ($record->canShowName()) {
848
				$list[] = $record;
849
			}
850
		}
851
852
		return $list;
853
	}
854
855
	/**
856
	 * Find families linked to this record.
@@ 862-884 (lines=23) @@
859
	 *
860
	 * @return Family[]
861
	 */
862
	public function linkedFamilies($link) {
863
		$rows = Database::prepare(
864
			"SELECT f_id AS xref, f_gedcom AS gedcom" .
865
			" FROM `##families`" .
866
			" JOIN `##link` ON f_file = l_file AND f_id = l_from" .
867
			" LEFT JOIN `##name` ON f_file = n_file AND f_id = n_id AND n_num = 0" .
868
			" WHERE f_file = :tree_id AND l_type = :link AND l_to = :xref"
869
		)->execute([
870
			'tree_id' => $this->tree->getTreeId(),
871
			'link'    => $link,
872
			'xref'    => $this->xref,
873
		])->fetchAll();
874
875
		$list = [];
876
		foreach ($rows as $row) {
877
			$record = Family::getInstance($row->xref, $this->tree, $row->gedcom);
878
			if ($record->canShowName()) {
879
				$list[] = $record;
880
			}
881
		}
882
883
		return $list;
884
	}
885
886
	/**
887
	 * Find sources linked to this record.
@@ 893-916 (lines=24) @@
890
	 *
891
	 * @return Source[]
892
	 */
893
	public function linkedSources($link) {
894
		$rows = Database::prepare(
895
			"SELECT s_id AS xref, s_gedcom AS gedcom" .
896
			" FROM `##sources`" .
897
			" JOIN `##link` ON s_file = l_file AND s_id = l_from" .
898
			" WHERE s_file = :tree_id AND l_type = :link AND l_to = :xref" .
899
			" ORDER BY s_name COLLATE :collation"
900
		)->execute([
901
			'tree_id'   => $this->tree->getTreeId(),
902
			'link'      => $link,
903
			'xref'      => $this->xref,
904
			'collation' => I18N::collation(),
905
		])->fetchAll();
906
907
		$list = [];
908
		foreach ($rows as $row) {
909
			$record = Source::getInstance($row->xref, $this->tree, $row->gedcom);
910
			if ($record->canShowName()) {
911
				$list[] = $record;
912
			}
913
		}
914
915
		return $list;
916
	}
917
918
	/**
919
	 * Find media objects linked to this record.
@@ 925-948 (lines=24) @@
922
	 *
923
	 * @return Media[]
924
	 */
925
	public function linkedMedia($link) {
926
		$rows = Database::prepare(
927
			"SELECT m_id AS xref, m_gedcom AS gedcom" .
928
			" FROM `##media`" .
929
			" JOIN `##link` ON m_file = l_file AND m_id = l_from" .
930
			" WHERE m_file = :tree_id AND l_type = :link AND l_to = :xref" .
931
			" ORDER BY m_titl COLLATE :collation"
932
		)->execute([
933
			'tree_id'   => $this->tree->getTreeId(),
934
			'link'      => $link,
935
			'xref'      => $this->xref,
936
			'collation' => I18N::collation(),
937
		])->fetchAll();
938
939
		$list = [];
940
		foreach ($rows as $row) {
941
			$record = Media::getInstance($row->xref, $this->tree, $row->gedcom);
942
			if ($record->canShowName()) {
943
				$list[] = $record;
944
			}
945
		}
946
947
		return $list;
948
	}
949
950
	/**
951
	 * Find notes linked to this record.
@@ 957-981 (lines=25) @@
954
	 *
955
	 * @return Note[]
956
	 */
957
	public function linkedNotes($link) {
958
		$rows = Database::prepare(
959
			"SELECT o_id AS xref, o_gedcom AS gedcom" .
960
			" FROM `##other`" .
961
			" JOIN `##link` ON o_file = l_file AND o_id = l_from" .
962
			" LEFT JOIN `##name` ON o_file = n_file AND o_id = n_id AND n_num = 0" .
963
			" WHERE o_file = :tree_id AND o_type = 'NOTE' AND l_type = :link AND l_to = :xref" .
964
			" ORDER BY n_sort COLLATE :collation"
965
		)->execute([
966
			'tree_id'   => $this->tree->getTreeId(),
967
			'link'      => $link,
968
			'xref'      => $this->xref,
969
			'collation' => I18N::collation(),
970
		])->fetchAll();
971
972
		$list = [];
973
		foreach ($rows as $row) {
974
			$record = Note::getInstance($row->xref, $this->tree, $row->gedcom);
975
			if ($record->canShowName()) {
976
				$list[] = $record;
977
			}
978
		}
979
980
		return $list;
981
	}
982
983
	/**
984
	 * Find repositories linked to this record.
@@ 990-1014 (lines=25) @@
987
	 *
988
	 * @return Repository[]
989
	 */
990
	public function linkedRepositories($link) {
991
		$rows = Database::prepare(
992
			"SELECT o_id AS xref, o_gedcom AS gedcom" .
993
			" FROM `##other`" .
994
			" JOIN `##link` ON o_file = l_file AND o_id = l_from" .
995
			" LEFT JOIN `##name` ON o_file = n_file AND o_id = n_id AND n_num = 0" .
996
			" WHERE o_file = :tree_id AND o_type = 'REPO' AND l_type = :link AND l_to = :xref" .
997
			" ORDER BY n_sort COLLATE :collation"
998
		)->execute([
999
			'tree_id'   => $this->tree->getTreeId(),
1000
			'link'      => $link,
1001
			'xref'      => $this->xref,
1002
			'collation' => I18N::collation(),
1003
		])->fetchAll();
1004
1005
		$list = [];
1006
		foreach ($rows as $row) {
1007
			$record = Repository::getInstance($row->xref, $this->tree, $row->gedcom);
1008
			if ($record->canShowName()) {
1009
				$list[] = $record;
1010
			}
1011
		}
1012
1013
		return $list;
1014
	}
1015
1016
	/**
1017
	 * Get all attributes (e.g. DATE or PLAC) from an event (e.g. BIRT or MARR).