Fixed the badges/all query to always show the correct award record

This commit is contained in:
Zachary Doll 2013-12-11 11:54:17 -06:00
parent 51b8dadb9f
commit c95bd9e84b
5 changed files with 30 additions and 35 deletions

View File

@ -48,8 +48,12 @@ class BadgesController extends Gdn_Controller {
$this->Title(T('Yaga.AllBadges')); $this->Title(T('Yaga.AllBadges'));
$UserID = Gdn::Session()->UserID; $UserID = Gdn::Session()->UserID;
// Get list of badges from the model and pass to the view // Get list of badges from the model and pass to the view
$this->SetData('Badges', $this->BadgeAwardModel->GetEarnedJoinAll($UserID)); $AllBadges = $this->BadgeModel->GetWithEarned($UserID);
$this->SetData('Badges', $AllBadges);
//$this->SetData('Earned')
$this->Render('all'); $this->Render('all');
} }

View File

@ -141,35 +141,6 @@ class BadgeAwardModel extends Gdn_Model {
->GetCount(); ->GetCount();
} }
/**
* Returns the full list of badges and the associated user awards if applicable
*
* @param int $UserID
* @return DataSet
*/
public function GetEarnedJoinAll($UserID) {
return $this->SQL
->Select('b.*, ba.UserID, ba.InsertUserID, ba.Reason, ba.DateInserted, ui.Name as InsertUserName')
->From('Badge b')
->Join('BadgeAward ba', 'ba.BadgeID = b.BadgeID', 'left')
->Join('User ui', 'ba.InsertUserID = ui.UserID', 'left')
->Where('ba.UserID', $UserID)
->OrWhere('b.BadgeID is not null') // needed to get the full set of badges
->GroupBy('b.BadgeID')
->OrderBy('b.BadgeID', 'Desc')
->Get();
}
public function GetEarned($UserID) {
return $this->SQL
->Select('ba.*, ui.Name as InsertUserName')
->From('BadgeAward ba')
->Join('User ui', 'ba.InsertUserID = ui.UserID', 'left')
->Where('ba.UserID', $UserID)
->OrderBy('ba.DateInserted', 'Desc')
->Get();
}
/** /**
* Returns the list of unobtained but enabled badges for a specific user * Returns the list of unobtained but enabled badges for a specific user
* *
@ -177,7 +148,7 @@ class BadgeAwardModel extends Gdn_Model {
* @param bool $Enabled Description * @param bool $Enabled Description
* @return DataSet * @return DataSet
*/ */
public function GetUnearned($UserID) { public function GetUnobtained($UserID) {
return $this->SQL return $this->SQL
->Select() ->Select()
->From('Badge b') ->From('Badge b')

View File

@ -149,10 +149,10 @@ class BadgeModel extends Gdn_Model {
->Set('CountBadges', 'CountBadges - 1', FALSE) ->Set('CountBadges', 'CountBadges - 1', FALSE)
->Where('UserID', $UserIDs) ->Where('UserID', $UserIDs)
->Put(); ->Put();
// Remove the award rows // Remove the award rows
$this->SQL->Delete('BadgeAward', array('BadgeID' => $BadgeID)); $this->SQL->Delete('BadgeAward', array('BadgeID' => $BadgeID));
$this->Database->CommitTransaction(); $this->Database->CommitTransaction();
} catch(Exception $Ex) { } catch(Exception $Ex) {
$this->Database->RollbackTransaction(); $this->Database->RollbackTransaction();
@ -166,4 +166,23 @@ class BadgeModel extends Gdn_Model {
} }
return FALSE; return FALSE;
} }
/**
* Get the full list of badges joined with the award data for a specific user
* This shouldn't really be here, but I can't think of a good place to put it
*
* @param int $UserID
*/
public function GetWithEarned($UserID) {
$Px = $this->Database->DatabasePrefix;
$Sql = 'select b.BadgeID, b.Name, b.Description, b.Photo, b.AwardValue, '
. 'ba.UserID, ba.InsertUserID, ba.Reason, ba.DateInserted, '
. 'ui.Name AS InsertUserName '
. "from {$Px}Badge as b "
. "left join {$Px}BadgeAward as ba ON b.BadgeID = ba.BadgeID and ba.UserID = :UserID "
. "left join {$Px}User as ui on ba.InsertUserID = ui.UserID";
return $this->Database->Query($Sql, array(':UserID' => $UserID))->Result();
}
} }

View File

@ -11,7 +11,8 @@ Yet Another Gamification Application
* ~~Move badge count to user table column~~ * ~~Move badge count to user table column~~
* ~~Translate every static string~~ * ~~Translate every static string~~
* ~~Create a badgeaward model~~ * ~~Create a badgeaward model~~
* Fix all badges page query to be right * ~~Fix all badges page query to be right~~
* Finish rank promotion screen
* Fix reaction method on profile page to show more than one page of discussion/comments * Fix reaction method on profile page to show more than one page of discussion/comments
** Also show the reaction record ** Also show the reaction record
** Also refactor that method, really messy right now ** Also refactor that method, really messy right now

View File

@ -603,7 +603,7 @@ class YagaHooks implements Gdn_IPlugin {
$User = $UserModel->GetID($UserID); $User = $UserModel->GetID($UserID);
$BadgeAwardModel = Yaga::BadgeAwardModel(); $BadgeAwardModel = Yaga::BadgeAwardModel();
$Badges = $BadgeAwardModel->GetUnearned($UserID); $Badges = $BadgeAwardModel->GetUnobtained($UserID);
$Rules = array(); $Rules = array();
foreach($Badges as $Badge) { foreach($Badges as $Badge) {