Completed
Pull Request — master (#203)
by
unknown
40:36
created

ForumReport_MemberSignups::columns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\Forum\Reports;
4
5
use SilverStripe\ORM\DB;
6
use SilverStripe\ORM\ArrayList;
7
use SilverStripe\View\ArrayData;
8
use SilverStripe\Reports\Report;
9
10
/**
11
 * Forum Reports.
12
 * These are some basic reporting tools which sit in the CMS for the user to view.
13
 * No fancy graphing tools or anything just some simple querys and numbers
14
 *
15
 * @package forum
16
 */
17
18
/**
19
 * Member Signups Report.
20
 * Lists the Number of people who have signed up in the past months categorized
21
 * by month.
22
 */
23 View Code Duplication
class ForumReport_MemberSignups extends Report
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
24
{
25
26
    public function title()
27
    {
28
        return _t('Forum.FORUMSIGNUPS', 'Forum Signups by Month');
29
    }
30
31
    public function sourceRecords($params = array())
32
    {
33
        $membersQuery = new SQLQuery();
34
        $membersQuery->setFrom('"Member"');
35
        $membersQuery->setSelect(array(
36
            'Month' => DB::getConn()->formattedDatetimeClause('"Created"', '%Y-%m'),
37
            'Signups' => 'COUNT("Created")'
38
        ));
39
        $membersQuery->setGroupBy('"Month"');
40
        $membersQuery->setOrderBy('"Month"', 'DESC');
41
        $members = $membersQuery->execute();
42
43
        $output = ArrayList::create();
44
        foreach ($members as $member) {
45
            $member['Month'] = date('Y F', strtotime($member['Month']));
46
            $output->add(ArrayData::create($member));
47
        }
48
        return $output;
49
    }
50
51
    public function columns()
52
    {
53
        $fields = array(
54
            'Month' => 'Month',
55
            'Signups' => 'Signups'
56
        );
57
58
        return $fields;
59
    }
60
61
    public function group()
62
    {
63
        return 'Forum Reports';
64
    }
65
}
66
67
/**
68
 * Member Posts Report.
69
 * Lists the Number of Posts made in the forums in the past months categorized
70
 * by month.
71
 */
72 View Code Duplication
class ForumReport_MonthlyPosts extends Report
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
73
{
74
75
    public function title()
76
    {
77
        return _t('Forum.FORUMMONTHLYPOSTS', 'Forum Posts by Month');
78
    }
79
80
    public function sourceRecords($params = array())
81
    {
82
        $postsQuery = new SQLQuery();
83
        $postsQuery->setFrom('"Post"');
84
        $postsQuery->setSelect(array(
85
            'Month' => DB::getConn()->formattedDatetimeClause('"Created"', '%Y-%m'),
86
            'Posts' => 'COUNT("Created")'
87
        ));
88
        $postsQuery->setGroupBy('"Month"');
89
        $postsQuery->setOrderBy('"Month"', 'DESC');
90
        $posts = $postsQuery->execute();
91
92
        $output = ArrayList::create();
93
        foreach ($posts as $post) {
94
            $post['Month'] = date('Y F', strtotime($post['Month']));
95
            $output->add(ArrayData::create($post));
96
        }
97
        return $output;
98
    }
99
100
    public function columns()
101
    {
102
        $fields = array(
103
            'Month' => 'Month',
104
            'Posts' => 'Posts'
105
        );
106
107
        return $fields;
108
    }
109
110
    public function group()
111
    {
112
        return 'Forum Reports';
113
    }
114
}
115