public static function post()
 {
     try {
         //Get list of user IDs of users that are a member this year
         $userIds = MembershipDB::getUserIdsThisYear();
         //Get list of last N winners
         $lastWinners = WeeklyWinnerDB::getLastNWinners(WeeklyWinnerConfig::MIN_WINNING_INTERVAL);
         //Get list of user IDs that have not won the last N times
         if ($lastWinners) {
             $possibleWinners = array_diff($userIds, $lastWinners);
         } else {
             $possibleWinners = $userIds;
         }
         //Pick a random user ID
         $winnerIdx = rand(0, count($possibleWinners) - 1);
         //Add chosen user ID as winner
         WeeklyWinnerDB::addWeeklyWinner($possibleWinners[$winnerIdx]);
         //Show the page again, this is the same as GETing so we just call get
         WeeklyWinnerController::get();
     } catch (Exception $ex) {
         $page = new Page();
         $page->addView('weeklyWinner/WeeklyWinnerTopView');
         $page->data['ErrorMessageNoDescriptionWithLinkView']['errorTitle'] = 'Kan geen nieuwe winnaar loten.';
         $page->data['ErrorMessageNoDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
         $page->addView('error/ErrorMessageNoDescriptionWithLinkView');
         $page->showWithMenu();
     }
 }
Esempio n. 2
0
 public static function run()
 {
     try {
         //Get list of user IDs of users that are a member this year
         $userIds = MembershipDB::getUserIdsThisYear();
         //Get list of last N winners
         $lastWinners = WeeklyWinnerDB::getLastNWinners(WeeklyWinnerConfig::MIN_WINNING_INTERVAL);
         //Get list of user IDs that have not won the last N times
         if ($lastWinners) {
             $possibleWinners = array_diff($userIds, $lastWinners);
         } else {
             $possibleWinners = $userIds;
         }
         //Pick a random user ID
         $winnerIdx = rand(0, count($possibleWinners) - 1);
         //Add chosen user ID as winner
         WeeklyWinnerDB::addWeeklyWinner($possibleWinners[$winnerIdx]);
     } catch (Exception $ex) {
         var_dump($ex);
     }
 }