1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* citeproc-php |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
6
|
|
|
* @copyright Copyright (c) 2020 Sebastian Böttger. |
7
|
|
|
* @license https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Style\Options; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
13
|
|
|
use SimpleXMLElement; |
14
|
|
|
|
15
|
|
|
class NameOptions |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
private static $attributes = [ |
19
|
|
|
'and', |
20
|
|
|
'delimiter-precedes-et-al', |
21
|
|
|
'delimiter-precedes-last', |
22
|
|
|
'et-al-min', |
23
|
|
|
'et-al-use-first', |
24
|
|
|
'et-al-use-last', |
25
|
|
|
'et-al-subsequent-min', |
26
|
|
|
'et-al-subsequent-use-first', |
27
|
|
|
'initialize', |
28
|
|
|
'initialize-with', |
29
|
|
|
'name-as-sort-order', |
30
|
|
|
'sort-separator', |
31
|
|
|
'name-form', |
32
|
|
|
'form', |
33
|
|
|
'name-delimiter', |
34
|
|
|
'delimiter' |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Specifies the delimiter between the second to last and last name of the names in a name variable. Allowed values |
39
|
|
|
* are “text” (selects the “and” term, e.g. “Doe, Johnson and Smith”) and “symbol” (selects the ampersand, |
40
|
|
|
* e.g. “Doe, Johnson & Smith”). |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $and; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Determines when the name delimiter or a space is used between a truncated name list and the “et-al” |
48
|
|
|
* (or “and others”) term in case of et-al abbreviation. Allowed values: |
49
|
|
|
* - “contextual” - (default), name delimiter is only used for name lists truncated to two or more names |
50
|
|
|
* - 1 name: “J. Doe et al.” |
51
|
|
|
* - 2 names: “J. Doe, S. Smith, et al.” |
52
|
|
|
* - “after-inverted-name” - name delimiter is only used if the preceding name is inverted as a result of the |
53
|
|
|
* - name-as-sort-order attribute. E.g. with name-as-sort-order set to “first”: |
54
|
|
|
* - “Doe, J., et al.” |
55
|
|
|
* - “Doe, J., S. Smith et al.” |
56
|
|
|
* - “always” - name delimiter is always used |
57
|
|
|
* - 1 name: “J. Doe, et al.” |
58
|
|
|
* - 2 names: “J. Doe, S. Smith, et al.” |
59
|
|
|
* - “never” - name delimiter is never used |
60
|
|
|
* - 1 name: “J. Doe et al.” |
61
|
|
|
* - 2 names: “J. Doe, S. Smith et al.” |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
private $delimiterPrecedesEtAl; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Determines when the name delimiter is used to separate the second to last and the last name in name lists (if |
69
|
|
|
* and is not set, the name delimiter is always used, regardless of the value of delimiter-precedes-last). Allowed |
70
|
|
|
* values: |
71
|
|
|
* |
72
|
|
|
* - “contextual” - (default), name delimiter is only used for name lists with three or more names |
73
|
|
|
* - 2 names: “J. Doe and T. Williams” |
74
|
|
|
* - 3 names: “J. Doe, S. Smith, and T. Williams” |
75
|
|
|
* - “after-inverted-name” - name delimiter is only used if the preceding name is inverted as a result of the |
76
|
|
|
* name-as-sort-order attribute. E.g. with name-as-sort-order set to “first”: |
77
|
|
|
* - “Doe, J., and T. Williams” |
78
|
|
|
* - “Doe, J., S. Smith and T. Williams” |
79
|
|
|
* - “always” - name delimiter is always used |
80
|
|
|
* - 2 names: “J. Doe, and T. Williams” |
81
|
|
|
* - 3 names: “J. Doe, S. Smith, and T. Williams” |
82
|
|
|
* - “never” - name delimiter is never used |
83
|
|
|
* - 2 names: “J. Doe and T. Williams” |
84
|
|
|
* - 3 names: “J. Doe, S. Smith and T. Williams” |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
private $delimiterPrecedesLast; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Use of etAlMin (et-al-min attribute) and etAlUseFirst (et-al-use-first attribute) enables et-al abbreviation. If |
92
|
|
|
* the number of names in a name variable matches or exceeds the number set on etAlMin, the rendered name list is |
93
|
|
|
* truncated after reaching the number of names set on etAlUseFirst. |
94
|
|
|
* |
95
|
|
|
* @var int |
96
|
|
|
*/ |
97
|
|
|
private $etAlMin; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Use of etAlMin (et-al-min attribute) and etAlUseFirst (et-al-use-first attribute) enables et-al abbreviation. If |
101
|
|
|
* the number of names in a name variable matches or exceeds the number set on etAlMin, the rendered name list is |
102
|
|
|
* truncated after reaching the number of names set on etAlUseFirst. |
103
|
|
|
* |
104
|
|
|
* @var int |
105
|
|
|
*/ |
106
|
|
|
private $etAlUseFirst; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* When set to “true” (the default is “false”), name lists truncated by et-al abbreviation are followed by the name |
110
|
|
|
* delimiter, the ellipsis character, and the last name of the original name list. This is only possible when the |
111
|
|
|
* original name list has at least two more names than the truncated name list (for this the value of |
112
|
|
|
* et-al-use-first/et-al-subsequent-min must be at least 2 less than the value of |
113
|
|
|
* et-al-min/et-al-subsequent-use-first). |
114
|
|
|
* |
115
|
|
|
* @var bool |
116
|
|
|
*/ |
117
|
|
|
private $etAlUseLast = false; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* If used, the values of these attributes (et-al-subsequent-min and et-al-subsequent-use-first) replace those of |
121
|
|
|
* respectively et-al-min and et-al-use-first for subsequent cites (cites referencing earlier cited items). |
122
|
|
|
* |
123
|
|
|
* @var int |
124
|
|
|
*/ |
125
|
|
|
private $etAlSubsequentMin; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* If used, the values of these attributes (et-al-subsequent-min and et-al-subsequent-use-first) replace those of |
129
|
|
|
* respectively et-al-min and et-al-use-first for subsequent cites (cites referencing earlier cited items). |
130
|
|
|
* |
131
|
|
|
* @var int |
132
|
|
|
*/ |
133
|
|
|
private $etAlSubsequentUseFirst; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* When set to “false” (the default is “true”), given names are no longer initialized when “initialize-with” is set. |
137
|
|
|
* However, the value of “initialize-with” is still added after initials present in the full name (e.g. with |
138
|
|
|
* initialize set to “false”, and initialize-with set to ”.”, “James T Kirk” becomes “James T. Kirk”). |
139
|
|
|
* |
140
|
|
|
* @var bool |
141
|
|
|
*/ |
142
|
|
|
private $initialize = true; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* When set, given names are converted to initials. The attribute value is added after each initial (”.” results |
146
|
|
|
* in “J.J. Doe”). For compound given names (e.g. “Jean-Luc”), hyphenation of the initials can be controlled with |
147
|
|
|
* the global initialize-with-hyphen option |
148
|
|
|
* |
149
|
|
|
* @var string |
150
|
|
|
*/ |
151
|
|
|
private $initializeWith = false; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Specifies that names should be displayed with the given name following the family name (e.g. “John Doe” becomes |
155
|
|
|
* “Doe, John”). The attribute has two possible values: |
156
|
|
|
* - “first” - attribute only has an effect on the first name of each name variable |
157
|
|
|
* - “all” - attribute has an effect on all names |
158
|
|
|
* Note that even when name-as-sort-order changes the name-part order, the display order is not necessarily the same |
159
|
|
|
* as the sorting order for names containing particles and suffixes (see Name-part order). Also, name-as-sort-order |
160
|
|
|
* only affects names written in the latin or Cyrillic alphabets. Names written in other alphabets (e.g. Asian |
161
|
|
|
* scripts) are always displayed with the family name preceding the given name. |
162
|
|
|
* |
163
|
|
|
* @var string |
164
|
|
|
*/ |
165
|
|
|
private $nameAsSortOrder = ""; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Sets the delimiter for name-parts that have switched positions as a result of name-as-sort-order. The default |
169
|
|
|
* value is ”, ” (“Doe, John”). As is the case for name-as-sort-order, this attribute only affects names written in |
170
|
|
|
* the latin or Cyrillic alphabets. |
171
|
|
|
* |
172
|
|
|
* @var string |
173
|
|
|
*/ |
174
|
|
|
private $sortSeparator = ", "; |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Specifies whether all the name-parts of personal names should be displayed (value “long”, the default), or only |
178
|
|
|
* the family name and the non-dropping-particle (value “short”). A third value, “count”, returns the total number |
179
|
|
|
* of names that would otherwise be rendered by the use of the cs:names element (taking into account the effects of |
180
|
|
|
* et-al abbreviation and editor/translator collapsing), which allows for advanced sorting. |
181
|
|
|
* |
182
|
|
|
* @var string |
183
|
|
|
*/ |
184
|
|
|
private $form; |
185
|
|
|
|
186
|
|
|
private $nameForm = "long"; |
187
|
|
|
|
188
|
|
|
private $nameDelimiter = ", "; |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param SimpleXMLElement $node |
192
|
|
|
*/ |
193
|
|
|
public static function updateNameOptions(SimpleXMLElement $node) |
194
|
|
|
{ |
195
|
|
|
|
196
|
|
|
$nameOptions = CiteProc::getContext()->getNameOptions(); |
197
|
|
|
foreach (self::$attributes as $nameAttribute) { |
198
|
|
|
$attribute = $node[$nameAttribute]; |
199
|
|
|
if (!empty($attribute)) { |
200
|
|
|
switch ($nameAttribute) { |
201
|
|
|
case 'and': |
202
|
|
|
$nameOptions->setAnd((string)$attribute); |
203
|
|
|
break; |
204
|
|
|
case 'delimiter-precedes-et-al': |
205
|
|
|
$nameOptions->setDelimiterPrecedesEtAl((string)$attribute); |
206
|
|
|
break; |
207
|
|
|
case 'delimiter-precedes-last': |
208
|
|
|
$nameOptions->setDelimiterPrecedesLast((string)$attribute); |
209
|
|
|
break; |
210
|
|
|
case 'et-al-min': |
211
|
|
|
$nameOptions->setEtAlMin(intval((string)$attribute)); |
212
|
|
|
break; |
213
|
|
|
case 'et-al-use-first': |
214
|
|
|
$nameOptions->setEtAlUseFirst(intval((string)$attribute)); |
215
|
|
|
break; |
216
|
|
|
case 'et-al-subsequent-min': |
217
|
|
|
$nameOptions->setEtAlSubsequentMin(intval((string)$attribute)); |
218
|
|
|
break; |
219
|
|
|
case 'et-al-subsequent-use-first': |
220
|
|
|
$nameOptions->setEtAlSubsequentUseFirst(intval((string)$attribute)); |
221
|
|
|
break; |
222
|
|
|
case 'et-al-use-last': |
223
|
|
|
$nameOptions->setEtAlUseLast(boolval((string)$attribute)); |
224
|
|
|
break; |
225
|
|
|
case 'initialize': |
226
|
|
|
$nameOptions->setInitialize(boolval((string)$attribute)); |
227
|
|
|
break; |
228
|
|
|
case 'initialize-with': |
229
|
|
|
$nameOptions->setInitializeWith((string)$attribute); |
230
|
|
|
break; |
231
|
|
|
case 'name-as-sort-order': |
232
|
|
|
$nameOptions->setNameAsSortOrder((string)$attribute); |
233
|
|
|
break; |
234
|
|
|
case 'sort-separator': |
235
|
|
|
$nameOptions->setSortSeparator((string)$attribute); |
236
|
|
|
break; |
237
|
|
|
case 'name-form': |
238
|
|
|
$nameOptions->setNameForm((string)$attribute); |
239
|
|
|
break; |
240
|
|
|
case 'form': |
241
|
|
|
$nameOptions->setForm((string)$attribute); |
242
|
|
|
break; |
243
|
|
|
case 'name-delimiter': |
244
|
|
|
$nameOptions->setNameDelimiter((string)$attribute); |
245
|
|
|
break; |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return string |
253
|
|
|
*/ |
254
|
|
|
public function getAnd(): ?string |
255
|
|
|
{ |
256
|
|
|
return $this->and; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param string $and |
261
|
|
|
*/ |
262
|
|
|
public function setAnd(string $and): void |
263
|
|
|
{ |
264
|
|
|
$this->and = $and; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
|
|
public function getDelimiterPrecedesEtAl(): ?string |
271
|
|
|
{ |
272
|
|
|
return $this->delimiterPrecedesEtAl; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param string $delimiterPrecedesEtAl |
277
|
|
|
*/ |
278
|
|
|
public function setDelimiterPrecedesEtAl(string $delimiterPrecedesEtAl): void |
279
|
|
|
{ |
280
|
|
|
$this->delimiterPrecedesEtAl = $delimiterPrecedesEtAl; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
public function getDelimiterPrecedesLast(): ?string |
287
|
|
|
{ |
288
|
|
|
return $this->delimiterPrecedesLast; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param string $delimiterPrecedesLast |
293
|
|
|
*/ |
294
|
|
|
public function setDelimiterPrecedesLast(string $delimiterPrecedesLast): void |
295
|
|
|
{ |
296
|
|
|
$this->delimiterPrecedesLast = $delimiterPrecedesLast; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @return int |
301
|
|
|
*/ |
302
|
|
|
public function getEtAlMin(): ?int |
303
|
|
|
{ |
304
|
|
|
return $this->etAlMin; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @param int $etAlMin |
309
|
|
|
*/ |
310
|
|
|
public function setEtAlMin(int $etAlMin): void |
311
|
|
|
{ |
312
|
|
|
$this->etAlMin = $etAlMin; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return int |
317
|
|
|
*/ |
318
|
|
|
public function getEtAlUseFirst(): ?int |
319
|
|
|
{ |
320
|
|
|
return $this->etAlUseFirst; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param int $etAlUseFirst |
325
|
|
|
*/ |
326
|
|
|
public function setEtAlUseFirst(int $etAlUseFirst): void |
327
|
|
|
{ |
328
|
|
|
$this->etAlUseFirst = $etAlUseFirst; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @return bool |
333
|
|
|
*/ |
334
|
|
|
public function isEtAlUseLast(): bool |
335
|
|
|
{ |
336
|
|
|
return $this->etAlUseLast; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @param bool $etAlUseLast |
341
|
|
|
*/ |
342
|
|
|
public function setEtAlUseLast(bool $etAlUseLast): void |
343
|
|
|
{ |
344
|
|
|
$this->etAlUseLast = $etAlUseLast; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @return int |
349
|
|
|
*/ |
350
|
|
|
public function getEtAlSubsequentMin(): ?int |
351
|
|
|
{ |
352
|
|
|
return $this->etAlSubsequentMin; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @param int $etAlSubsequentMin |
357
|
|
|
*/ |
358
|
|
|
public function setEtAlSubsequentMin(int $etAlSubsequentMin): void |
359
|
|
|
{ |
360
|
|
|
$this->etAlSubsequentMin = $etAlSubsequentMin; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @return int |
365
|
|
|
*/ |
366
|
|
|
public function getEtAlSubsequentUseFirst(): ?int |
367
|
|
|
{ |
368
|
|
|
return $this->etAlSubsequentUseFirst; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @param int $etAlSubsequentUseFirst |
373
|
|
|
*/ |
374
|
|
|
public function setEtAlSubsequentUseFirst(int $etAlSubsequentUseFirst): void |
375
|
|
|
{ |
376
|
|
|
$this->etAlSubsequentUseFirst = $etAlSubsequentUseFirst; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @return bool |
381
|
|
|
*/ |
382
|
|
|
public function isInitialize(): bool |
383
|
|
|
{ |
384
|
|
|
return $this->initialize; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @param bool $initialize |
389
|
|
|
*/ |
390
|
|
|
public function setInitialize(bool $initialize): void |
391
|
|
|
{ |
392
|
|
|
$this->initialize = $initialize; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @return string |
397
|
|
|
*/ |
398
|
|
|
public function getInitializeWith() |
399
|
|
|
{ |
400
|
|
|
return $this->initializeWith; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @param string $initializeWith |
405
|
|
|
*/ |
406
|
|
|
public function setInitializeWith($initializeWith): void |
407
|
|
|
{ |
408
|
|
|
$this->initializeWith = $initializeWith; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
|
|
public function getNameAsSortOrder(): string |
415
|
|
|
{ |
416
|
|
|
return $this->nameAsSortOrder; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* @param string $nameAsSortOrder |
421
|
|
|
*/ |
422
|
|
|
public function setNameAsSortOrder(string $nameAsSortOrder): void |
423
|
|
|
{ |
424
|
|
|
$this->nameAsSortOrder = $nameAsSortOrder; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* @return string |
429
|
|
|
*/ |
430
|
|
|
public function getSortSeparator(): string |
431
|
|
|
{ |
432
|
|
|
return $this->sortSeparator; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* @param string $sortSeparator |
437
|
|
|
*/ |
438
|
|
|
public function setSortSeparator(string $sortSeparator): void |
439
|
|
|
{ |
440
|
|
|
$this->sortSeparator = $sortSeparator; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @return string |
445
|
|
|
*/ |
446
|
|
|
public function getForm(): ?string |
447
|
|
|
{ |
448
|
|
|
return $this->form; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* @param string $form |
453
|
|
|
*/ |
454
|
|
|
public function setForm(string $form): void |
455
|
|
|
{ |
456
|
|
|
$this->form = $form; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @return string |
461
|
|
|
*/ |
462
|
|
|
public function getNameForm(): string |
463
|
|
|
{ |
464
|
|
|
return $this->nameForm; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* @param string $nameForm |
469
|
|
|
*/ |
470
|
|
|
public function setNameForm(string $nameForm): void |
471
|
|
|
{ |
472
|
|
|
$this->nameForm = $nameForm; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* @return string |
477
|
|
|
*/ |
478
|
|
|
public function getNameDelimiter(): string |
479
|
|
|
{ |
480
|
|
|
return $this->nameDelimiter; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* @param string $nameDelimiter |
485
|
|
|
*/ |
486
|
|
|
public function setNameDelimiter(string $nameDelimiter): void |
487
|
|
|
{ |
488
|
|
|
$this->nameDelimiter = $nameDelimiter; |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
|