1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Forum Reports. |
4
|
|
|
* These are some basic reporting tools which sit in the CMS for the user to view. |
5
|
|
|
* No fancy graphing tools or anything just some simple querys and numbers |
6
|
|
|
* |
7
|
|
|
* @package forum |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Member Signups Report. |
12
|
|
|
* Lists the Number of people who have signed up in the past months categorized |
13
|
|
|
* by month. |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class ForumReport_MemberSignups extends SS_Report |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function title() |
19
|
|
|
{ |
20
|
|
|
return _t('Forum.FORUMSIGNUPS', 'Forum Signups by Month'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function sourceRecords($params = array()) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$membersQuery = new SQLQuery(); |
|
|
|
|
26
|
|
|
$membersQuery->setFrom('"Member"'); |
27
|
|
|
$membersQuery->setSelect(array( |
28
|
|
|
'Month' => DB::getConn()->formattedDatetimeClause('"Created"', '%Y-%m'), |
|
|
|
|
29
|
|
|
'Signups' => 'COUNT("Created")' |
30
|
|
|
)); |
31
|
|
|
$membersQuery->setGroupBy('"Month"'); |
32
|
|
|
$membersQuery->setOrderBy('"Month"', 'DESC'); |
33
|
|
|
$members = $membersQuery->execute(); |
34
|
|
|
|
35
|
|
|
$output = ArrayList::create(); |
36
|
|
|
foreach ($members as $member) { |
37
|
|
|
$member['Month'] = date('Y F', strtotime($member['Month'])); |
38
|
|
|
$output->add(ArrayData::create($member)); |
39
|
|
|
} |
40
|
|
|
return $output; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function columns() |
44
|
|
|
{ |
45
|
|
|
$fields = array( |
46
|
|
|
'Month' => 'Month', |
47
|
|
|
'Signups' => 'Signups' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $fields; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function group() |
54
|
|
|
{ |
55
|
|
|
return 'Forum Reports'; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Member Posts Report. |
61
|
|
|
* Lists the Number of Posts made in the forums in the past months categorized |
62
|
|
|
* by month. |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
class ForumReport_MonthlyPosts extends SS_Report |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
public function title() |
68
|
|
|
{ |
69
|
|
|
return _t('Forum.FORUMMONTHLYPOSTS', 'Forum Posts by Month'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function sourceRecords($params = array()) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$postsQuery = new SQLQuery(); |
|
|
|
|
75
|
|
|
$postsQuery->setFrom('"Post"'); |
76
|
|
|
$postsQuery->setSelect(array( |
77
|
|
|
'Month' => DB::getConn()->formattedDatetimeClause('"Created"', '%Y-%m'), |
|
|
|
|
78
|
|
|
'Posts' => 'COUNT("Created")' |
79
|
|
|
)); |
80
|
|
|
$postsQuery->setGroupBy('"Month"'); |
81
|
|
|
$postsQuery->setOrderBy('"Month"', 'DESC'); |
82
|
|
|
$posts = $postsQuery->execute(); |
83
|
|
|
|
84
|
|
|
$output = ArrayList::create(); |
85
|
|
|
foreach ($posts as $post) { |
86
|
|
|
$post['Month'] = date('Y F', strtotime($post['Month'])); |
87
|
|
|
$output->add(ArrayData::create($post)); |
88
|
|
|
} |
89
|
|
|
return $output; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function columns() |
93
|
|
|
{ |
94
|
|
|
$fields = array( |
95
|
|
|
'Month' => 'Month', |
96
|
|
|
'Posts' => 'Posts' |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $fields; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function group() |
103
|
|
|
{ |
104
|
|
|
return 'Forum Reports'; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.