From 655929ccf455a4d2fc463b4f619995eb30fa1442 Mon Sep 17 00:00:00 2001 From: Zachary Doll Date: Tue, 19 Nov 2013 15:16:09 -0600 Subject: [PATCH] Updated leaderboard module to allow different periods of leaders --- controllers/class.badgescontroller.php | 6 ++- modules/class.leaderboardmodule.php | 58 +++++++++++++++++++------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/controllers/class.badgescontroller.php b/controllers/class.badgescontroller.php index 6f88b74..200e2fe 100644 --- a/controllers/class.badgescontroller.php +++ b/controllers/class.badgescontroller.php @@ -26,7 +26,11 @@ class BadgesController extends Gdn_Controller { $this->AddCssFile('style.css'); $this->AddCssFile('badges.css'); $this->AddModule('BadgesModule'); - $this->AddModule('LeaderBoardModule'); + $Module = new LeaderBoardModule(); + $Module->GetData('w'); + $this->AddModule($Module); + $Module = new LeaderBoardModule(); + $this->AddModule($Module); } /** diff --git a/modules/class.leaderboardmodule.php b/modules/class.leaderboardmodule.php index 7630d5c..4e950cd 100755 --- a/modules/class.leaderboardmodule.php +++ b/modules/class.leaderboardmodule.php @@ -8,28 +8,56 @@ class LeaderBoardModule extends Gdn_Module { public function __construct($Sender = '') { parent::__construct($Sender); - - // Get the leaderboard data - $UserModel = new UserModel(); - $this->Data = $UserModel->GetWhere(FALSE, 'Points', 'desc', 10, 0); - $this->Title = T('All Time Leaders'); } public function AssetTarget() { return 'Panel'; } + public function GetData($SlotType = 'a') { + // Get the leaderboard data + $Leaders = Gdn::SQL() + ->Select('up.Points as Points, u.*') + ->From('User u') + ->Join('UserPoints up', 'u.UserID = up.UserID') + ->Where('up.SlotType', $SlotType) + ->Where('up.Source', 'Total') + ->OrderBy('up.Points', 'desc') + ->Limit(10, 0) + ->Get() + ->Result(); + + $this->Data = $Leaders; + switch($SlotType) { + case 'a': + $this->Title = T('All Time Leaders'); + break; + case 'w': + $this->Title = T("This Week's Leaders"); + break; + case 'm': + $this->Title = T("This Month's Leaders"); + break; + case 'y': + $this->Title = T("This Years's Leaders"); + break; + } + + } + public function ToString() { - if($this->Data) { - if($this->Visible) { - $ViewPath = $this->FetchViewLocation('leaderboard', 'yaga'); - $String = ''; - ob_start(); - include ($ViewPath); - $String = ob_get_contents(); - @ob_end_clean(); - return $String; - } + if(!$this->Data) { + $this->GetData(); + } + + if($this->Visible) { + $ViewPath = $this->FetchViewLocation('leaderboard', 'yaga'); + $String = ''; + ob_start(); + include ($ViewPath); + $String = ob_get_contents(); + @ob_end_clean(); + return $String; } return ''; }