Completed
Pull Request — master (#39)
by Sebastian
11:45
created

Context::setCitation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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;
11
use Seboettg\CiteProc\Data\DataList;
12
use Seboettg\CiteProc\Locale\Locale;
13
use Seboettg\CiteProc\Root\Info;
14
use Seboettg\CiteProc\Style\Bibliography;
15
use Seboettg\CiteProc\Style\Citation;
16
use Seboettg\CiteProc\Style\Macro;
17
use Seboettg\CiteProc\Style\Options\BibliographyOptions;
18
use Seboettg\CiteProc\Style\Options\CitationOptions;
19
use Seboettg\CiteProc\Style\Options\GlobalOptions;
20
use Seboettg\CiteProc\Style\Sort\Sort;
21
use Seboettg\CiteProc\Root\Root;
22
use Seboettg\CiteProc\Styles\Css\CssStyle;
23
use Seboettg\Collection\ArrayList;
24
25
26
/**
27
 * Class Context
28
 * @package Seboettg\CiteProc
29
 *
30
 * @author Sebastian Böttger <[email protected]>
31
 */
32
class Context
33
{
34
    /**
35
     * @var ArrayList
36
     */
37
    private $macros;
38
39
    /**
40
     * @var Locale
41
     */
42
    private $locale;
43
44
    /**
45
     * @var Bibliography
46
     */
47
    private $bibliography;
48
49
    /**
50
     * @var Citation
51
     */
52
    private $citation;
53
54
    /**
55
     * @var Sort
56
     */
57
    private $sorting;
58
59
    /**
60
     * @var string
61
     */
62
    private $mode;
63
64
    /**
65
     * @var DataList
66
     */
67
    private $citationItems;
68
69
    /**
70
     * @var ArrayList
71
     */
72
    private $results;
73
74
    /**
75
     * @var Root
76
     */
77
    private $root;
78
79
    /**
80
     * @var GlobalOptions
81
     */
82
    private $globalOptions;
83
84
    /**
85
     * @var BibliographyOptions
86
     */
87
    private $bibliographySpecificOptions;
88
89
    /**
90
     * @var CitationOptions
91
     */
92
    private $citationSpecificOptions;
93
94
    /**
95
     * @var string (sorting|rendering)
96
     */
97
    private $renderingState;
98
99
    /**
100
     * @var CssStyle
101
     */
102
    private $cssStyle;
103
104
    /**
105
     * @var Info
106
     */
107
    private $info;
108
109
    /**
110
     * @var bool
111
     */
112
    private $citationsAsArray = false;
113
114
    public function __construct($locale = null)
115
    {
116
        if (!empty($locale)) {
117
            $this->locale = $locale;
118
        }
119
120
        $this->macros = new ArrayList();
121
        $this->citationItems = new DataList();
122
        $this->results = new ArrayList();
123
        $this->renderingState = "rendering";
124
    }
125
126
    public function addMacro($key, $macro)
127
    {
128
        $this->macros->add($key, $macro);
129
    }
130
131
    /**
132
     * @param $key
133
     * @return Macro
134
     */
135
    public function getMacro($key)
136
    {
137
        return $this->macros->get($key);
138
    }
139
140
    /**
141
     * @param Locale $locale
142
     */
143
    public function setLocale(Locale $locale)
144
    {
145
        $this->locale = $locale;
146
    }
147
148
    /**
149
     * @return Locale
150
     */
151
    public function getLocale()
152
    {
153
        return $this->locale;
154
    }
155
156
    /**
157
     * @return Bibliography
158
     */
159
    public function getBibliography()
160
    {
161
        return $this->bibliography;
162
    }
163
164
    /**
165
     * @param Bibliography $bibliography
166
     */
167
    public function setBibliography(Bibliography $bibliography)
168
    {
169
        $this->bibliography = $bibliography;
170
    }
171
172
    /**
173
     * @return Citation
174
     */
175
    public function getCitation()
176
    {
177
        return $this->citation;
178
    }
179
180
    /**
181
     * @param Citation $citation
182
     */
183
    public function setCitation($citation)
184
    {
185
        $this->citation = $citation;
186
    }
187
188
    /**
189
     * @param $citationsAsArray
190
     */
191
    public function setCitationsAsArray($citationsAsArray = true)
192
    {
193
        $this->citationsAsArray = $citationsAsArray;
194
    }
195
196
    public function isCitationsAsArray()
197
    {
198
        return $this->citationsAsArray;
199
    }
200
201
    public function setSorting($sorting)
202
    {
203
        $this->sorting = $sorting;
204
    }
205
206
    public function getSorting()
207
    {
208
        return $this->sorting;
209
    }
210
211
    /**
212
     * return the render mode (citation|bibliography)
213
     * @return string
214
     */
215
    public function getMode()
216
    {
217
        return $this->mode;
218
    }
219
220
    /**
221
     * @param string $mode
222
     */
223
    public function setMode($mode)
224
    {
225
        $this->mode = $mode;
226
    }
227
228
    /**
229
     * returns true if the render mode is set to citation
230
     * @return bool
231
     */
232
    public function isModeCitation()
233
    {
234
        return $this->mode === "citation";
235
    }
236
237
    /**
238
     * returns true if the render mode is set to bibliography
239
     * @return bool
240
     */
241
    public function isModeBibliography()
242
    {
243
        return $this->mode === "bibliography";
244
    }
245
246
    /**
247
     * @return DataList
248
     */
249
    public function getCitationItems()
250
    {
251
        return $this->citationItems;
252
    }
253
254
    /**
255
     * @param DataList $citationItems
256
     */
257
    public function setCitationItems(&$citationItems)
258
    {
259
        $this->citationItems = $citationItems;
260
    }
261
262
    public function hasCitationItems()
263
    {
264
        return ($this->citationItems->count() > 0);
265
    }
266
267
    /**
268
     * @return ArrayList
269
     */
270
    public function getMacros()
271
    {
272
        return $this->macros;
273
    }
274
275
    /**
276
     * @return ArrayList
277
     */
278
    public function getResults()
279
    {
280
        return $this->results;
281
    }
282
283
    /**
284
     * @return Root
285
     */
286
    public function getRoot()
287
    {
288
        return $this->root;
289
    }
290
291
    /**
292
     * @param Root $root
293
     */
294
    public function setRoot(Root $root)
295
    {
296
        $this->root = $root;
297
    }
298
299
    /**
300
     * @return GlobalOptions
301
     */
302
    public function getGlobalOptions()
303
    {
304
        return $this->globalOptions;
305
    }
306
307
    /**
308
     * @param GlobalOptions $globalOptions
309
     */
310
    public function setGlobalOptions(GlobalOptions $globalOptions)
311
    {
312
        $this->globalOptions = $globalOptions;
313
    }
314
315
    /**
316
     * @return string
317
     */
318
    public function getRenderingState()
319
    {
320
        return $this->renderingState;
321
    }
322
323
    /**
324
     * @param string $renderingState
325
     */
326
    public function setRenderingState($renderingState)
327
    {
328
        $this->renderingState = $renderingState;
329
    }
330
331
    /**
332
     * @return BibliographyOptions
333
     */
334
    public function getBibliographySpecificOptions()
335
    {
336
        return $this->bibliographySpecificOptions;
337
    }
338
339
    /**
340
     * @param BibliographyOptions $bibliographySpecificOptions
341
     */
342
    public function setBibliographySpecificOptions(BibliographyOptions $bibliographySpecificOptions)
343
    {
344
        $this->bibliographySpecificOptions = $bibliographySpecificOptions;
345
    }
346
347
    /**
348
     * @return CitationOptions
349
     */
350
    public function getCitationSpecificOptions()
351
    {
352
        return $this->citationSpecificOptions;
353
    }
354
355
    /**
356
     * @param CitationOptions $citationSpecificOptions
357
     */
358
    public function setCitationSpecificOptions(CitationOptions $citationSpecificOptions)
359
    {
360
        $this->citationSpecificOptions = $citationSpecificOptions;
361
    }
362
363
    /**
364
     * @param CssStyle $cssStyle
365
     */
366
    public function setCssStyle(CssStyle $cssStyle)
367
    {
368
        $this->cssStyle = $cssStyle;
369
    }
370
371
    /**
372
     * @return CssStyle
373
     */
374
    public function getCssStyle()
375
    {
376
        return $this->cssStyle;
377
    }
378
379
    public function setInfo(Info $info)
380
    {
381
        $this->info = $info;
382
    }
383
384
    public function getInfo()
385
    {
386
        return $this->info;
387
    }
388
}