Skip to content

Commit

Permalink
Merge pull request #164 from 3Dgoo/feature/reports-fix-0.8
Browse files Browse the repository at this point in the history
Fixing forum reports.
  • Loading branch information
edlinklater committed Oct 26, 2015
2 parents 2068a95 + 84aafca commit bc80636
Showing 1 changed file with 51 additions and 44 deletions.
95 changes: 51 additions & 44 deletions code/reports/ForumReport.php
Expand Up @@ -13,33 +13,38 @@
* by month.
*/
class ForumReport_MemberSignups extends SS_Report {
function title() {
return _t('Forum.FORUMSIGNUPS',"Forum Signups by Month");

public function title() {
return _t('Forum.FORUMSIGNUPS', 'Forum Signups by Month');
}
function records($params = array()) {
$members = DB::query("
SELECT DATE_FORMAT(\"Created\", '%Y %M') AS \"Month\", COUNT(\"Created\") AS \"NumberJoined\"
FROM \"Member\"
GROUP BY DATE_FORMAT(\"Created\", '%M %Y')
ORDER BY \"Created\" DESC
");
$output = array();
foreach($members->map() as $record => $value) {
$output[$record] = $value;

public function sourceRecords($params = array()) {
$membersQuery = new SQLQuery();
$membersQuery->setFrom('Member');
$membersQuery->selectField('DATE_FORMAT("Created", \'%Y %M\')', 'Month');
$membersQuery->selectField('COUNT("Created")', 'Signups');
$membersQuery->setGroupBy('Month');
$membersQuery->setOrderBy('Created', 'DESC');
$members = $membersQuery->execute();

$output = ArrayList::create();
foreach ($members as $member) {
$output->add(ArrayData::create($member));
}
return $output;

}
function fieldsToShow() {

public function columns() {
$fields = array(
'Month' => 'Month',
'Signups' => 'Signups'
);

return $fields;
}
function getHTML() {
$result = "<ul class=\"$this->class\">\n";
foreach($this->records() as $record => $value) {
$signups = ($value == 1) ? "Signup" : "Signups";
$result .= "<li>". $record . " - ". $value . ' '. $signups ."</li>";
}
$result .= "</ul>";
return $result;

public function group() {
return 'Forum Reports';
}
}

Expand All @@ -49,35 +54,37 @@ function getHTML() {
* by month.
*/
class ForumReport_MonthlyPosts extends SS_Report {
function title() {
return _t('Forum.FORUMMONTHLYPOSTS',"Forum Posts by Month");

public function title() {
return _t('Forum.FORUMMONTHLYPOSTS', 'Forum Posts by Month');
}

function records($params = array()) {
$members = DB::query("
SELECT DATE_FORMAT(\"Created\", '%Y %M') AS \"Month\", COUNT(\"Created\") AS \"PostsTotal\"
FROM \"Post\"
GROUP BY DATE_FORMAT(\"Created\", '%M %Y')
ORDER BY \"Created\" DESC
");
$output = array();
foreach($members->map() as $record => $value) {
$output[$record] = $value;
public function sourceRecords($params = array()) {
$postsQuery = new SQLQuery();
$postsQuery->setFrom('Post');
$postsQuery->selectField('DATE_FORMAT("Created", \'%Y %M\')', 'Month');
$postsQuery->selectField('COUNT("Created")', 'Posts');
$postsQuery->setGroupBy('Month');
$postsQuery->setOrderBy('Created', 'DESC');
$posts = $postsQuery->execute();

$output = ArrayList::create();
foreach ($posts as $post) {
$output->add(ArrayData::create($post));
}
return $output;

}

function fieldsToShow() {
public function columns() {
$fields = array(
'Month' => 'Month',
'Posts' => 'Posts'
);

return $fields;
}

function getHTML() {
$result = "<ul class=\"$this->class\">\n";
foreach($this->records() as $record => $value) {
$signups = ($value == 1) ? "Post" : "Posts";
$result .= "<li>". $record . " - ". $value . ' '. $signups ."</li>";
}
$result .= "</ul>";
return $result;
public function group() {
return 'Forum Reports';
}
}

0 comments on commit bc80636

Please sign in to comment.