1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2018 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\Document; |
9
|
|
|
|
10
|
|
|
use __\__; |
11
|
|
|
use allejo\stakx\Filesystem\File; |
12
|
|
|
use allejo\stakx\FrontMatter\ExpandedValue; |
13
|
|
|
|
14
|
|
|
class RepeaterPageView extends BasePageView implements TemplateReadyDocument |
15
|
|
|
{ |
16
|
|
|
/** @var \ArrayIterator An iterator for the permalinks used in order for this entity to be treated as a static PageView. */ |
17
|
|
|
private $permalinksIterator; |
18
|
|
|
|
19
|
|
|
/** @var ExpandedValue[] All of the expanded permalinks. */ |
20
|
|
|
private $permalinks; |
21
|
|
|
|
22
|
|
|
/** @var ExpandedValue[][] All of expanded redirects that should point to the respective permalink; this is estimated by index. */ |
23
|
|
|
private $redirectLinks; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* RepeaterPageView constructor. |
27
|
|
|
*/ |
28
|
3 |
|
public function __construct(File $file) |
29
|
|
|
{ |
30
|
3 |
|
parent::__construct($file); |
31
|
|
|
|
32
|
3 |
|
$this->type = BasePageView::REPEATER_TYPE; |
33
|
3 |
|
} |
34
|
|
|
|
35
|
|
|
public function getPermalinkWhere(array $where) |
36
|
|
|
{ |
37
|
|
|
foreach ($this->permalinks as $expandedValue) |
38
|
|
|
{ |
39
|
|
|
/** @var ExpandedValue[] $permalink */ |
40
|
|
|
$permalink = __::where($expandedValue->getIterators(), $where); |
41
|
|
|
|
42
|
|
|
if (!empty($permalink)) |
43
|
|
|
{ |
44
|
|
|
return $permalink[0]->getEvaluated(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return null; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get the expanded values for the permalinks to this PageView. |
53
|
|
|
* |
54
|
|
|
* @return ExpandedValue[] |
55
|
|
|
*/ |
56
|
3 |
|
public function getRepeaterPermalinks() |
57
|
|
|
{ |
58
|
3 |
|
return $this->permalinks; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the expanded values for the redirects pointing to this PageView. |
63
|
|
|
* |
64
|
|
|
* @return ExpandedValue[][] |
65
|
|
|
*/ |
66
|
3 |
|
public function getRepeaterRedirects() |
67
|
|
|
{ |
68
|
3 |
|
return $this->redirectLinks; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* When looping through permalinks in a RepeaterPageView, the permalink needs to be updated each time so that it may |
73
|
|
|
* behave as a static PageView. |
74
|
|
|
*/ |
75
|
3 |
|
public function bumpPermalink() |
76
|
|
|
{ |
77
|
3 |
|
$this->permalink = $this->permalinksIterator->current()->getEvaluated(); |
78
|
3 |
|
$this->permalinksIterator->next(); |
79
|
3 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Rewind the permalink iterator to the beginning. |
83
|
|
|
*/ |
84
|
3 |
|
public function rewindPermalink() |
85
|
|
|
{ |
86
|
3 |
|
$this->permalinksIterator->rewind(); |
87
|
3 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Configure permalinks from expanded values internally. |
91
|
|
|
*/ |
92
|
3 |
|
public function configurePermalinks() |
93
|
|
|
{ |
94
|
3 |
|
$evaluated = $this->frontMatter['permalink']; |
95
|
|
|
|
96
|
3 |
|
$this->permalinks = $evaluated[0]; |
97
|
3 |
|
array_shift($evaluated); |
98
|
3 |
|
$this->redirectLinks = $evaluated; |
99
|
|
|
|
100
|
3 |
|
$this->permalinksIterator = new \ArrayIterator($this->permalinks); |
101
|
3 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
3 |
|
public function buildPermalink($force = false) |
107
|
|
|
{ |
108
|
3 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
3 |
|
public function createJail() |
114
|
|
|
{ |
115
|
3 |
|
return new JailedDocument($this, self::$whiteListedFunctions); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function jsonSerialize() |
122
|
|
|
{ |
123
|
|
|
return []; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|