Code Duplication    Length = 23-25 lines in 5 locations

app/GedcomRecord.php 5 locations

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