Fixed the badges/all query to always show the correct award record
This commit is contained in:
parent
51b8dadb9f
commit
c95bd9e84b
@ -48,8 +48,12 @@ class BadgesController extends Gdn_Controller {
|
||||
$this->Title(T('Yaga.AllBadges'));
|
||||
|
||||
$UserID = Gdn::Session()->UserID;
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
@ -141,35 +141,6 @@ class BadgeAwardModel extends Gdn_Model {
|
||||
->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
|
||||
*
|
||||
@ -177,7 +148,7 @@ class BadgeAwardModel extends Gdn_Model {
|
||||
* @param bool $Enabled Description
|
||||
* @return DataSet
|
||||
*/
|
||||
public function GetUnearned($UserID) {
|
||||
public function GetUnobtained($UserID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Badge b')
|
||||
|
@ -149,10 +149,10 @@ class BadgeModel extends Gdn_Model {
|
||||
->Set('CountBadges', 'CountBadges - 1', FALSE)
|
||||
->Where('UserID', $UserIDs)
|
||||
->Put();
|
||||
|
||||
|
||||
// Remove the award rows
|
||||
$this->SQL->Delete('BadgeAward', array('BadgeID' => $BadgeID));
|
||||
|
||||
|
||||
$this->Database->CommitTransaction();
|
||||
} catch(Exception $Ex) {
|
||||
$this->Database->RollbackTransaction();
|
||||
@ -166,4 +166,23 @@ class BadgeModel extends Gdn_Model {
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,8 @@ Yet Another Gamification Application
|
||||
* ~~Move badge count to user table column~~
|
||||
* ~~Translate every static string~~
|
||||
* ~~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
|
||||
** Also show the reaction record
|
||||
** Also refactor that method, really messy right now
|
||||
|
@ -603,7 +603,7 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
$User = $UserModel->GetID($UserID);
|
||||
|
||||
$BadgeAwardModel = Yaga::BadgeAwardModel();
|
||||
$Badges = $BadgeAwardModel->GetUnearned($UserID);
|
||||
$Badges = $BadgeAwardModel->GetUnobtained($UserID);
|
||||
|
||||
$Rules = array();
|
||||
foreach($Badges as $Badge) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user