|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* citeproc-php |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
|
6
|
|
|
* @copyright Copyright (c) 2016 Sebastian Böttger. |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Rendering\Name; |
|
11
|
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
|
13
|
|
|
use Seboettg\CiteProc\Data\DataList; |
|
14
|
|
|
use Seboettg\CiteProc\Locale\Locale; |
|
15
|
|
|
use Seboettg\CiteProc\Rendering\Rendering; |
|
16
|
|
|
use Seboettg\CiteProc\Styles\FormattingRenderer; |
|
17
|
|
|
use SimpleXMLElement; |
|
18
|
|
|
use stdClass; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class EtAl |
|
22
|
|
|
* Et-al abbreviation, controlled via the et-al-... attributes (see Name), can be further customized with the optional |
|
23
|
|
|
* cs:et-al element, which must follow the cs:name element (if present). The term attribute may be set to either “et-al” |
|
24
|
|
|
* (the default) or to “and others” to use either term. The formatting attributes may also be used, for example to |
|
25
|
|
|
* italicize the “et-al” term. |
|
26
|
|
|
* |
|
27
|
|
|
* @package Seboettg\CiteProc\Rendering\Name |
|
28
|
|
|
* |
|
29
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class EtAl implements Rendering |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var string */ |
|
34
|
|
|
private $term; |
|
35
|
|
|
|
|
36
|
|
|
/** @var Locale */ |
|
37
|
|
|
private $locale; |
|
38
|
|
|
|
|
39
|
|
|
/** @var FormattingRenderer */ |
|
40
|
|
|
private $formattingRenderer; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param SimpleXMLElement $node |
|
44
|
|
|
* @return EtAl |
|
45
|
|
|
*/ |
|
46
|
14 |
|
public static function factory(SimpleXMLElement $node): EtAl |
|
47
|
|
|
{ |
|
48
|
14 |
|
$term = (string)$node->attributes()['term']; |
|
49
|
|
|
// The term attribute may be set to either “et-al” (the default) or to “and others” to use either term. |
|
50
|
14 |
|
$term = empty($term) ? "et-al" : $term; |
|
51
|
14 |
|
$locale = CiteProc::getContext()->getLocale(); |
|
52
|
14 |
|
$formattingRenderer = FormattingRenderer::factory($node); |
|
53
|
14 |
|
return new self($term, $locale, $formattingRenderer); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
14 |
|
public function __construct(?string $term, Locale $locale, FormattingRenderer $formattingRenderer) |
|
57
|
|
|
{ |
|
58
|
14 |
|
$this->term = $term; |
|
59
|
14 |
|
$this->locale = $locale; |
|
60
|
14 |
|
$this->formattingRenderer = $formattingRenderer; |
|
61
|
14 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array|DataList|stdClass $data |
|
65
|
|
|
* @param null $citationNumber |
|
|
|
|
|
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function render($data, $citationNumber = null) |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->formattingRenderer->render( |
|
71
|
1 |
|
$this->locale->filter('terms', $this->term)->single |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|