Updated leaderboard module to allow different periods of leaders

This commit is contained in:
Zachary Doll 2013-11-19 15:16:09 -06:00
parent f92f4c6e28
commit 655929ccf4
2 changed files with 48 additions and 16 deletions

View File

@ -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);
}
/**

View File

@ -8,19 +8,48 @@ 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->Data) {
$this->GetData();
}
if($this->Visible) {
$ViewPath = $this->FetchViewLocation('leaderboard', 'yaga');
$String = '';
@ -30,7 +59,6 @@ class LeaderBoardModule extends Gdn_Module {
@ob_end_clean();
return $String;
}
}
return '';
}