public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'LotteryChooseHallView.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'LotteryProcess.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     // Check the hard cap!
     if (LotteryProcess::hardCapReached($term)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, re-application is now closed.');
         $errorCmd = CommandFactory::getCommand('ShowStudentMenu');
         $errorCmd->redirect();
     }
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     if ($rlcAssignment == false) {
         $rlcAssignment = null;
     }
     $view = new LotteryChooseHallView($student, $term, $rlcAssignment);
     $context->setContent($view->show());
 }
 public function show()
 {
     $tpl = array();
     $tpl['DATES'] = HMS_Util::getPrettyDateRange($this->startDate, $this->endDate);
     $tpl['STATUS'] = "";
     $hardCapReached = LotteryProcess::hardCapReached($this->term);
     if (!is_null($this->assignment)) {
         // Student has already been assigned.
         $tpl['ICON'] = FEATURE_COMPLETED_ICON;
         //$tpl['ASSIGNED'] = $this->assignment->where_am_i();
         $tpl['ASSIGNED'] = '';
     } else {
         if ($hardCapReached) {
             // Hard cap has been reached
             $tpl['ICON'] = FEATURE_LOCKED_ICON;
             $tpl['HARD_CAP'] = "";
             // dummy tag
         } else {
             if (!is_null($this->application) && $this->application->isWinner()) {
                 // Student has won, let them choose their room
                 $tpl['ICON'] = FEATURE_OPEN_ICON;
                 $chooseRoomCmd = CommandFactory::getCommand('LotteryShowChooseHall');
                 $tpl['SELECT_LINK'] = $chooseRoomCmd->getLink('Click here to select your room');
             } else {
                 if (!is_null($this->application)) {
                     // Student has already re-applied
                     $tpl['ICON'] = FEATURE_COMPLETED_ICON;
                     $tpl['ALREADY_APPLIED'] = "";
                     // dummy tag, text is in template
                 } else {
                     if (time() < $this->startDate) {
                         // Too early
                         $tpl['ICON'] = FEATURE_NOTYET_ICON;
                         $tpl['BEGIN_DEADLINE'] = HMS_Util::getFriendlyDate($this->startDate);
                     } else {
                         if (time() > $this->endDate) {
                             // Too late
                             $tpl['ICON'] = FEATURE_LOCKED_ICON;
                             // fade out header
                             $tpl['STATUS'] = "locked";
                             $tpl['END_DEADLINE'] = HMS_Util::getFriendlyDate($this->endDate);
                         } else {
                             if (HMS_Lottery::determineEligibility(UserStatus::getUsername())) {
                                 $tpl['ICON'] = FEATURE_OPEN_ICON;
                                 $reAppCommand = CommandFactory::getCommand('ShowReApplication');
                                 $reAppCommand->setTerm($this->term);
                                 $tpl['ELIGIBLE'] = "";
                                 //dummy tag, text is in template
                                 $tpl['LOTTERY_TERM_1'] = Term::toString($this->term);
                                 $tpl['NEXT_TERM_1'] = Term::toString(Term::getNextTerm($this->term));
                                 $tpl['ENTRY_LINK'] = $reAppCommand->getLink('Click here to re-apply.');
                             } else {
                                 $tpl['ICON'] = FEATURE_LOCKED_ICON;
                                 $tpl['NOT_ELIGIBLE'] = "";
                                 //dummy tag, text is in template
                                 $tpl['LOTTERY_TERM_2'] = Term::toString($this->term);
                                 $tpl['NEXT_TERM_2'] = Term::toString(Term::getNextTerm($this->term));
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!$hardCapReached && time() > $this->startDate) {
         if ($this->roommateRequests != FALSE && !is_null($this->roommateRequests) && $this->assignment != TRUE && !PEAR::isError($this->assignment)) {
             $tpl['roommates'] = array();
             $tpl['ROOMMATE_REQUEST'] = '';
             // dummy tag
             foreach ($this->roommateRequests as $invite) {
                 $cmd = CommandFactory::getCommand('LotteryShowRoommateRequest');
                 $cmd->setRequestId($invite['id']);
                 $roommie = StudentFactory::getStudentByUsername($invite['requestor'], $this->term);
                 $tpl['roommates'][]['ROOMMATE_LINK'] = $cmd->getLink($roommie->getName());
                 //$tpl['roommates'][]['ROOMMATE_LINK'] = PHPWS_Text::secureLink(HMS_SOAP::get_name($invite['requestor']), 'hms', array('type'=>'student', 'op'=>'lottery_show_roommate_request', 'id'=>$invite['id']));
             }
         }
     }
     return PHPWS_Template::process($tpl, 'hms', 'student/menuBlocks/reApplicationMenuBlock.tpl');
 }
Example #3
0
 public function sendInvites()
 {
     HMS_Activity_Log::log_activity('hms', ACTIVITY_LOTTERY_EXECUTED, 'hms');
     $this->output[] = "Lottery system invoked on " . date("d M, Y @ g:i:s", $this->now) . " ({$this->now})";
     /**
      * **
      * Check the hard cap.
      * Don't do anything if it's been reached.
      */
     if (LotteryProcess::hardCapReached($this->term)) {
         $this->output[] = 'Hard cap reached. Done!';
         return;
     }
     /**
      * *****************
      * Reminder Emails *
      * *****************
      */
     $output = array();
     if ($this->sendReminders) {
         $this->output[] = "Sending invite reminder emails...";
         $this->sendWinningReminderEmails();
         $output[] = "Sending roommate invite reminder emails...";
         $this->sendRoommateReminderEmails();
     }
     // check the jr/sr soft caps
     if (LotteryProcess::jrSoftCapReached($this->term)) {
         $this->inviteCounts[CLASS_JUNIOR][MALE] = 0;
         $this->inviteCounts[CLASS_JUNIOR][FEMALE] = 0;
     }
     if (LotteryProcess::srSoftCapReached($this->term)) {
         $this->inviteCounts[CLASS_SENIOR][MALE] = 0;
         $this->inviteCounts[CLASS_SENIOR][FEMALE] = 0;
     }
     /**
      * ****
      * Count the number of remaining entries
      * *******
      */
     try {
         // Count remaining applications by class and gender
         $this->applicationsRemaining = array();
         foreach ($this->classes as $c) {
             foreach ($this->genders as $g) {
                 $this->applicationsRemaining[$c][$g] = LotteryProcess::countRemainingApplicationsByClassGender($this->term, $c, $g);
             }
         }
     } catch (Exception $e) {
         $this->output[] = 'Error counting outstanding lottery entires, quitting. Exception: ' . $e->getMessage();
         return;
     }
     $this->output[] = "{$this->applicationsRemaining[CLASS_SENIOR][MALE]} senior male lottery entries remaining";
     $this->output[] = "{$this->applicationsRemaining[CLASS_SENIOR][FEMALE]} senior female lottery entries remaining";
     $this->output[] = "{$this->applicationsRemaining[CLASS_JUNIOR][MALE]} junior male lottery entries remaining";
     $this->output[] = "{$this->applicationsRemaining[CLASS_JUNIOR][FEMALE]} junior female lottery entries remaining";
     $this->output[] = "{$this->applicationsRemaining[CLASS_SOPHOMORE][MALE]} sophomore male lottery entries remaining";
     $this->output[] = "{$this->applicationsRemaining[CLASS_SOPHOMORE][FEMALE]} sophomore female lottery entries remaining";
     /**
      * ****************
      * Send magic winner invites
      */
     if ($this->sendMagicWinners) {
         $this->output[] = "Sending magic winner invites...";
         while (($magicWinner = $this->getMagicWinner()) != null) {
             $student = StudentFactory::getStudentByBannerId($magicWinner['banner_id'], $this->term);
             $this->sendInvite($student);
         }
     }
     /**
      * ****************
      * Send Invites
      */
     foreach ($this->classes as $c) {
         foreach ($this->genders as $g) {
             $this->output[] = "Sending {$this->inviteCounts[$c][$g]} invites for class: {$c}, gender: {$g}";
             $this->output[] = "There are {$this->applicationsRemaining[$c][$g]} remaining applicants of that class and gender.";
             // While we need to send an invite and there is an applicant remaining
             // And we haven't exceeded our batch size
             while ($this->inviteCounts[$c][$g] > $this->numInvitesSent[$c][$g] && $this->applicationsRemaining[$c][$g] >= 1 && $this->numInvitesSent['TOTAL'] <= MAX_INVITES_PER_BATCH) {
                 // Send an invite to the proper class & gender
                 $winningRow = $this->chooseWinner($c, $g);
                 $student = StudentFactory::getStudentByBannerId($winningRow['banner_id'], $this->term);
                 $this->sendInvite($student);
                 // Update counts
                 $this->numInvitesSent[$c][$g]++;
                 $this->applicationsRemaining[$c][$g]--;
             }
         }
     }
     $this->output[] = "Done. Sent {$this->numInvitesSent['TOTAL']} invites total.";
 }