/** * Load up the leaderboard module data based on a specific time slot * * @param string $SlotType Valid options are 'a': All Time, 'w': Weekly, 'm': * Monthly, 'y': Yearly */ public function GetData($SlotType = 'a') { // Get the leaderboard data $Leaders = Gdn::SQL()->Select('up.Points as YagaPoints, u.*')->From('User u')->Join('UserPoints up', 'u.UserID = up.UserID')->Where('up.SlotType', $SlotType)->Where('up.TimeSlot', gmdate('Y-m-d', Gdn_Statistics::TimeSlotStamp($SlotType)))->Where('up.Source', 'Total')->OrderBy('up.Points', 'desc')->Limit(C('Yaga.LeaderBoard.Limit', 10), 0)->Get()->Result(); $this->Data = $Leaders; switch ($SlotType) { case 'a': $this->Title = T('Yaga.LeaderBoard.AllTime'); break; case 'w': $this->Title = T('Yaga.LeaderBoard.Week'); break; case 'm': $this->Title = T('Yaga.LeaderBoard.Month'); break; case 'y': $this->Title = T('Yaga.LeaderBoard.Year'); break; } }
/** * Add points to a user's total in a specific timeslot. * * @since 2.1.0 * @access protected * @see self::GivePoints */ protected static function _GivePoints($UserID, $Points, $SlotType, $Source = 'Total', $Timestamp = FALSE) { $TimeSlot = gmdate('Y-m-d', Gdn_Statistics::TimeSlotStamp($SlotType, $Timestamp)); $Px = Gdn::Database()->DatabasePrefix; $Sql = "insert {$Px}UserPoints (UserID, SlotType, TimeSlot, Source, Points)\n values (:UserID, :SlotType, :TimeSlot, :Source, :Points)\n on duplicate key update Points = Points + :Points1"; Gdn::Database()->Query($Sql, array(':UserID' => $UserID, ':Points' => $Points, ':SlotType' => $SlotType, ':Source' => $Source, ':TimeSlot' => $TimeSlot, ':Points1' => $Points)); }