Last active
December 16, 2015 07:38
-
-
Save wilr/5400107 to your computer and use it in GitHub Desktop.
An example SS_Report for LastLoggedIn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LastLoggedInReport extends SS_Report { | |
public function title() { | |
if(isset($_GET['ago'])) { | |
$ago = (int) $_GET['ago']; | |
return "Last logged in $ago months ago"; | |
} | |
return "Last logged in ago.."; | |
} | |
public function records($params = null) { | |
$records = new ArrayList(); | |
if(isset($_GET['date'])) { | |
list($month, $year) = explode('-', $_GET['date']); | |
$agents = Group::get()->filter(array( | |
'Code' => 'users' | |
))->first(); | |
$agentsId = $agents->ID; | |
$data = Member::get()->where(array( | |
"EXTRACT(YEAR FROM LastVisited) = '$year' | |
AND EXTRACT(MONTH FROM LastVisited) = '$month' | |
AND Group_Members.GroupID = '$agentsId'" | |
))->exclude(array( | |
'TestAgent' => 1 | |
))->innerJoin("Group_Members", "Member.ID = Group_Members.MemberID") | |
->sort('LastVisited ASC'); | |
return $data; | |
} | |
for($i = 0; $i <= 24; $i++) { | |
$t = strtotime("-$i MONTH"); | |
$year = date('Y', $t); | |
$month = date('m', $t); | |
$records->push(new ReportsDataRow(array( | |
'Title' => date('F Y', $t), | |
'Date' => date('m-Y', $t), | |
'I' => $i, | |
'Count' => DB::query(" | |
SELECT COUNT(*) | |
FROM Member | |
WHERE EXTRACT(YEAR FROM LastVisited) = '$year' AND EXTRACT(MONTH FROM LastVisited) = '$month'" | |
)->value() | |
))); | |
} | |
return $records; | |
} | |
public function sourceRecords($params = null) { | |
return $this->records(); | |
} | |
public function getReportField() { | |
$field = parent::getReportField(); | |
$field->getConfig()->getComponentByType('GridFieldPaginator')->setItemsPerPage(2000); | |
return $field; | |
} | |
public function columns() { | |
if(isset($_GET['ago'])) { | |
return array( | |
'FirstName' => array( | |
"formatting" => '<a href=\"users/show/$UrlHash/$Slug\">$value</a>' | |
), | |
'Surname' => array(), | |
'Email' => array(), | |
); | |
} | |
else { | |
return array( | |
"Title" => array( | |
"title" => "Last logged in months ago..", | |
'formatting' => '<a href=\"admin/reports/LastLoggedInReport/?date=$Date&ago=$I\">$I months ago</a>' | |
), | |
"Count" => array() | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ReportsDataRow extends ArrayData { | |
public function canView() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment