-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Dashboard | ||
|
||
CMS dashboard, uses plastyk/silverstripe-dashboard and extends with custom panels. | ||
# Member Activity | ||
|
||
SilverStripe add on to track member activity | ||
For now - trackes date last visited and number of visits | ||
Future - could add others |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# cms-dashboard initgit add README.mdgit commit -m first commitgit branch -M maingit remote add origin [email protected]:PlasticStudio/cms-dashboard.gitgit push -u origin main |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SilverStripe\Security\Member: | ||
extensions: | ||
- PlasticStudio\Extensions\MemberExtension |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "plasticstudio/member-activity", | ||
"type": "silverstripe-vendormodule", | ||
"description": "SilverStripe add on to track member activity", | ||
"homepage": "https://psdigital.co.nz", | ||
"keywords": ["silverstripe","member"], | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Emma Baker", | ||
"homepage": "https://psdigital.co.nz", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "http://github.com/plasticstudio/dashboard/issues" | ||
}, | ||
"extra": { | ||
"expose": [ | ||
"client" | ||
] | ||
}, | ||
"require": { | ||
"silverstripe/cms": "^4 || ^5", | ||
"silverstripe/framework": "^4 || ^5", | ||
"silverstripe/vendor-plugin": "^1 || ^2" | ||
}, | ||
"minimum-stability": "dev" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Skeletor\Extensions; | ||
|
||
use SilverStripe\ORM\DB; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\ORM\DataExtension; | ||
use SilverStripe\Security\Security; | ||
use SilverStripe\Forms\ReadonlyField; | ||
|
||
class MemberExtension extends DataExtension | ||
{ | ||
// https://docs.silverstripe.org/en/5/developer_guides/extending/how_tos/track_member_logins/ | ||
|
||
private static $db = [ | ||
'LastVisited' => 'Datetime', | ||
'NumVisit' => 'Int', | ||
]; | ||
|
||
/** | ||
* This extension hook is called every time a member is logged in | ||
*/ | ||
public function afterMemberLoggedIn() | ||
{ | ||
$this->logVisit(); | ||
} | ||
|
||
/** | ||
* This extension hook is called when a member's session is restored from "remember me" cookies | ||
*/ | ||
public function memberAutoLoggedIn() | ||
{ | ||
$this->logVisit(); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldsToTab('Root.Main', [ | ||
ReadonlyField::create('LastVisited', 'Last visited'), | ||
ReadonlyField::create('NumVisit', 'Number of visits'), | ||
]); | ||
} | ||
|
||
protected function logVisit() | ||
{ | ||
if (!Security::database_is_ready()) { | ||
return; | ||
} | ||
|
||
$lastVisitedTable = DataObject::getSchema()->tableForField(Member::class, 'LastVisited'); | ||
|
||
DB::query(sprintf( | ||
'UPDATE "' . $lastVisitedTable . '" SET "LastVisited" = %s, "NumVisit" = "NumVisit" + 1 WHERE "ID" = %d', | ||
DB::get_conn()->now(), | ||
$this->owner->ID | ||
)); | ||
} | ||
} |