Badges Module is now on profile pages

This commit is contained in:
Zachary Doll 2013-11-13 11:08:51 -06:00
parent 076bc91a83
commit 67f9d8141a
5 changed files with 50 additions and 35 deletions

View File

@ -25,7 +25,7 @@ class BadgesController extends Gdn_Controller {
$this->AddJsFile('global.js');
$this->AddCssFile('style.css');
$this->AddCssFile('badges.css');
$this->AddModule('MyBadgesModule');
$this->AddModule('BadgesModule');
}
/**

42
modules/class.badgesmodule.php Executable file
View File

@ -0,0 +1,42 @@
<?php if(!defined('APPLICATION')) exit();
/* Copyright 2013 Zachary Doll */
/**
* Renders a users badges in a nice grid in the panel
*/
class BadgesModule extends Gdn_Module {
public function __construct($Sender = '') {
parent::__construct($Sender);
// default to the user object on the controller/the currently logged in user
if(property_exists($Sender, 'User')) {
$UserID = $Sender->User->UserID;
}
else {
$UserID = Gdn::Session()->UserID;
}
$BadgeModel = new BadgeModel();
$this->Data = $BadgeModel->GetUserBadgeAwards($UserID);
}
public function AssetTarget() {
return 'Panel';
}
public function ToString() {
if($this->Data) {
if($this->Visible) {
$ViewPath = $this->FetchViewLocation('badges', 'yaga');
$String = '';
ob_start();
include ($ViewPath);
$String = ob_get_contents();
@ob_end_clean();
return $String;
}
}
return '';
}
}

View File

@ -1,34 +0,0 @@
<?php if(!defined('APPLICATION')) exit();
/* Copyright 2013 Zachary Doll */
/**
* Renders a users badges in a nice grid in the panel
*/
class MyBadgesModule extends Gdn_Module {
public function __construct($Sender = '') {
parent::__construct($Sender);
// Load badges
$this->Data = FALSE;
if(Gdn::Session()->IsValid()) {
$UserID = Gdn::Session()->UserID;
$BadgeModel = new BadgeModel();
$Data = $BadgeModel->GetUserBadgeAwards($UserID);
$this->Data = $Data;
}
}
public function AssetTarget() {
return 'Panel';
}
public function ToString() {
if($this->Data)
return parent::ToString();
return '';
}
}

View File

@ -235,6 +235,12 @@ class YagaHooks implements Gdn_IPlugin {
*/
public function ProfileController_Render_Before($Sender) {
$this->_AddResources($Sender);
// $UserID = $Sender->User->UserID;
// $Module = new BadgesModule();
// $Module->SetUser($UserID);
$Sender->AddModule('BadgesModule');
}
public function DiscussionController_Render_Before($Sender) {
@ -286,6 +292,7 @@ class YagaHooks implements Gdn_IPlugin {
if(!C('Yaga.Badges.Enabled', FALSE)) {
return;
}
$Session = Gdn::Session();
if(!$Session->IsValid())
return;