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\Style; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
13
|
|
|
use Seboettg\CiteProc\Config\RenderingMode; |
14
|
|
|
use Seboettg\CiteProc\Data\DataList; |
15
|
|
|
use Seboettg\CiteProc\Rendering\Layout; |
16
|
|
|
use Seboettg\CiteProc\Root\Root; |
17
|
|
|
use Seboettg\CiteProc\Style\Options\CitationOptions; |
18
|
|
|
use Seboettg\CiteProc\Style\Options\NameOptions; |
19
|
|
|
use Seboettg\CiteProc\Style\Sort\Sort; |
20
|
|
|
use Seboettg\Collection\ArrayList\ArrayListInterface; |
21
|
|
|
use Seboettg\Collection\ArrayList as ArrayList; |
22
|
|
|
use SimpleXMLElement; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Citation |
26
|
|
|
* |
27
|
|
|
* The cs:citation element describes the formatting of citations, which consist of one or more references (“cites”) to |
28
|
|
|
* bibliographic sources. Citations appear in the form of either in-text citations (in the author (e.g. “[Doe]”), |
29
|
|
|
* author-date (“[Doe 1999]”), label (“[doe99]”) or number (“[1]”) format) or notes. The required cs:layout child |
30
|
|
|
* element describes what, and how, bibliographic data should be included in the citations (see Layout). |
31
|
|
|
* |
32
|
|
|
* @package Seboettg\CiteProc\Node\Style |
33
|
|
|
* |
34
|
|
|
* @author Sebastian Böttger <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class Citation extends StyleElement |
37
|
|
|
{ |
38
|
|
|
/** @var CitationOptions */ |
39
|
|
|
private $citationOptions; |
40
|
|
|
|
41
|
160 |
|
public static function factory(SimpleXMLElement $node, Root $parent): Citation |
42
|
|
|
{ |
43
|
160 |
|
$nameOptions = NameOptions::updateNameOptions($node); |
44
|
160 |
|
CiteProc::getContext()->setNameOptions($nameOptions, RenderingMode::CITATION()); |
45
|
|
|
/* cs:citation and cs:bibliography may include a cs:sort child element before the cs:layout element to |
46
|
|
|
* specify the sorting order of respectively cites within citations, and bibliographic entries within |
47
|
|
|
* the bibliography. In the absence of cs:sort, cites and bibliographic entries appear in the order in |
48
|
|
|
* which they are cited. |
49
|
|
|
*/ |
50
|
|
|
|
51
|
160 |
|
$sorting = Sort::factory($node->sort); |
52
|
160 |
|
CiteProc::getContext()->setSorting(RenderingMode::CITATION(), $sorting); |
53
|
160 |
|
$citationOptions = CitationOptions::factory($node); |
54
|
160 |
|
CiteProc::getContext()->setCitationSpecificOptions($citationOptions); |
55
|
160 |
|
$citation = new Citation($nameOptions, $citationOptions); |
56
|
160 |
|
$layout = Layout::factory($node->layout); |
57
|
160 |
|
if (null !== $layout) { |
58
|
160 |
|
$layout->setParent($citation); |
59
|
160 |
|
$layout->setSorting($sorting); |
60
|
160 |
|
$layout->setStyleOptions($citationOptions); |
61
|
|
|
} |
62
|
160 |
|
$citation->setLayout($layout); |
63
|
160 |
|
$citation->setParent($parent); |
64
|
160 |
|
return $citation; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Citation constructor. |
69
|
|
|
* @param NameOptions $nameOptions |
70
|
|
|
* @param CitationOptions $citationOptions |
71
|
|
|
*/ |
72
|
160 |
|
public function __construct(NameOptions $nameOptions, CitationOptions $citationOptions) |
73
|
|
|
{ |
74
|
160 |
|
$this->nameOptions = $nameOptions; |
75
|
160 |
|
$this->citationOptions = $citationOptions; |
76
|
160 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param array|DataList $data |
80
|
|
|
* @param ArrayListInterface $citationItems |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
103 |
|
public function render($data, ArrayListInterface $citationItems) |
84
|
|
|
{ |
85
|
103 |
|
return $this->layout->render($data, $citationItems); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|