forked from psi-4ward/news4ward_archiveMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArchiveMenuHelper.php
52 lines (44 loc) · 1.13 KB
/
ArchiveMenuHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* News4ward
* a contentelement driven news/blog-system
*
* @author Christoph Wiechert <wio@psitrax.de>
* @copyright 4ward.media GbR <http://www.4wardmedia.de>
* @package news4ward_archiveMenu
* @filesource
* @licence LGPL
*/
namespace Psi\News4ward;
class ArchiveMenuHelper extends \System
{
/**
* Return the WHERE-condition if a the url has an archive-parameter
* @return bool|string
*/
public function archiveFilter()
{
if(!$this->Input->get('archive')) return;
if(preg_match("~^\d{4}$~",$this->Input->get('archive')))
{
// filter for year
$year = $this->Input->get('archive');
return array
(
'where' => 'YEAR(FROM_UNIXTIME(tl_news4ward_article.start)) = ?',
'values' => array($year)
);
}
elseif(preg_match("~^\d{4}-\d{1,2}$~",$this->Input->get('archive')))
{
// filter for year and month
list($year,$month) = explode('-',$this->Input->get('archive'));
return array
(
'where' => 'YEAR(FROM_UNIXTIME(tl_news4ward_article.start)) = ? AND MONTH(FROM_UNIXTIME(tl_news4ward_article.start)) = ?',
'values' => array($year, $month)
);
}
return;
}
}