Skip to content

Commit 1e27de2

Browse files
committed
Add more stuff to BibliographicRecord
1 parent e8fba91 commit 1e27de2

File tree

10 files changed

+367
-32
lines changed

10 files changed

+367
-32
lines changed

src/BibliographicRecord.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Scriptotek\Marc\Fields\Classification;
77
use Scriptotek\Marc\Fields\Isbn;
88
use Scriptotek\Marc\Fields\Person;
9+
use Scriptotek\Marc\Fields\Publisher;
910
use Scriptotek\Marc\Fields\Subject;
1011
use Scriptotek\Marc\Fields\SubjectInterface;
1112
use Scriptotek\Marc\Fields\Title;
@@ -15,7 +16,10 @@ class BibliographicRecord extends Record
1516
/**
1617
* @var array List of properties to be included when serializing the record using the `toArray()` method.
1718
*/
18-
public $properties = ['id', 'isbns', 'title', 'creators', 'subjects', 'classifications'];
19+
public $properties = [
20+
'id', 'isbns', 'title', 'publisher', 'pub_year', 'edition', 'creators',
21+
'subjects', 'classifications', 'toc', 'summary', 'part_of'
22+
];
1923

2024
/**
2125
* Get the descriptive cataloging form value from LDR/18. Returns any of
@@ -61,6 +65,72 @@ public function getTitle()
6165
return Title::get($this);
6266
}
6367

68+
/**
69+
* Get 26[04]$b as a `Publisher` object. Returns null if no such field was found.
70+
*
71+
* @return Title
72+
*/
73+
public function getPublisher()
74+
{
75+
return Publisher::get($this);
76+
}
77+
78+
/**
79+
* Get the publication year from 008
80+
*
81+
* @return string
82+
*/
83+
public function getPubYear()
84+
{
85+
return substr($this->query('008')->text(), 7, 4);
86+
}
87+
88+
/**
89+
* Get TOC
90+
*
91+
* @return string
92+
*/
93+
public function getToc()
94+
{
95+
$field = $this->getField('505');
96+
if ($field) {
97+
if ($field->getIndicator(2) === '0') {
98+
// Enhanced
99+
$out = [
100+
'text' => [],
101+
];
102+
foreach ($field->getSubfields('t') as $sf) {
103+
$out['text'][] = $sf->getData();
104+
}
105+
$out['text'] = implode("\n", $out['text']);
106+
107+
return $out;
108+
109+
} else {
110+
// Basic
111+
return $field->mapSubFields([
112+
'a' => 'text',
113+
]);
114+
}
115+
}
116+
}
117+
118+
/**
119+
* Get Summary
120+
*
121+
* @return array
122+
*/
123+
public function getSummary()
124+
{
125+
$field = $this->getField('520');
126+
if ($field) {
127+
return $field->mapSubFields([
128+
'a' => 'text',
129+
'c' => 'assigning_source',
130+
]);
131+
}
132+
}
133+
64134
/**
65135
* Get an array of the 6XX fields as `SubjectInterface` objects, optionally
66136
* filtered by vocabulary and/or tag.
@@ -112,4 +182,24 @@ public function getCreators($tag = null)
112182
return empty($tag) || in_array($person->getType(), $tag);
113183
}));
114184
}
185+
186+
/**
187+
* Get part of from 773.
188+
*
189+
* @return string
190+
*/
191+
public function getPartOf()
192+
{
193+
$field = $this->getField('773');
194+
if ($field) {
195+
return $field->mapSubFields([
196+
'i' => 'relationship',
197+
't' => 'title',
198+
'x' => 'issn',
199+
'w' => 'id',
200+
'v' => 'volume',
201+
]);
202+
}
203+
}
204+
115205
}

src/Fields/Field.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace Scriptotek\Marc\Fields;
44

5+
use Scriptotek\Marc\MagicAccess;
56
use Scriptotek\Marc\Record;
67

