Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.18% covered (success)
91.18%
62 / 68
90.91% covered (success)
90.91%
20 / 22
CRAP
0.00% covered (danger)
0.00%
0 / 1
MarcBasicTrait
91.18% covered (success)
91.18%
62 / 68
90.91% covered (success)
90.91%
20 / 22
34.79
0.00% covered (danger)
0.00%
0 / 1
 getISBNs
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 getISSNs
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 getFormats
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUniqueID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCallNumbers
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 getDeweyCallNumber
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPrimaryAuthors
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getLanguages
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
6
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSortTitle
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getShortTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSubtitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPublishers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDateSpan
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPublicationDates
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCorporateAuthors
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getSecondaryAuthors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNewerTitles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPreviousTitles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEdition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRawLCCN
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPhysicalDescriptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Functions to add basic MARC-driven functionality to a record driver not already
5 * powered by the standard index spec. Depends upon MarcReaderTrait.
6 *
7 * PHP version 8
8 *
9 * Copyright (C) Villanova University 2017.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  RecordDrivers
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Ere Maijala <ere.maijala@helsinki.fi>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
30 */
31
32namespace VuFind\RecordDriver\Feature;
33
34use function strlen;
35
36/**
37 * Functions to add basic MARC-driven functionality to a record driver not already
38 * powered by the standard index spec. Depends upon MarcReaderTrait.
39 *
40 * @category VuFind
41 * @package  RecordDrivers
42 * @author   Demian Katz <demian.katz@villanova.edu>
43 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
45 */
46trait MarcBasicTrait
47{
48    /**
49     * Get an array of all ISBNs associated with the record (may be empty).
50     *
51     * @return array
52     */
53    public function getISBNs()
54    {
55        $isbn = array_merge(
56            $this->getFieldArray('020', ['a', 'z', '9'], false),
57            $this->getFieldArray('773', ['z'])
58        );
59        foreach ($isbn as $key => $num) {
60            $isbn[$key] = str_replace('-', '', $num);
61        }
62        $isbn = array_unique($isbn);
63        return $isbn;
64    }
65
66    /**
67     * Get an array of all ISSNs associated with the record (may be empty).
68     *
69     * @return array
70     */
71    public function getISSNs()
72    {
73        $issn = array_merge(
74            $this->getFieldArray('022', ['a']),
75            $this->getFieldArray('440', ['x']),
76            $this->getFieldArray('490', ['x']),
77            $this->getFieldArray('730', ['x']),
78            $this->getFieldArray('773', ['x']),
79            $this->getFieldArray('776', ['x']),
80            $this->getFieldArray('780', ['x']),
81            $this->getFieldArray('785', ['x'])
82        );
83        $issn = array_unique($issn);
84        return $issn;
85    }
86
87    /**
88     * Get an array of all the formats associated with the record.
89     *
90     * @return array
91     */
92    public function getFormats()
93    {
94        return $this->getFieldArray('245', ['h']);
95    }
96
97    /**
98     * Return the unique identifier of this record within the Solr index;
99     * useful for retrieving additional information (like tags and user
100     * comments) from the external MySQL database.
101     *
102     * @return string Unique identifier.
103     */
104    public function getUniqueID()
105    {
106        return (string)$this->getMarcReader()->getField('001');
107    }
108
109    /**
110     * Get the call numbers associated with the record (empty string if none).
111     *
112     * @return array
113     */
114    public function getCallNumbers()
115    {
116        $retVal = [];
117        foreach (['090', '050'] as $field) {
118            $callNo = $this->getFirstFieldValue($field, ['a', 'b']);
119            if (!empty($callNo)) {
120                $retVal[] = $callNo;
121            }
122        }
123        $dewey = $this->getDeweyCallNumber();
124        if (!empty($dewey)) {
125            $retVal[] = $dewey;
126        }
127        return $retVal;
128    }
129
130    /**
131     * Get the Dewey call number associated with this record (empty string if none).
132     *
133     * @return string
134     */
135    public function getDeweyCallNumber()
136    {
137        return $this->getFirstFieldValue('082', ['a']);
138    }
139
140    /**
141     * Get the main authors of the record.
142     *
143     * @return array
144     */
145    public function getPrimaryAuthors()
146    {
147        $primary = $this->getFirstFieldValue('100', ['a', 'b', 'c', 'd']);
148        return empty($primary) ? [] : [$primary];
149    }
150
151    /**
152     * Get an array of all the languages associated with the record.
153     *
154     * @return array
155     */
156    public function getLanguages()
157    {
158        $retVal = [];
159        $field = $this->getMarcReader()->getField('008');
160        if ($field) {
161            if (strlen($field) >= 38) {
162                $retVal[] = substr($field, 35, 3);
163            }
164        }
165        $fields = $this->getMarcReader()->getFields('041');
166        foreach ($fields as $field) {
167            if ($field['i2'] !== '7') {
168                foreach ($this->getSubfields($field, 'a') as $subfield) {
169                    $retVal[] = $subfield;
170                }
171            }
172        }
173        return array_unique($retVal);
174    }
175
176    /**
177     * Get the full title of the record.
178     *
179     * @return string
180     */
181    public function getTitle()
182    {
183        return $this->getFirstFieldValue('245', ['a', 'b']);
184    }
185
186    /**
187     * Get a sortable title for the record (i.e. no leading articles).
188     *
189     * @return string
190     */
191    public function getSortTitle()
192    {
193        $field = $this->getMarcReader()->getField('245');
194        if ($field && $title = $this->getSubfield($field, 'a')) {
195            $skip = $field['i2'];
196            return substr($title, $skip);
197        }
198        return parent::getSortTitle();
199    }
200
201    /**
202     * Get the short (pre-subtitle) title of the record.
203     *
204     * @return string
205     */
206    public function getShortTitle()
207    {
208        return $this->getFirstFieldValue('245', ['a']);
209    }
210
211    /**
212     * Get the subtitle of the record.
213     *
214     * @return string
215     */
216    public function getSubtitle()
217    {
218        return $this->getFirstFieldValue('245', ['b']);
219    }
220
221    /**
222     * Get the publishers of the record.
223     *
224     * @return array
225     */
226    public function getPublishers()
227    {
228        return $this->getPublicationInfo('b');
229    }
230
231    /**
232     * Get the date coverage for a record which spans a period of time (i.e. a
233     * journal). Use getPublicationDates for publication dates of particular
234     * monographic items.
235     *
236     * @return array
237     */
238    public function getDateSpan()
239    {
240        return $this->getFieldArray('362', ['a']);
241    }
242
243    /**
244     * Get the publication dates of the record.  See also getDateSpan().
245     *
246     * @return array
247     */
248    public function getPublicationDates()
249    {
250        return $this->getPublicationInfo('c');
251    }
252
253    /**
254     * Get an array of all corporate authors (complementing getPrimaryAuthor()).
255     *
256     * @return array
257     */
258    public function getCorporateAuthors()
259    {
260        return array_merge(
261            $this->getFieldArray('110', ['a', 'b']),
262            $this->getFieldArray('111', ['a', 'b']),
263            $this->getFieldArray('710', ['a', 'b']),
264            $this->getFieldArray('711', ['a', 'b'])
265        );
266    }
267
268    /**
269     * Get an array of all secondary authors (complementing getPrimaryAuthors()).
270     *
271     * @return array
272     */
273    public function getSecondaryAuthors()
274    {
275        return $this->getFieldArray('700', ['a', 'b', 'c', 'd']);
276    }
277
278    /**
279     * Get an array of newer titles for the record.
280     *
281     * @return array
282     */
283    public function getNewerTitles()
284    {
285        return $this->getFieldArray('785', ['a', 's', 't']);
286    }
287
288    /**
289     * Get an array of previous titles for the record.
290     *
291     * @return array
292     */
293    public function getPreviousTitles()
294    {
295        return $this->getFieldArray('780', ['a', 's', 't']);
296    }
297
298    /**
299     * Get the edition of the current record.
300     *
301     * @return string
302     */
303    public function getEdition()
304    {
305        return $this->getFirstFieldValue('250', ['a']);
306    }
307
308    /**
309     * Get a raw, unnormalized LCCN. (See DefaultRecord::getLCCN for normalization).
310     *
311     * @return string
312     */
313    protected function getRawLCCN()
314    {
315        return $this->getFirstFieldValue('010', ['a']);
316    }
317
318    /**
319     * Get an array of physical descriptions of the item.
320     *
321     * @return array
322     */
323    public function getPhysicalDescriptions()
324    {
325        return $this->getFieldArray('300', ['a', 'b', 'c', 'e', 'f', 'g'], true);
326    }
327}