From 2badceef07c1eae8c6ca4cd7450138084551e773 Mon Sep 17 00:00:00 2001 From: ebakernz Date: Fri, 20 Sep 2024 10:47:29 +1200 Subject: [PATCH] working --- .gitignore | 0 README.md | 7 ++-- README.mdgit | 1 + _config.php | 1 + _config/extensions.yml | 3 ++ composer.json | 29 +++++++++++++++ src/Extensions/MemberExtension.php | 60 ++++++++++++++++++++++++++++++ 7 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 README.mdgit create mode 100755 _config.php create mode 100644 _config/extensions.yml create mode 100755 composer.json create mode 100644 src/Extensions/MemberExtension.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 7d93140..375291f 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/README.mdgit b/README.mdgit new file mode 100644 index 0000000..77a4253 --- /dev/null +++ b/README.mdgit @@ -0,0 +1 @@ +# cms-dashboard initgit add README.mdgit commit -m first commitgit branch -M maingit remote add origin git@github.com:PlasticStudio/cms-dashboard.gitgit push -u origin main diff --git a/_config.php b/_config.php new file mode 100755 index 0000000..6fd199e --- /dev/null +++ b/_config.php @@ -0,0 +1 @@ + '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 + )); + } +} \ No newline at end of file