78
class Field implements \JsonSerializable
89
{
9-
use SerializableField;
10+
use SerializableField, MagicAccess;
1011

1112
/**
1213
* @var array List of properties to be included when serializing the record using the `toArray()` method.
@@ -47,23 +48,6 @@ public function __call($name, $args)
4748
return call_user_func_array([$this->field, $name], $args);
4849
}
4950

50-
public function __get($key)
51-
{
52-
// Convert key from underscore_case to camelCase.
53-
$key_uc = preg_replace_callback(
54-
'/_([a-z])/',
55-
function($matches) {
56-
return strtoupper($matches[1]);
57-
},
58-
$key
59-
);
60-
61-
$method = 'get' . ucfirst($key_uc);
62-
if (method_exists($this, $method)) {
63-
return call_user_func([$this, $method]);
64-
}
65-
}
66-
6751
public function __toString()
6852
{
6953
return $this->field->__toString();

src/Fields/Publisher.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Scriptotek\Marc\Fields;
4+
5+
use Scriptotek\Marc\Record;
6+
7+
class Publisher extends Field implements FieldInterface
8+
{
9+
public static function get(Record $record)
10+
{
11+
foreach ($record->getFields('264') as $field) {
12+
return new static($field->getField());
13+
}
14+
foreach ($record->getFields('260') as $field) {
15+
return new static($field->getField());
16+
}
17+
}
18+
19+
public function __toString()
20+
{
21+
return $this->sf('b');
22+
}
23+
}

src/MagicAccess.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
namespace Scriptotek\Marc;
5+
6+
7+
trait MagicAccess
8+
{
9+
public function __get($key)
10+
{
11+
// Convert key from underscore_case to camelCase.
12+
$key_uc = preg_replace_callback(
13+
'/_([a-z])/',
14+
function($matches) {
15+
return strtoupper($matches[1]);
16+
},
17+
$key
18+
);
19+
20+
$method = 'get' . ucfirst($key_uc);
21+
if (method_exists($this, $method)) {
22+
return call_user_func([$this, $method]);
23+
}
24+
}
25+
26+
}

src/Record.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class Record implements \JsonSerializable
2626
{
27+
use MagicAccess;
28+
2729
protected $record;
2830

2931
/**
@@ -153,8 +155,12 @@ public function jsonSerialize()
153155
$o[$prop] = $value;
154156
} elseif (is_array($value)) {
155157
$t = [];
156-
foreach ($value as $v) {
157-
$t[] = $v->jsonSerialize();
158+
foreach ($value as $k => $v) {
159+
if (is_object($v)) {
160+
$t[$k] = $v->jsonSerialize();
161+
} else {
162+
$t[$k] = (string) $v;
163+
}
158164
}
159165
$o[$prop] = $t;
160166
} else if (is_object($value)) {
@@ -171,14 +177,6 @@ public function __call($name, $args)
171177
return call_user_func_array([$this->record, $name], $args);
172178
}
173179

174-
public function __get($key)
175-
{
176-
$method = 'get' . ucfirst($key);
177-
if (method_exists($this, $method)) {
178-
return call_user_func([$this, $method]);
179-
}
180-
}
181-
182180
public function __toString()
183181
{
184182
return strval($this->record);

tests/data/examples/bibliographic.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"id": "999401461934702201",
33
"isbns": [],
44
"title": "The eightfold way",
5+
"publisher": "W.A. Benjamin",
6+
"pub_year": "1964",
7+
"edition": null,
58
"creators": [
69
{
710
"type": "100",
@@ -31,5 +34,8 @@
3134
"scheme": "msc",
3235
"number": "81"
3336
}
34-
]
37+
],
38+
"toc": null,
39+
"summary": null,
40+
"part_of": null
3541
}

tests/data/examples/bibliographic2.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"0471616389"
55
],
66
"title": "Acousto-optic devices : principles, design, and applications",
7+
"publisher": "Wiley",
8+
"pub_year": "1992",
9+
"edition": null,
710
"creators": [
811
{
912
"type": "100",
@@ -86,5 +89,8 @@
8689
"scheme": "inspec",
8790
"number": "a4280"
8891
}
89-
]
92+
],
93+
"toc": null,
94+
"summary": null,
95+
"part_of": null
9096
}

tests/data/examples/bibliographic3.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"9788202308414"
55
],
66
"title": "Å nærme seg en katt",
7+
"publisher": "Cappelen Damm",
8+
"pub_year": "2009",
9+
"edition": null,
710
"creators": [
811
{
912
"type": "100",
@@ -55,5 +58,8 @@
5558
"scheme": "oosk",
5659
"number": "S 13c/US"
5760
}
58-
]
61+
],
62+
"toc": null,
63+
"summary": null,
64+
"part_of": null
5965
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"id": "999919884907102204",
3+
"isbns": [
4+
"9781107084940",
5+
"1107084946"
6+
],
7+
"title": "Physics of electronic materials : fundamentals to device applications",
8+
"publisher": "Cambridge University Press,",
9+
"pub_year": "2017",
10+
"edition": null,
11+
"creators": [
12+
{
13+
"type": "100",
14+
"name": "Rammer, Jørgen",
15+
"id": "90614467",
16+
"relationship": "aut"
17+
}
18+
],
19+
"subjects": [
20+
{
21+
"type": "650",
22+
"vocabulary": "lcsh",
23+
"term": "Semiconductors."
24+
},
25+
{
26+
"type": "650",
27+
"vocabulary": "noubomn",
28+
"term": "Halvledere",
29+
"id": "(NoOU)REAL005740"
30+
},
31+
{
32+
"type": "650",
33+
"vocabulary": "noubomn",
34+
"term": "Elektriske kretser",
35+
"id": "(NoOU)REAL003680"
36+
},
37+
{
38+
"type": "653",
39+
"term": "halvledere"
40+
},
41+
{
42+
"type": "653",
43+
"term": "kvantemekanikk"
44+
},
45+
{
46+
"type": "653",
47+
"term": "elektronikk"
48+
}
49+
],
50+
"classifications": [
51+
{
52+
"scheme": "ddc",
53+
"number": "537.622",
54+
"edition": "23"
55+
},
56+
{
57+
"scheme": "ddc",
58+
"number": "537.62",
59+
"edition": "23/nor"
60+
}
61+
],
62+
"toc": {
63+
"text": "Quantum mechanics -- Quantum tunneling -- Standard metal model -- Standard conductor model -- Electric circuit theory -- Quantum wells -- Particle in a periodic potential -- Bloch currents -- Crystalline solids -- Semiconductor doping -- Transistors -- Heterostructures -- Mesoscopic physics -- Arithmetic, logic and machines."
64+
},
65+
"summary": {
66+
"text": "\"Electronic devices play a crucial role in todays societies and in the physical sciences where they originated. Contemplating that in just a few decades, technology guiding electrons and photons has emerged that makes possible oral and visual communication between peoples on opposite sides of the planet is truly a triumph of science and technology. Not to mention that equipped with a computer with access to the Internet, one can instantly access a wealth of human knowledge. The physical principles providing the understanding of the functioning of present day electronic devices should therefore be of interest not only to physicists, electrical engineers and material scientists, but to anyone with a general interest in how the wired world around us is functioning. Present day information technology is based on the physical properties of semiconductors, in particular the functioning of the transistor. The intension of this book is to take the reader from the principles of quantum mechanics through the quantum theory of metals and semiconductors all the way to how devices are used to perform their duties in electric circuits: for example functioning as amplifiers, switches, and in the hard ware of computers. The mechanics of arithmetic and logical operations are discussed and it is shown how electronic devices in the present day CMOS-technology can be carriers of arithmetic calculations and logic operations in computers\"--",
67+
"assigning_source": "Provided by publisher."
68+
},
69+
"part_of": null
70+
}

0 commit comments

Comments
 (0)