1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\Document; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A dynamic PageView is created when the following keywords are found in the FrontMatter of a PageView: |
12
|
|
|
* |
13
|
|
|
* - collection |
14
|
|
|
* - dataset |
15
|
|
|
* |
16
|
|
|
* This PageView type will contain references to all of the RepeatableItems |
17
|
|
|
*/ |
18
|
|
|
class DynamicPageView extends PageView |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The RepeatableItems that belong to this PageView. |
22
|
|
|
* |
23
|
|
|
* @var RepeatableItem[] |
24
|
|
|
*/ |
25
|
|
|
private $repeatableItems; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
6 |
|
public function __construct($filePath) |
31
|
|
|
{ |
32
|
6 |
|
parent::__construct($filePath); |
33
|
|
|
|
34
|
6 |
|
$this->repeatableItems = array(); |
35
|
6 |
|
$this->type = PageView::DYNAMIC_TYPE; |
36
|
6 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add a RepeatableItem to this dynamic PageView. |
40
|
|
|
* |
41
|
|
|
* @param RepeatableItem $repeatableItem |
42
|
|
|
*/ |
43
|
5 |
|
public function addRepeatableItem(RepeatableItem &$repeatableItem) |
44
|
|
|
{ |
45
|
5 |
|
$this->repeatableItems[$repeatableItem->getObjectName()] = &$repeatableItem; |
46
|
5 |
|
$repeatableItem->setParentPageView($this); |
47
|
5 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Remove a RepeatableItem from the list of items that this dynamic PageView is responsible for. |
51
|
|
|
* |
52
|
|
|
* @param RepeatableItem $repeatableItem |
53
|
|
|
*/ |
54
|
|
|
public function delRepeatableItem(RepeatableItem &$repeatableItem) |
55
|
|
|
{ |
56
|
|
|
unset($this->repeatableItems[$repeatableItem->getObjectName()]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get all of the RepeatableItem that belong to this dynamic PageView. |
61
|
|
|
* |
62
|
|
|
* @return RepeatableItem[] |
63
|
|
|
*/ |
64
|
4 |
|
public function getRepeatableItems() |
65
|
|
|
{ |
66
|
4 |
|
return $this->repeatableItems; |
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
public function getRepeatableNamespace() |
|
|
|
|
70
|
|
|
{ |
71
|
3 |
|
$fm = $this->getFrontMatter(false); |
|
|
|
|
72
|
|
|
|
73
|
3 |
|
if (isset($fm['collection'])) |
74
|
3 |
|
{ |
75
|
3 |
|
return $fm['collection']; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $fm['dataset']; |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
public function getObjectName() |
82
|
|
|
{ |
83
|
3 |
|
return $this->getRepeatableNamespace(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.