|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Addons\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\Director; |
|
6
|
|
|
use SilverStripe\Addons\Model\Addon; |
|
7
|
|
|
use SilverStripe\Addons\Model\AddonVersion; |
|
8
|
|
|
use SilverStripe\ORM\ArrayList; |
|
9
|
|
|
use SilverStripe\ORM\ArrayData; |
|
10
|
|
|
use SilverStripe\ORM\MySQLQuery; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The home page controller. |
|
14
|
|
|
*/ |
|
15
|
|
|
class HomeController extends SiteController |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
private static $popular_blacklist = [ |
|
19
|
|
|
'silverstripe/framework', |
|
20
|
|
|
'silverstripe/cms', |
|
21
|
|
|
'silverstripe/sqlite3', |
|
22
|
|
|
'silverstripe/postgresql', |
|
23
|
|
|
'silverstripe-themes/simple' |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
27
|
|
|
'index' |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function index() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->renderWith(array('Home', 'Page')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function Title() |
|
36
|
|
|
{ |
|
37
|
|
|
return 'Home'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function Link($action = null) |
|
41
|
|
|
{ |
|
42
|
|
|
return Director::baseURL(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function PopularAddons($limit = 10) |
|
46
|
|
|
{ |
|
47
|
|
|
return Addon::get() |
|
48
|
|
|
->sort('Downloads', 'DESC') |
|
49
|
|
|
->exclude('Name', $this->config()->popular_blacklist) |
|
50
|
|
|
->limit($limit); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function NewestAddons($limit = 10) |
|
54
|
|
|
{ |
|
55
|
|
|
return Addon::get()->sort('Released', 'DESC')->limit($limit); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function RandomAddons($limit = 10) |
|
59
|
|
|
{ |
|
60
|
|
|
return Addon::get()->sort(DB::getConn()->random(), 'DESC')->limit($limit); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function NewestVersions($limit = 10) |
|
64
|
|
|
{ |
|
65
|
|
|
return AddonVersion::get() |
|
66
|
|
|
->filter('Development', false) |
|
67
|
|
|
->sort('Released', 'DESC') |
|
68
|
|
|
->limit($limit); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function ChartData() |
|
72
|
|
|
{ |
|
73
|
|
|
$chartData = array(); |
|
74
|
|
|
$list = ArrayList::create(array()); |
|
75
|
|
|
|
|
76
|
|
|
$sqlQuery = new MySQLQuery(); |
|
77
|
|
|
$sqlQuery->setFrom('Addon'); |
|
78
|
|
|
$sqlQuery->setSelect('DATE(Created) as Created'); |
|
79
|
|
|
$sqlQuery->selectField('COUNT(*)', 'CountInOneDay'); |
|
80
|
|
|
$sqlQuery->addWhere('"Created" >= DATE_SUB(NOW(), INTERVAL 30 DAY)'); |
|
81
|
|
|
$sqlQuery->addGroupBy('DATE(Created)'); |
|
82
|
|
|
|
|
83
|
|
|
$result = $sqlQuery->execute(); |
|
84
|
|
|
|
|
85
|
|
|
if(count($result)) { |
|
86
|
|
|
foreach($result as $row) { |
|
87
|
|
|
$date = date('j M Y', strtotime($row['Created'])); |
|
88
|
|
|
if(!isset($chartData[$date])) { |
|
89
|
|
|
$chartData[$date] = $row['CountInOneDay']; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if(count($chartData)) { |
|
95
|
|
|
foreach($chartData as $x => $y) { |
|
96
|
|
|
$list->push(ArrayData::create(array( |
|
97
|
|
|
'XValue' => $x, |
|
98
|
|
|
'YValue' => $y |
|
99
|
|
|
))); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $list; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|