Rank WIP
This commit is contained in:
parent
03e5e07fc8
commit
a0ad2e509b
@ -61,13 +61,11 @@ class RankController extends DashboardController {
|
||||
|
||||
$this->Title(T('Add Rank'));
|
||||
$Edit = FALSE;
|
||||
$Permissions = Gdn::PermissionModel()->GetPermissionsEdit(0);
|
||||
if($RankID) {
|
||||
$this->Rank = $this->RankModel->GetRank($RankID);
|
||||
$this->Form->AddHidden('RankID', $RankID);
|
||||
$Edit = TRUE;
|
||||
$this->Title(T('Edit Rank'));
|
||||
$Permissions = $this->Rank->Permissions;
|
||||
}
|
||||
|
||||
// Load up all permissions
|
||||
@ -100,9 +98,6 @@ class RankController extends DashboardController {
|
||||
|
||||
$this->Form->SetFormValue('Photo', $Parts['SaveName']);
|
||||
}
|
||||
|
||||
decho($this->Form->FormValues());
|
||||
die();
|
||||
|
||||
if($this->Form->Save()) {
|
||||
if($Edit) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
class Yaga {
|
||||
|
||||
protected static $_ReactionModel = NULL;
|
||||
protected static $_BadgeModel = NULL;
|
||||
|
||||
/**
|
||||
* Get a reference to the reaction model
|
||||
@ -18,4 +19,15 @@ class Yaga {
|
||||
}
|
||||
return self::$_ReactionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the badge model
|
||||
* @return ReactionModel
|
||||
*/
|
||||
public static function BadgeModel() {
|
||||
if (is_null(self::$_BadgeModel)) {
|
||||
self::$_BadgeModel = new BadgeModel();
|
||||
}
|
||||
return self::$_BadgeModel;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ class BadgeModel extends Gdn_Model {
|
||||
return self::$_Badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total number of badges in the system
|
||||
* @return int
|
||||
*/
|
||||
public function GetBadgeCount() {
|
||||
return count($this->GetBadges());
|
||||
}
|
||||
@ -256,6 +260,15 @@ class BadgeModel extends Gdn_Model {
|
||||
->Result(DATASET_TYPE_ARRAY);
|
||||
}
|
||||
|
||||
public function GetUserBadgeAwardCount($UserID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Badge b')
|
||||
->Join('BadgeAward ba', 'ba.BadgeID = b.BadgeID', 'left')
|
||||
->Where('ba.UserID', $UserID)
|
||||
->GetCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full list of badges and the associated user awards if applicable
|
||||
*
|
||||
|
@ -36,17 +36,13 @@ class RankModel extends Gdn_Model {
|
||||
self::$_Ranks = $this->SQL
|
||||
->Select()
|
||||
->From('Rank')
|
||||
->OrderBy('RankID')
|
||||
->OrderBy('PointsRequired')
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
return self::$_Ranks;
|
||||
}
|
||||
|
||||
public function GetRankCount() {
|
||||
return count($this->GetRanks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of currently enabled ranks
|
||||
*
|
||||
@ -57,7 +53,7 @@ class RankModel extends Gdn_Model {
|
||||
->Select()
|
||||
->From('Rank')
|
||||
->Where('Enabled', TRUE)
|
||||
->OrderBy('RankID')
|
||||
->OrderBy('PointsRequired')
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
@ -78,39 +74,6 @@ class RankModel extends Gdn_Model {
|
||||
return $Rank;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last inserted rank
|
||||
*
|
||||
* @return DataSet
|
||||
*/
|
||||
public function GetNewestRank() {
|
||||
$Rank = $this->SQL
|
||||
->Select()
|
||||
->From('Rank')
|
||||
->OrderBy('RankID', 'desc')
|
||||
->Get()
|
||||
->FirstRow();
|
||||
return $Rank;
|
||||
}
|
||||
|
||||
public function GetRankAwardCount($RankID) {
|
||||
$Wheres = array('RankID' => $RankID);
|
||||
return $this->SQL
|
||||
->GetCount('RankAward', $Wheres);
|
||||
}
|
||||
|
||||
public function GetRecentRankAwards($RankID, $Limit = 15) {
|
||||
return $this->SQL
|
||||
->Select('ba.UserID, ba.DateInserted, u.Name, u.Photo, u.Gender, u.Email')
|
||||
->From('RankAward ba')
|
||||
->Join('User u', 'ba.UserID = u.UserID')
|
||||
->Where('RankID', $RankID)
|
||||
->OrderBy('DateInserted', 'Desc')
|
||||
->Limit($Limit)
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to determin if a rank id currently exists
|
||||
*
|
||||
@ -145,46 +108,40 @@ class RankModel extends Gdn_Model {
|
||||
public function DeleteRank($RankID) {
|
||||
if($this->RankExists($RankID)) {
|
||||
$this->SQL->Delete('Rank', array('RankID' => $RankID));
|
||||
$this->SQL->Delete('RankAward', array('RankID' => $RankID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Award a rank to a user and record some activity
|
||||
* Set a user's rank and record some activity if it was a promotion
|
||||
*
|
||||
* @param int $RankID
|
||||
* @param int $UserID This is the user that should get the award
|
||||
* @param int $InsertUserID This is the user that gave the award
|
||||
* @param string $Reason This is the reason the giver gave with the award
|
||||
*/
|
||||
public function AwardRank($RankID, $UserID, $InsertUserID = NULL, $Reason = '') {
|
||||
$Rank = $this->GetRank($RankID);
|
||||
if(!empty($Rank)) {
|
||||
if(!$this->UserHasRank($UserID, $RankID)) {
|
||||
$this->SQL->Insert('RankAward', array(
|
||||
'RankID' => $RankID,
|
||||
'UserID' => $UserID,
|
||||
'InsertUserID' => $InsertUserID,
|
||||
'Reason' => $Reason,
|
||||
'DateInserted' => date(DATE_ISO8601)
|
||||
));
|
||||
public function SetRank($RankID, $UserID) {
|
||||
$NewRank = $this->GetRank($RankID);
|
||||
$UserModel = Gdn::UserModel();
|
||||
$User = $UserModel->GetID($UserID);
|
||||
|
||||
if(!empty($NewRank)
|
||||
&& !empty($User)) {
|
||||
$UserModel->SetField('RankID', $RankID);
|
||||
|
||||
// Record the points for this rank
|
||||
UserModel::GivePoints($UserID, $Rank->AwardValue, 'Rank');
|
||||
// Record some activity if it was a promotion
|
||||
|
||||
// Record some activity
|
||||
$Rank = $this->GetRank($RankID);
|
||||
$OldRank = $this->GetRank($User->RankID);
|
||||
|
||||
if($OldRank->PointsRequired <= $NewRank->PointsRequired) {
|
||||
$ActivityModel = new ActivityModel();
|
||||
|
||||
$Activity = array(
|
||||
'ActivityType' => 'RankAward',
|
||||
'ActivityType' => 'RankPromotion',
|
||||
'ActivityUserID' => Gdn::Session()->UserID,
|
||||
'RegardingUserID' => $UserID,
|
||||
'Photo' => '/uploads/' . $Rank->Photo,
|
||||
'RecordType' => 'Rank',
|
||||
'RecordID' => $RankID,
|
||||
'Route' => '/ranks/detail/' . $Rank->RankID . '/' . Gdn_Format::Url($Rank->Name),
|
||||
'HeadlineFormat' => '{RegardingUserID,You} earned the <a href="{Url,html}">{Data.Name,text}</a> rank.',
|
||||
'HeadlineFormat' => '{RegardingUserID,You} have been promoted to {Data.Name,text}.',
|
||||
'Data' => array(
|
||||
'Name' => $Rank->Name
|
||||
),
|
||||
@ -201,7 +158,7 @@ class RankModel extends Gdn_Model {
|
||||
$ActivityModel->SaveQueue();
|
||||
|
||||
$this->EventArguments['UserID'] = $UserID;
|
||||
$this->FireEvent('AfterRankAward');
|
||||
$this->FireEvent('AfterRankPromotion');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -222,75 +179,4 @@ class RankModel extends Gdn_Model {
|
||||
->Where('UserID', $UserID)
|
||||
->GetCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ranks a user already has
|
||||
*
|
||||
* @param int $UserID
|
||||
* @return array
|
||||
*/
|
||||
public function GetUserRankAward($UserID, $RankID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Rank b')
|
||||
->Join('RankAward ba', 'ba.RankID = b.RankID', 'left')
|
||||
->Where('b.RankID', $RankID)
|
||||
->Where('ba.UserID', $UserID)
|
||||
->Get()
|
||||
->FirstRow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ranks a user already has
|
||||
*
|
||||
* @param int $UserID
|
||||
* @return array
|
||||
*/
|
||||
public function GetUserRankAwards($UserID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Rank b')
|
||||
->Join('RankAward ba', 'ba.RankID = b.RankID', 'left')
|
||||
->Where('ba.UserID', $UserID)
|
||||
->Get()
|
||||
->Result(DATASET_TYPE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full list of ranks and the associated user awards if applicable
|
||||
*
|
||||
* @param int $UserID
|
||||
* @return DataSet
|
||||
*/
|
||||
public function GetAllRanksUserAwards($UserID) {
|
||||
return $this->SQL
|
||||
->Select('b.*, ba.UserID, ba.InsertUserID, ba.Reason, ba.DateInserted, ui.Name as InsertUserName')
|
||||
->From('Rank b')
|
||||
->Join('RankAward ba', 'ba.RankID = b.RankID', 'left')
|
||||
->Join('User ui', 'ba.InsertUserID = ui.UserID', 'left')
|
||||
->Where('ba.UserID', $UserID)
|
||||
->OrWhere('b.RankID is not null') // needed to get the full set of ranks
|
||||
->GroupBy('b.RankID')
|
||||
->OrderBy('b.RankID', 'Desc')
|
||||
->Get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of unobtained but enabled ranks for a specific user
|
||||
*
|
||||
* @param int $UserID
|
||||
* @param bool $Enabled Description
|
||||
* @return DataSet
|
||||
*/
|
||||
public function GetRanksToCheckForUser($UserID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Rank b')
|
||||
->Join('RankAward ba', 'b.RankID = ba.RankID', 'left')
|
||||
->Where('ba.UserID', $UserID)
|
||||
->Where('b.Enabled', 1)
|
||||
//->OrWhere('b.RankID is not null') // needed to get the full set of ranks
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
}
|
@ -61,6 +61,18 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
|
||||
echo Wrap($String, 'div', array('class' => 'DataCounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the badge count into the user info module
|
||||
*
|
||||
* @param UserInfoModule $Sender
|
||||
*/
|
||||
public function UserInfoModule_OnBasicInfo_Handler($Sender) {
|
||||
$UserID = $Sender->User->UserID;
|
||||
$BadgeCount = Yaga::BadgeModel()->GetUserBadgeAwardCount($UserID);
|
||||
echo '<dt class="Badges">Badges</dt> ';
|
||||
echo '<dd class="Badges">' . $BadgeCount . '</dd>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
|
@ -58,17 +58,23 @@ $Construct->Table('BadgeAward')
|
||||
->Column('DateInserted', 'datetime')
|
||||
->Set($Explicit, $Drop);
|
||||
|
||||
// Tracks the actual awarding of badges
|
||||
// Describes a rank and associated values
|
||||
$Construct->Table('Rank')
|
||||
->PrimaryKey('RankID')
|
||||
->Column('Name', 'varchar(140)')
|
||||
->Column('Description', 'varchar(255)', NULL)
|
||||
->Column('Photo', 'varchar(255)', NULL)
|
||||
->Column('PointsRequired', 'int', 0)
|
||||
->Column('Permissions', 'text', NULL)
|
||||
->Column('Permission', 'text', NULL)
|
||||
->Column('Enabled', 'tinyint(1)', '1')
|
||||
->Set($Explicit, $Drop);
|
||||
|
||||
// Tracks the current rank a user has
|
||||
$Construct->Table('User')
|
||||
->Column('CountBadges', 'int', 0)
|
||||
->Column('RankID', 'int', 0)
|
||||
->Set();
|
||||
|
||||
// Add activity types for Badge and Rank awards
|
||||
if ($SQL->GetWhere('ActivityType', array('Name' => 'BadgeAward'))->NumRows() == 0)
|
||||
$SQL->Insert('ActivityType', array('AllowComments' => '1', 'Name' => 'BadgeAward', 'FullHeadline' => '%1$s earned a badge.', 'ProfileHeadline' => '%1$s earned a badge.', 'Notify' => 1));
|
||||
|
@ -34,16 +34,10 @@ echo $this->Form->Errors();
|
||||
</li>
|
||||
<li>
|
||||
<?php
|
||||
echo $this->Form->Label('Permissions', 'Permissions');
|
||||
echo $this->Form->Dropdown('Permissions', $this->Data('Permissions'), array('multiple' => 'multiple'));
|
||||
echo $this->Form->Label('Permission Award', 'Permission');
|
||||
echo $this->Form->Dropdown('Permission', $this->Data('Permissions'), array('IncludeNULL' => TRUE));
|
||||
?>
|
||||
</li>
|
||||
<!-- <li>
|
||||
<?php
|
||||
// echo '<strong>'.T('Check all permissions that apply to this role:').'</strong>';
|
||||
// echo $this->Form->CheckBoxGridGroups($this->PermissionData, 'Permissions');
|
||||
?>
|
||||
</li>-->
|
||||
<li>
|
||||
<?php
|
||||
echo $this->Form->Label('Points Required', 'PointsRequired');
|
||||
|
@ -12,9 +12,9 @@ echo Wrap(Anchor('Add Rank', 'yaga/rank/add', array('class' => 'SmallButton')),
|
||||
<th>Image</th>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Rule</th>
|
||||
<th>Award Value</th>
|
||||
<th>Active</th>
|
||||
<th>Points Required</th>
|
||||
<th>Permission Award</th>
|
||||
<th>Auto Award</th>
|
||||
<th>Options</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -33,8 +33,8 @@ echo Wrap(Anchor('Add Rank', 'yaga/rank/add', array('class' => 'SmallButton')),
|
||||
}
|
||||
$Row .= Wrap($Rank->Name, 'td');
|
||||
$Row .= Wrap($Rank->Description, 'td');
|
||||
$Row .= Wrap($Rules[$Rank->RuleClass], 'td');
|
||||
$Row .= Wrap($Rank->AwardValue, 'td');
|
||||
$Row .= Wrap($Rank->PointsRequired, 'td');
|
||||
$Row .= Wrap($Rank->Permission, 'td');
|
||||
$ToggleText = ($Rank->Enabled) ? T('Enabled') : T('Disabled');
|
||||
$ActiveClass = ($Rank->Enabled) ? 'Active' : 'InActive';
|
||||
$Row .= Wrap(Wrap(Anchor($ToggleText, 'yaga/rank/toggle/' . $Rank->RankID, 'Hijack SmallButton'), 'span', array('class' => "ActivateSlider ActivateSlider-{$ActiveClass}")), 'td');
|
||||
|
Loading…
x
Reference in New Issue
Block a user