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
|
|
|
use allejo\stakx\FrontMatter\ExpandedValue; |
11
|
|
|
|
12
|
|
|
class RepeaterPageView extends PageView |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* An iterator for the permalinks used in order for this entity to be treated as a static PageView. |
16
|
|
|
* |
17
|
|
|
* @var \ArrayIterator |
18
|
|
|
*/ |
19
|
|
|
private $permalinksIterator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* All of the expanded permalinks. |
23
|
|
|
* |
24
|
|
|
* @var ExpandedValue[] |
25
|
|
|
*/ |
26
|
|
|
private $permalinks; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* All of expanded redirects that should point to the respective permalink; this is estimated by index. |
30
|
|
|
* |
31
|
|
|
* @var ExpandedValue[][] |
32
|
|
|
*/ |
33
|
|
|
private $redirectLinks; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
2 |
|
public function __construct($filePath) |
39
|
|
|
{ |
40
|
2 |
|
parent::__construct($filePath); |
41
|
|
|
|
42
|
2 |
|
$this->type = PageView::REPEATER_TYPE; |
43
|
|
|
|
44
|
2 |
|
$this->configureValues(); |
45
|
2 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the expanded values for the permalinks to this PageView. |
49
|
|
|
* |
50
|
|
|
* @return ExpandedValue[] |
51
|
|
|
*/ |
52
|
|
|
public function getRepeaterPermalinks() |
53
|
|
|
{ |
54
|
|
|
return $this->permalinks; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the expanded values for the redirects pointing to this PageView. |
59
|
|
|
* |
60
|
|
|
* @return ExpandedValue[][] |
61
|
|
|
*/ |
62
|
|
|
public function getRepeaterRedirects() |
63
|
|
|
{ |
64
|
|
|
return $this->redirectLinks; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* When looping through permalinks in a RepeaterPageView, the permalink needs to be updated each time so that it may |
69
|
|
|
* behave as a static PageView. |
70
|
|
|
*/ |
71
|
|
|
public function bumpPermalink() |
72
|
|
|
{ |
73
|
|
|
$this->permalink = $this->permalinksIterator->current()->getEvaluated(); |
74
|
|
|
$this->permalinksIterator->next(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Rewind the permalink iterator to the beginning. |
79
|
|
|
*/ |
80
|
2 |
|
public function rewindPermalink() |
81
|
|
|
{ |
82
|
2 |
|
$this->permalinksIterator->rewind(); |
83
|
2 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Setup this object. |
87
|
|
|
*/ |
88
|
2 |
|
private function configureValues() |
89
|
|
|
{ |
90
|
|
|
// Cause the Front Matter to be evaluated |
91
|
2 |
|
$this->getFrontMatter(); |
92
|
|
|
|
93
|
2 |
|
$evaluated = $this->frontMatter['permalink']; |
94
|
|
|
|
95
|
2 |
|
$this->permalinks = $evaluated[0]; |
96
|
2 |
|
array_shift($evaluated); |
97
|
2 |
|
$this->redirectLinks = $evaluated; |
98
|
|
|
|
99
|
2 |
|
$this->permalinksIterator = new \ArrayIterator($this->permalinks); |
100
|
2 |
|
} |
101
|
|
|
} |
102
|
|
|
|