1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package net.nemein.wiki |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Wikipage latest handler |
11
|
|
|
* |
12
|
|
|
* @package net.nemein.wiki |
13
|
|
|
*/ |
14
|
|
|
class net_nemein_wiki_handler_latest extends midcom_baseclasses_components_handler |
15
|
|
|
{ |
16
|
|
|
private $_updated_pages = 0; |
17
|
|
|
private $_max_pages = 0; |
18
|
|
|
private $latest_pages = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* List all items updated with then given timeframe |
22
|
|
|
*/ |
23
|
1 |
|
private function _seek_updated(int $from, int $to = null) |
24
|
|
|
{ |
25
|
1 |
|
if ($to === null) { |
26
|
1 |
|
$to = time(); |
27
|
|
|
} |
28
|
|
|
|
29
|
1 |
|
$qb = net_nemein_wiki_wikipage::new_query_builder(); |
30
|
1 |
|
$qb->add_constraint('topic.component', '=', 'net.nemein.wiki'); |
31
|
1 |
|
$qb->add_constraint('topic', 'INTREE', $this->_topic->id); |
32
|
1 |
|
$qb->add_constraint('metadata.revised', '<=', date('Y-m-d H:i:s', $to)); |
33
|
1 |
|
$qb->add_constraint('metadata.revised', '>=', date('Y-m-d H:i:s', $from)); |
34
|
1 |
|
$qb->add_order('metadata.revised', 'DESC'); |
35
|
|
|
|
36
|
1 |
|
$rcs = midcom::get()->rcs; |
37
|
|
|
|
38
|
1 |
|
foreach ($qb->execute() as $page) { |
39
|
|
|
$rcs_handler = $rcs->load_backend($page); |
40
|
|
|
|
41
|
|
|
// Get object history |
42
|
|
|
foreach ($rcs_handler->get_history()->all() as $history) { |
43
|
|
|
if ($this->_updated_pages >= $this->_max_pages) { |
44
|
|
|
// End here |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ( $history['date'] < $from |
49
|
|
|
|| $history['date'] > $to) { |
50
|
|
|
// We can ignore revisions outside the timeframe |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
$history['object'] = $page; |
54
|
|
|
$this->_add_history_entry($history); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function _add_history_entry(array $entry) |
60
|
|
|
{ |
61
|
|
|
$history_date = date('Y-m-d', $entry['date']); |
62
|
|
|
|
63
|
|
|
if (!isset($this->latest_pages[$history_date])) { |
64
|
|
|
$this->latest_pages[$history_date] = []; |
65
|
|
|
} |
66
|
|
|
$this->latest_pages[$history_date][] = $entry; |
67
|
|
|
$this->_updated_pages++; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function _handler_latest(array &$data) |
71
|
|
|
{ |
72
|
1 |
|
$this->_max_pages = $this->_config->get('latest_count'); |
73
|
|
|
|
74
|
|
|
// Start by looking for items within last two weeks |
75
|
1 |
|
$from = strtotime('14 days ago'); |
76
|
1 |
|
$this->_seek_updated($from); |
77
|
|
|
|
78
|
1 |
|
$i = 0; |
79
|
1 |
|
while ( $this->_updated_pages < $this->_max_pages |
80
|
|
|
&& $i < 20) { |
81
|
|
|
// Expand seek by another two weeks |
82
|
1 |
|
$to = $from; |
83
|
1 |
|
$from = strtotime('14 days ago', $to); |
84
|
1 |
|
$this->_seek_updated($from, $to); |
85
|
1 |
|
$i++; |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
$data['view_title'] = sprintf($this->_l10n->get('latest updates in %s'), $this->_topic->extra); |
89
|
1 |
|
midcom::get()->head->set_pagetitle($data['view_title']); |
90
|
|
|
|
91
|
1 |
|
$this->add_breadcrumb('latest/', $data['view_title']); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
public function _show_latest(string $handler_id, array &$data) |
95
|
|
|
{ |
96
|
1 |
|
if (!empty($this->latest_pages)) { |
97
|
|
|
krsort($this->latest_pages); |
98
|
|
|
$dates_shown = []; |
99
|
|
|
midcom_show_style('view-latest-header'); |
100
|
|
|
foreach ($this->latest_pages as $date => $versions) { |
101
|
|
|
if (!isset($dates_shown[$date])) { |
102
|
|
|
$data['date'] = $date; |
103
|
|
|
midcom_show_style('view-latest-date'); |
104
|
|
|
$dates_shown[$date] = true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
foreach ($versions as $history) { |
108
|
|
|
$data['history'] = $history; |
109
|
|
|
midcom_show_style('view-latest-item'); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
midcom_show_style('view-latest-footer'); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|