/** * @see Form::save() */ public function save() { MessageForm::save(); // save solution $this->entry->update($this->text, $this->state, $this->getOptions(), $this->attachmentListEditor); $this->saved(); // forward HeaderUtil::redirect('index.php?page=ContestSolutionEntry' . '&contestID=' . $this->entry->contestID . '&solutionID=' . $this->entry->solutionID . SID_ARG_2ND_NOT_ENCODED . '#solution' . $this->entry->solutionID); exit; }
/** * @see Action::execute() */ public function execute() { parent::execute(); // delete solution $this->solution->delete(); $this->executed(); // forward HeaderUtil::redirect('index.php?page=ContestSolution&contestID=' . $this->solution->contestID . SID_ARG_2ND_NOT_ENCODED); exit; }
public function testReflectionAPI() { require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/participant/ContestParticipantEditor.class.php'; $this->deleteArray[] = $user = $this->createUser(); $this->deleteArray[] = $participant = ContestParticipantEditor::create($contestID = 0, $userID = $user->userID, $groupID = 0, $state = 'private'); $this->deleteArray[] = $solution = ContestSolutionEditor::create($contestID = 0, $participantID = $participant->participantID, $message = __METHOD__ . ' message', $state = 'private'); $this->callAllMethodsWithoutRequiredParameters($solution); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/ContestEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/participant/ContestParticipantEditor.class.php'; $this->deleteArray[] = $this->contest = ContestEditor::create($userID = 0, $groupID = 0, $subject = __METHOD__ . ' subject', $message = __METHOD__ . ' message', $options = array()); $this->deleteArray[] = $this->user = $this->createUser(); $this->deleteArray[] = $this->participant = ContestParticipantEditor::create($contestID = $this->contest->contestID, $userID = $this->user->userID, $groupID = 0, $state = 'accepted'); $this->deleteArray[] = $this->solution = ContestSolutionEditor::create($contestID = $this->contest->contestID, $participantID = $this->participant->participantID, $message = __METHOD__ . ' message', $state = 'private'); }
public function testSolutionCounter() { require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/solution/rating/ContestSolutionRatingEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/ContestEditor.class.php'; $this->deleteArray[] = $contest = ContestEditor::create($userID = 0, $groupID = 0, $subject = __METHOD__ . ' subject', $message = __METHOD__ . ' message', $options = array()); $this->deleteArray[] = $solution = ContestSolutionEditor::create($contestID = $contest->contestID, $participantID = 0, $message = __METHOD__ . ' message', $state = 'accepted'); $this->deleteArray[] = $user = $this->createUser(); $this->deleteArray[] = $rating = ContestSolutionRatingEditor::create($solution->solutionID, $optionID = 0, $score = 3, $user->userID); // increase $solution = new ContestSolutionEditor($solution->solutionID); $this->assertEquals($solution->ratings, 1); // decrease $rating->delete(); $solution = new ContestSolutionEditor($solution->solutionID); $this->assertEquals($solution->ratings, 0); }
/** * finish the contest */ public function close() { if (!($this->contest->state == 'scheduled' && $this->contest->untilTime < time())) { throw new Exception('contest needs to be scheduled, and time has to be over.'); } // make a jury instance from the contst owner $jury = ContestJury::find($this->contest->contestID, $this->contest->userID, $this->contest->groupID); if ($jury === null) { $jury = ContestJuryEditor::create($this->contest->contestID, $this->contest->userID, $this->contest->groupID, $state = 'accepted'); } $userID = $this->contest->userID; if ($userID == 0 && $this->contest->groupID > 0) { $sql = "SELECT userID\n\t\t\t\tFROM wcf" . WCF_N . "_user_to_groups\n\t\t\t\tWHERE groupID = " . intval($this->contest->groupID); $row = WCF::getDB()->getFirstRow($sql); $userID = $row['userID']; } if (!$userID) { throw new Exception('cannot determine a user from which the ratings will be added.'); } $classIDs = array_keys($this->contest->getClasses()); $ratingoptionIDs = array_keys(ContestRatingoption::getByClassIDs($classIDs)); if (empty($ratingoptionIDs)) { throw new Exception('cannot determine a ratingoption from classes [' . implode(',', $classIDs) . '] needed for contest ratings to be added.'); } // get interactions $interactionList = new ContestInteractionList($this->contest); $interactionList->sqlLimit = 0; $interactionList->readObjects(); $owners = $interactionList->getObjects(); foreach ($owners as $owner) { $this->sum += $owner->c; } // get prices $priceList = new ContestPriceList(); $priceList->sqlConditions .= 'contest_price.state = "accepted" AND contest_price.contestID = ' . intval($this->contest->contestID); $priceList->sqlLimit = 0; $priceList->readObjects(); $score = 5 + $priceList->countObjects(); foreach ($priceList->getObjects() as $price) { // choose a winner $owner = $this->chooseWinner($price, $owners); // error, there are more prices than participants if (!$owner) { throw new Exception('there are more prices than participants.'); } $lang = 'wcf.contest.interaction.tickets.solution'; $message = WCF::getLanguage()->getDynamicVariable($lang, array('tickets' => $owner->c)); // create pseudo solution $solution = ContestSolutionEditor::create($this->contest->contestID, $owner->participantID, $message, $state = 'accepted'); foreach ($ratingoptionIDs as $ratingOptionID) { // create pseudo rating $rating = ContestSolutionRatingEditor::create($solution->solutionID, $ratingOptionID, $score, $userID); } // decrease score $score--; } // close contest state $this->contest->getEditor()->updateState('closed'); }
/** * Updates this price and set the solution winner. * * @param integer $solutionID */ public function pick($solutionID, $position) { $sql = "UPDATE\twcf" . WCF_N . "_contest_price\n\t\t\tSET\tsolutionID = " . intval($solutionID) . ",\n\t\t\t\tposition = " . intval($position) . "\n\t\t\tWHERE\tpriceID = " . intval($this->priceID); WCF::getDB()->sendQuery($sql); // update pick times require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionEditor.class.php'; $solution = new ContestSolutionEditor($solutionID); $solution->updatePickTime(TIME_NOW); // update price expirations, next winner may only have 24 hours from now on require_once WCF_DIR . 'lib/data/contest/ContestEditor.class.php'; $contest = new ContestEditor($this->contestID); $contest->updatePickTimes(); // TODO: send secretMessage to winner if ($this->secretMessage) { // use notification api if (false) { require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; $owner = $this->getOwner(); ContestEventEditor::create($this->contestID, $owner->userID, $owner->groupID, 'ContestPriceSecretMessage', array('priceID' => $this->priceID, 'owner' => $owner->getName())); } // TODO: remove after notification api is implemented // TODO: missing translation if ($solution->getOwner()->userID) { $mail = new Mail($solution->getOwner()->email, 'easy-coding Gewinnspiel - du hast gewonnen', 'Hallo ' . $solution->getOwner()->getName() . ', du hast soeben einen Preis beim easy-coding Gewinnspiel gewählt. Der Sponsor hat dir dazu einen Hinweis mit folgendem Inhalt hinterlassen: ' . $this->secretMessage . ' Vielen Dank für die Teilnahme beim Gewinnspiel, Torben Brodt'); $mail->addBCC(MAIL_ADMIN_ADDRESS); $mail->send(); } } // TODO: pricepick: send event to sponsor if (false) { require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; $owner = $this->getOwner(); ContestEventEditor::create($this->contestID, $owner->userID, $owner->groupID, 'ContestPricePick', array('priceID' => $this->priceID, 'owner' => $owner->getName())); } }
/** * @see Form::save() */ public function save() { parent::save(); $participant = ContestParticipant::find($this->contest->contestID, $this->userID, $this->groupID); if ($participant === null) { require_once WCF_DIR . 'lib/data/contest/participant/ContestParticipantEditor.class.php'; $state = $this->contest->enableParticipantCheck ? 'applied' : 'accepted'; $participant = ContestParticipantEditor::create($this->contest->contestID, $this->userID, $this->groupID, $state); } // save solution $solution = ContestSolutionEditor::create($this->contest->contestID, $participant->participantID, $this->text, $this->state, $this->getOptions(), $this->attachmentListEditor); $this->saved(); // forward HeaderUtil::redirect('index.php?page=ContestSolutionEntry&contestID=' . $this->contest->contestID . '&solutionID=' . $solution->solutionID . SID_ARG_2ND_NOT_ENCODED . '#solution' . $solution->solutionID); exit; }
/** * @see Form::submit() */ public function submit() { // call submit event EventHandler::fireAction($this, 'submit'); $this->readFormParameters(); try { // attachment handling if ($this->showAttachments) { $this->attachmentListEditor->handleRequest(); } // preview if ($this->preview) { require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php'; AttachmentBBCode::setAttachments($this->attachmentListEditor->getSortedAttachments()); WCF::getTPL()->assign('preview', ContestSolutionEditor::createPreview($this->subject, $this->text, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes)); } // send message or save as draft if ($this->send) { $this->validate(); // no errors $this->save(); } } catch (UserInputException $e) { $this->errorField = $e->getField(); $this->errorType = $e->getType(); } }