/**
  * Gets the field definitions for the form.
  *
  * @since 0.1
  *
  * @param Contest $contest
  * @param integer|false $challengeId
  * @return array
  */
 protected function getFormFields(Contest $contest, $challengeId)
 {
     $fields = array();
     $user = $this->getUser();
     $fields['contest-id'] = array('type' => 'hidden', 'default' => $contest->getId(), 'id' => 'contest-id');
     $fields['contestant-realname'] = array('type' => 'text', 'default' => $user->getRealName(), 'label-message' => 'contest-signup-realname', 'required' => true, 'validation-callback' => array(__CLASS__, 'validateNameField'));
     $fields['contestant-email'] = array('type' => 'text', 'default' => $user->getEmail(), 'label-message' => 'contest-signup-email', 'required' => true, 'validation-callback' => array(__CLASS__, 'validateEmailField'));
     $fields['contestant-country'] = array('type' => 'select', 'label-message' => 'contest-signup-country', 'required' => true, 'options' => ContestContestant::getCountriesForInput(true), 'validation-callback' => array(__CLASS__, 'validateCountryField'));
     $fields['contestant-challengeid'] = array('type' => 'radio', 'label-message' => 'contest-signup-challenge', 'options' => $this->getChallengesList($contest), 'required' => true, 'validation-callback' => array(__CLASS__, 'validateChallengeField'));
     if ($challengeId !== false) {
         $fields['contestant-challengeid']['default'] = $challengeId;
     }
     $fields['contestant-volunteer'] = array('type' => 'check', 'default' => '0', 'label-message' => 'contest-signup-volunteer');
     $fields['contestant-wmf'] = array('type' => 'check', 'default' => '0', 'label-message' => 'contest-signup-wmf');
     $fields['contestant-readrules'] = array('type' => 'check', 'default' => '0', 'label-message' => array('contest-signup-readrules', $contest->getField('rules_page')), 'validation-callback' => array(__CLASS__, 'validateRulesField'), 'id' => 'contest-rules', 'data-foo' => 'bar');
     return $fields;
 }
 /**
  * Testing foreign keys with multiple referrer columns.
  * @link       http://propel.phpdb.org/trac/ticket/606
  */
 public function testMultiColJoin()
 {
     BookstoreContestPeer::doDeleteAll();
     BookstoreContestEntryPeer::doDeleteAll();
     $bs = new Bookstore();
     $bs->setStoreName("Test1");
     $bs->setPopulationServed(5);
     $bs->save();
     $bs1Id = $bs->getId();
     $bs2 = new Bookstore();
     $bs2->setStoreName("Test2");
     $bs2->setPopulationServed(5);
     $bs2->save();
     $bs2Id = $bs2->getId();
     $ct1 = new Contest();
     $ct1->setName("Contest1!");
     $ct1->save();
     $ct1Id = $ct1->getId();
     $ct2 = new Contest();
     $ct2->setName("Contest2!");
     $ct2->save();
     $ct2Id = $ct2->getId();
     $cmr = new Customer();
     $cmr->setName("Customer1");
     $cmr->save();
     $cmr1Id = $cmr->getId();
     $cmr2 = new Customer();
     $cmr2->setName("Customer2");
     $cmr2->save();
     $cmr2Id = $cmr2->getId();
     $contest = new BookstoreContest();
     $contest->setBookstoreId($bs1Id);
     $contest->setContestId($ct1Id);
     $contest->save();
     $contest = new BookstoreContest();
     $contest->setBookstoreId($bs2Id);
     $contest->setContestId($ct1Id);
     $contest->save();
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct1Id);
     $entry->setCustomerId($cmr1Id);
     $entry->save();
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct1Id);
     $entry->setCustomerId($cmr2Id);
     $entry->save();
     // Note: this test isn't really working very well.  We setup fkeys that
     // require that the BookstoreContest rows exist and then try to violate
     // the rules ... :-/  This may work in some lenient databases, but an error
     // is expected here.
     /*
      * Commented out for now ... though without it, this test may not really be testing anything
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct2Id);
     $entry->setCustomerId($cmr2Id);
     $entry->save();
     */
     $c = new Criteria();
     $c->addJoin(array(BookstoreContestEntryPeer::BOOKSTORE_ID, BookstoreContestEntryPeer::CONTEST_ID), array(BookstoreContestPeer::BOOKSTORE_ID, BookstoreContestPeer::CONTEST_ID));
     $results = BookstoreContestEntryPeer::doSelect($c);
     $this->assertEquals(2, count($results));
     foreach ($results as $result) {
         $this->assertEquals($bs1Id, $result->getBookstoreId());
         $this->assertEquals($ct1Id, $result->getContestId());
     }
 }
 /**
  * Show a paged list of the contestants foe this contest.
  *
  * @since 0.1
  *
  * @param Contest $contest
  * @param string|false $challengeTitle
  */
 protected function showContestants(Contest $contest, $challengeTitle)
 {
     $out = $this->getOutput();
     $out->addWikiMsg('contest-contest-contestants-text');
     $conds = array('contestant_contest_id' => $contest->getId());
     $this->addRequestConditions($conds);
     $pager = new ContestantPager($this, $conds);
     if ($pager->getNumRows()) {
         $out->addHTML($pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar());
     } else {
         $out->addWikiMsg('contest-contest-no-results');
     }
 }
 /**
  * Handle page request when the contest is enabled.
  *
  * @since 0.1
  *
  * @param Contest $contest
  */
 protected function handleEnabledPage(Contest $contest)
 {
     // Check if the user is already a contestant in this contest.
     // If he is, redirect to submission page, else show signup form.
     $contestant = ContestContestant::s()->selectRow(null, array('contest_id' => $contest->getId(), 'user_id' => $this->getUser()->getId()));
     if ($contestant === false) {
         $this->getOutput()->redirect(SpecialPage::getTitleFor('ContestSignup', $contest->getField('name'))->getLocalURL());
     } else {
         $contestant->setContest($contest);
         $this->showSubmissionPage($contestant);
     }
 }
 protected function showEnabledPage(Contest $contest)
 {
     $out = $this->getOutput();
     $alreadySignedup = $this->getUser()->isLoggedIn();
     if ($alreadySignedup) {
         // Check if the user is already a contestant in this contest.
         // If he is, reirect to submission page, else show signup form.
         $alreadySignedup = ContestContestant::s()->selectRow('id', array('contest_id' => $contest->getId(), 'user_id' => $this->getUser()->getId())) !== false;
     }
     if ($alreadySignedup) {
         $out->redirect(SpecialPage::getTitleFor('MyContests', $contest->getField('name'))->getLocalURL());
     } else {
         $out->setPageTitle($contest->getField('name'));
         $this->showIntro($contest);
         $this->showChallenges($contest);
         $this->showOpportunities($contest);
         $this->showRules($contest);
         $out->addModules('contest.special.welcome');
     }
 }