|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package sitemaker |
|
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace blitze\content\blocks; |
|
11
|
|
|
|
|
12
|
|
|
class archive extends \blitze\sitemaker\services\blocks\driver\block |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
15
|
|
|
protected $db; |
|
16
|
|
|
|
|
17
|
|
|
/* @var \phpbb\controller\helper */ |
|
18
|
|
|
protected $helper; |
|
19
|
|
|
|
|
20
|
|
|
/* @var \blitze\content\services\types */ |
|
21
|
|
|
protected $content_types; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \blitze\sitemaker\services\forum\data */ |
|
24
|
|
|
protected $forum; |
|
25
|
|
|
|
|
26
|
|
|
/** @var integer */ |
|
27
|
|
|
protected $cache_time; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
* |
|
32
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database object |
|
33
|
|
|
* @param \phpbb\controller\helper $helper Helper object |
|
34
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
|
35
|
|
|
* @param \blitze\sitemaker\services\forum\data $forum Forum Data object |
|
36
|
|
|
* @param integer $cache_time Cache results for 3 hours by default |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \blitze\content\services\types $content_types, \blitze\sitemaker\services\forum\data $forum, $cache_time) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->db = $db; |
|
41
|
|
|
$this->helper = $helper; |
|
42
|
|
|
$this->content_types = $content_types; |
|
43
|
|
|
$this->forum = $forum; |
|
44
|
|
|
$this->cache_time = $cache_time; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function get_config(array $settings) |
|
51
|
|
|
{ |
|
52
|
|
|
$content_type_options = $this->get_content_type_options(); |
|
53
|
|
|
$month_dsp_options = array('short' => 'MONTH_FORMAT_SHORT', 'long' => 'MONTH_FORMAT_LONG'); |
|
54
|
|
|
|
|
55
|
|
|
return array( |
|
56
|
|
|
'legend1' => 'SETTINGS', |
|
57
|
|
|
'forum_id' => array('lang' => 'CONTENT_TYPE', 'validate' => 'string', 'type' => 'select', 'options' => $content_type_options, 'default' => 0, 'explain' => false), |
|
58
|
|
|
'show_count' => array('lang' => 'SHOW_TOPICS_COUNT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false, 'default' => 0), |
|
59
|
|
|
'all_months' => array('lang' => 'SHOW_ALL_MONTHS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false, 'default' => 1), |
|
60
|
|
|
'month_dsp' => array('lang' => 'MONTH_FORMAT', 'validate' => 'bool', 'type' => 'radio', 'options' => $month_dsp_options, 'explain' => false, 'default' => 'long'), |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function display(array $bdata, $edit_mode = false) |
|
68
|
|
|
{ |
|
69
|
|
|
extract($this->get_query_params($bdata['settings'])); |
|
70
|
|
|
|
|
71
|
|
|
$sql = $this->db->sql_build_query('SELECT', $this->get_sql_array($forum_ids)); |
|
72
|
|
|
$result = $this->db->sql_query($sql, $this->cache_time); |
|
73
|
|
|
|
|
74
|
|
|
$archive = array(); |
|
75
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
|
76
|
|
|
{ |
|
77
|
|
|
$archive[$row['year']]['name'] = $row['year']; |
|
78
|
|
|
$archive[$row['year']]['months'][$row['month'] - 1] = array( |
|
79
|
|
|
'count' => $row['total'], |
|
80
|
|
|
'url' => $this->helper->route($route_name, $route_params + array( |
|
81
|
|
|
'filter_type' => 'archive', |
|
82
|
|
|
'filter_value' => $row['year'] . '-' . $row['month'], |
|
83
|
|
|
)), |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
$this->db->sql_freeresult($result); |
|
87
|
|
|
|
|
88
|
|
|
$this->ptemplate->assign_vars(array_merge($bdata['settings'], array('archive' => $archive))); |
|
89
|
|
|
|
|
90
|
|
|
return array( |
|
91
|
|
|
'title' => 'ARCHIVES', |
|
92
|
|
|
'content' => $this->ptemplate->render_view('blitze/content', 'blocks/archive.html', 'archive_block'), |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param array $settings |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function get_query_params(array $settings) |
|
101
|
|
|
{ |
|
102
|
|
|
if ($settings['forum_id']) |
|
103
|
|
|
{ |
|
104
|
|
|
return array( |
|
105
|
|
|
'forum_ids' => (array) $settings['forum_id'], |
|
106
|
|
|
'route_name' => 'blitze_content_index', |
|
107
|
|
|
'route_params' => array('type' => $this->content_types->get_forum_type($settings['forum_id'])), |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
else |
|
111
|
|
|
{ |
|
112
|
|
|
return array( |
|
113
|
|
|
'forum_ids' => array_keys($this->content_types->get_forum_types()), |
|
114
|
|
|
'route_name' => 'blitze_content_index_filter', |
|
115
|
|
|
'route_params' => array(), |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param array $forum_ids |
|
122
|
|
|
* @return array |
|
123
|
|
|
*/ |
|
124
|
|
|
protected function get_sql_array(array $forum_ids) |
|
125
|
|
|
{ |
|
126
|
|
|
$sql_array = array( |
|
127
|
|
|
'SELECT' => array('YEAR(FROM_UNIXTIME(t.topic_time)) AS year, MONTH(FROM_UNIXTIME(t.topic_time)) AS month, COUNT(t.topic_id) AS total'), |
|
128
|
|
|
'WHERE' => array($this->db->sql_in_set('t.forum_id', $forum_ids)), |
|
129
|
|
|
'GROUP_BY' => 'year, month', |
|
130
|
|
|
'ORDER_BY' => 'year DESC', |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
return $this->forum->query(false, false) |
|
134
|
|
|
->fetch_custom($sql_array, array('SELECT')) |
|
135
|
|
|
->build(true, false, false) |
|
136
|
|
|
->get_sql_array(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return array |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function get_content_type_options() |
|
143
|
|
|
{ |
|
144
|
|
|
$content_types = $this->content_types->get_all_types(); |
|
145
|
|
|
|
|
146
|
|
|
$content_type_options = array('' => 'CONTENT_TYPE_ANY'); |
|
147
|
|
|
foreach ($content_types as $type => $entity) |
|
148
|
|
|
{ |
|
149
|
|
|
$content_type_options[$entity->get_forum_id()] = $entity->get_content_langname(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return $content_type_options; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|