Lines 1764-1926
sub get_marc_hostinfo_only {
Link Here
|
1764 |
return $hostinfo; |
1764 |
return $hostinfo; |
1765 |
} |
1765 |
} |
1766 |
|
1766 |
|
1767 |
=head3 link_marc_host |
1767 |
=head3 generate_marc_host_field |
1768 |
|
1768 |
|
1769 |
=cut |
1769 |
my $link_field = $biblio->generate_marc_host_field; |
|
|
1770 |
$child->link_marc_host( $link_field ); |
1770 |
|
1771 |
|
1771 |
sub link_marc_host { |
1772 |
This method generates a MARC link field from the biblio that can be added to child |
1772 |
my ( $self, $params ) = @_; |
1773 |
records to link them to the host record. |
1773 |
|
1774 |
|
1774 |
my $host = Koha::Biblios->find( $params->{biblionumber} ); |
1775 |
NOTE: This replicates and partially enhances C4::Biblio::prepare_marc_host(). We should merge |
1775 |
return unless $host; |
1776 |
functionality from C4::Biblio::PrepareMarcHost() too and then replace all calls to those methods |
|
|
1777 |
with this one and remove those alternatives from the codebase. |
1778 |
|
1779 |
=cut |
1780 |
|
1781 |
sub generate_marc_host_field { |
1782 |
my ($self) = @_; |
1776 |
|
1783 |
|
1777 |
my $marcflavour = C4::Context->preference('marcflavour'); |
1784 |
my $marcflavour = C4::Context->preference('marcflavour'); |
1778 |
my $marc_host = $host->metadata->record; |
1785 |
my $marc_host = $self->metadata->record; |
1779 |
my %sfd; |
1786 |
my %sfd; |
1780 |
my $field; |
|
|
1781 |
my $host_field; |
1787 |
my $host_field; |
|
|
1788 |
my $link_field; |
1782 |
|
1789 |
|
1783 |
if ( $marcflavour eq 'MARC21' ) { |
1790 |
if ( $marcflavour eq 'MARC21' ) { |
|
|
1791 |
|
1784 |
# Author |
1792 |
# Author |
1785 |
if ( $field = |
1793 |
if ( $host_field = $marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111') ) { |
1786 |
$marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111') ) |
1794 |
my $s = $host_field->as_string('ab'); |
1787 |
{ |
|
|
1788 |
my $s = $field->as_string('ab'); |
1789 |
if ($s) { |
1795 |
if ($s) { |
1790 |
$sfd{a} = $s; |
1796 |
$sfd{a} = $s; |
1791 |
} |
1797 |
} |
1792 |
} |
1798 |
} |
1793 |
# Title |
1799 |
|
1794 |
if ( $field = $marc_host->field('245') ) { |
1800 |
# Edition |
1795 |
my $s = $field->as_string('ab'); |
1801 |
if ( $host_field = $marc_host->field('250') ) { |
|
|
1802 |
my $s = $host_field->as_string('ab'); |
1796 |
if ($s) { |
1803 |
if ($s) { |
1797 |
$sfd{t} = $s; |
1804 |
$sfd{b} = $s; |
1798 |
} |
1805 |
} |
1799 |
} |
1806 |
} |
1800 |
# Uniform title |
1807 |
|
1801 |
if ( $field = $marc_host->field('240') ) { |
1808 |
# Publication |
1802 |
my $s = $field->as_string('a'); |
1809 |
if ( $host_field = $marc_host->field('260') ) { |
|
|
1810 |
my $s = $host_field->as_string('abc'); |
1803 |
if ($s) { |
1811 |
if ($s) { |
1804 |
$sfd{s} = $s; |
1812 |
$sfd{d} = $s; |
1805 |
} |
1813 |
} |
1806 |
} |
1814 |
} |
1807 |
# Publication |
1815 |
|
1808 |
if ( $field = $marc_host->field('260') ) { |
1816 |
# Uniform title |
1809 |
my $s = $field->as_string('abc'); |
1817 |
if ( $host_field = $marc_host->field('240') ) { |
|
|
1818 |
my $s = $host_field->as_string('a'); |
1810 |
if ($s) { |
1819 |
if ($s) { |
1811 |
$sfd{d} = $s; |
1820 |
$sfd{s} = $s; |
1812 |
} |
1821 |
} |
1813 |
} |
1822 |
} |
1814 |
# Edition |
1823 |
|
1815 |
if ( $field = $marc_host->field('250') ) { |
1824 |
# Title |
1816 |
my $s = $field->as_string('ab'); |
1825 |
if ( $host_field = $marc_host->field('245') ) { |
|
|
1826 |
my $s = $host_field->as_string('ab'); |
1817 |
if ($s) { |
1827 |
if ($s) { |
1818 |
$sfd{b} = $s; |
1828 |
$sfd{t} = $s; |
1819 |
} |
1829 |
} |
1820 |
} |
1830 |
} |
|
|
1831 |
|
1821 |
# ISSN |
1832 |
# ISSN |
1822 |
if ( $field = $marc_host->field('022') ) { |
1833 |
if ( $host_field = $marc_host->field('022') ) { |
1823 |
my $s = $field->as_string('a'); |
1834 |
my $s = $host_field->as_string('a'); |
1824 |
if ($s) { |
1835 |
if ($s) { |
1825 |
$sfd{x} = $s; |
1836 |
$sfd{x} = $s; |
1826 |
} |
1837 |
} |
1827 |
} |
1838 |
} |
|
|
1839 |
|
1828 |
# ISBN |
1840 |
# ISBN |
1829 |
if ( $field = $marc_host->field('020') ) { |
1841 |
if ( $host_field = $marc_host->field('020') ) { |
1830 |
my $s = $field->as_string('a'); |
1842 |
my $s = $host_field->as_string('a'); |
1831 |
if ($s) { |
1843 |
if ($s) { |
1832 |
$sfd{z} = $s; |
1844 |
$sfd{z} = $s; |
1833 |
} |
1845 |
} |
1834 |
} |
1846 |
} |
1835 |
if ( C4::Context->preference('UseControlNumber') ) { |
1847 |
if ( C4::Context->preference('UseControlNumber') ) { |
|
|
1848 |
|
1836 |
# Control number |
1849 |
# Control number |
1837 |
if ( $field = $marc_host->field('001') ) { |
1850 |
if ( $host_field = $marc_host->field('001') ) { |
1838 |
$sfd{w} = $field->data(),; |
1851 |
$sfd{w} = $host_field->data(),; |
1839 |
} |
1852 |
} |
|
|
1853 |
|
1840 |
# Control number identifier |
1854 |
# Control number identifier |
1841 |
if ( $field = $marc_host->field('003') ) { |
1855 |
if ( $host_field = $marc_host->field('003') ) { |
1842 |
$sfd{w} = '('.$field->data().')'.$sfd{w}; |
1856 |
$sfd{w} = '(' . $host_field->data() . ')' . $sfd{w}; |
1843 |
} |
1857 |
} |
1844 |
} |
1858 |
} |
1845 |
$host_field = MARC::Field->new( 773, '0', ' ', %sfd ); |
1859 |
$link_field = MARC::Field->new( 773, '0', ' ', %sfd ); |
1846 |
} |
1860 |
} elsif ( $marcflavour eq 'UNIMARC' ) { |
1847 |
elsif ( $marcflavour eq 'UNIMARC' ) { |
|
|
1848 |
|
1861 |
|
1849 |
#author |
1862 |
#author |
1850 |
if ( $field = |
1863 |
if ( $host_field = $marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) { |
1851 |
$marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) |
1864 |
my $s = $host_field->as_string('ab'); |
1852 |
{ |
|
|
1853 |
my $s = $field->as_string('ab'); |
1854 |
if ($s) { |
1865 |
if ($s) { |
1855 |
$sfd{a} = $s; |
1866 |
$sfd{a} = $s; |
1856 |
} |
1867 |
} |
1857 |
} |
1868 |
} |
1858 |
|
1869 |
|
1859 |
#title |
|
|
1860 |
if ( $field = $marc_host->field('200') ) { |
1861 |
my $s = $field->as_string('a'); |
1862 |
if ($s) { |
1863 |
$sfd{t} = $s; |
1864 |
} |
1865 |
} |
1866 |
|
1867 |
#place of publicaton |
1870 |
#place of publicaton |
1868 |
if ( $field = $marc_host->field('210') ) { |
1871 |
if ( $host_field = $marc_host->field('210') ) { |
1869 |
my $s = $field->as_string('a'); |
1872 |
my $s = $host_field->as_string('a'); |
1870 |
if ($s) { |
1873 |
if ($s) { |
1871 |
$sfd{c} = $s; |
1874 |
$sfd{c} = $s; |
1872 |
} |
1875 |
} |
1873 |
} |
1876 |
} |
1874 |
|
1877 |
|
1875 |
#date of publication |
1878 |
#date of publication |
1876 |
if ( $field = $marc_host->field('210') ) { |
1879 |
if ( $host_field = $marc_host->field('210') ) { |
1877 |
my $s = $field->as_string('d'); |
1880 |
my $s = $host_field->as_string('d'); |
1878 |
if ($s) { |
1881 |
if ($s) { |
1879 |
$sfd{d} = $s; |
1882 |
$sfd{d} = $s; |
1880 |
} |
1883 |
} |
1881 |
} |
1884 |
} |
1882 |
|
1885 |
|
1883 |
#edition statement |
1886 |
#edition statement |
1884 |
if ( $field = $marc_host->field('205') ) { |
1887 |
if ( $host_field = $marc_host->field('205') ) { |
1885 |
my $s = $field->as_string(); |
1888 |
my $s = $host_field->as_string(); |
1886 |
if ($s) { |
1889 |
if ($s) { |
1887 |
$sfd{e} = $s; |
1890 |
$sfd{e} = $s; |
1888 |
} |
1891 |
} |
1889 |
} |
1892 |
} |
1890 |
|
1893 |
|
|
|
1894 |
#title |
1895 |
if ( $host_field = $marc_host->field('200') ) { |
1896 |
my $s = $host_field->as_string('a'); |
1897 |
if ($s) { |
1898 |
$sfd{t} = $s; |
1899 |
} |
1900 |
} |
1901 |
|
1891 |
#URL |
1902 |
#URL |
1892 |
if ( $field = $marc_host->field('856') ) { |
1903 |
if ( $host_field = $marc_host->field('856') ) { |
1893 |
my $s = $field->as_string('u'); |
1904 |
my $s = $host_field->as_string('u'); |
1894 |
if ($s) { |
1905 |
if ($s) { |
1895 |
$sfd{u} = $s; |
1906 |
$sfd{u} = $s; |
1896 |
} |
1907 |
} |
1897 |
} |
1908 |
} |
1898 |
|
1909 |
|
1899 |
#ISSN |
1910 |
#ISSN |
1900 |
if ( $field = $marc_host->field('011') ) { |
1911 |
if ( $host_field = $marc_host->field('011') ) { |
1901 |
my $s = $field->as_string('a'); |
1912 |
my $s = $host_field->as_string('a'); |
1902 |
if ($s) { |
1913 |
if ($s) { |
1903 |
$sfd{x} = $s; |
1914 |
$sfd{x} = $s; |
1904 |
} |
1915 |
} |
1905 |
} |
1916 |
} |
1906 |
|
1917 |
|
1907 |
#ISBN |
1918 |
#ISBN |
1908 |
if ( $field = $marc_host->field('010') ) { |
1919 |
if ( $host_field = $marc_host->field('010') ) { |
1909 |
my $s = $field->as_string('a'); |
1920 |
my $s = $host_field->as_string('a'); |
1910 |
if ($s) { |
1921 |
if ($s) { |
1911 |
$sfd{y} = $s; |
1922 |
$sfd{y} = $s; |
1912 |
} |
1923 |
} |
1913 |
} |
1924 |
} |
1914 |
if ( $field = $marc_host->field('001') ) { |
1925 |
if ( $host_field = $marc_host->field('001') ) { |
1915 |
$sfd{0} = $field->data(),; |
1926 |
$sfd{0} = $host_field->data(),; |
1916 |
} |
1927 |
} |
1917 |
$host_field = MARC::Field->new( 461, '0', ' ', %sfd ); |
1928 |
$link_field = MARC::Field->new( 461, '0', ' ', %sfd ); |
|
|
1929 |
} |
1930 |
|
1931 |
return $link_field; |
1932 |
} |
1933 |
|
1934 |
=head3 link_marc_host |
1935 |
|
1936 |
$biblio->link_marc_host({ field => $link_field}); |
1937 |
$biblio->link_marc_host({ host => $biblio }); |
1938 |
$biblio->link_marc_host({ host => $biblionumber }); |
1939 |
|
1940 |
Links a child marc record to the parent. Expects either a pre-formed link field as generated by |
1941 |
$parent->get_link_field, the biblio object or biblionumber of the host to link to. |
1942 |
|
1943 |
=cut |
1944 |
|
1945 |
sub link_marc_host { |
1946 |
my ( $self, $params ) = @_; |
1947 |
|
1948 |
my $host_link_field; |
1949 |
if ( $params->{field} ) { |
1950 |
$host_link_field = $params->{field}; |
1951 |
} elsif ( ref( $params->{host} ) eq 'Koha::Biblio' ) { |
1952 |
$host_link_field = $params->{host}->generate_marc_host_field; |
1953 |
} else { |
1954 |
my $host = Koha::Biblios->find( $params->{host} ); |
1955 |
$host_link_field = $host->generate_marc_host_field; |
1918 |
} |
1956 |
} |
1919 |
|
1957 |
|
1920 |
my $marc_record = $self->metadata->record; |
1958 |
my $marc_record = $self->metadata->record; |
1921 |
$marc_record->append_fields($host_field); |
1959 |
$marc_record->append_fields($host_link_field); |
1922 |
|
1960 |
|
1923 |
C4::Biblio::ModBiblioMarc($marc_record, $self->biblionumber); |
1961 |
C4::Biblio::ModBiblioMarc( $marc_record, $self->biblionumber ); |
1924 |
return $self; |
1962 |
return $self; |
1925 |
} |
1963 |
} |
1926 |
|
1964 |
|
1927 |
- |
|
|