/** * Creates a new sponsor. * * @param integer $contestID * @param integer $userID * @param integer $groupID * @param string $state * @return ContestSponsorEditor */ public static function create($contestID, $userID, $groupID, $state) { // check primary keys $existing = self::find($contestID, $userID, $groupID); if ($existing) { $update = false; if ($existing->state == 'invited' && $state == 'applied' || $existing->state == 'applied' && $state == 'invited') { $state = 'accepted'; $update = true; } else { if ($state != $existing->state) { $update = true; } } if ($update) { $existing->update($contestID, $userID, $groupID, $state); } return $existing; } $sql = "INSERT INTO\twcf" . WCF_N . "_contest_sponsor\n\t\t\t\t\t(contestID, userID, groupID, state, time)\n\t\t\tVALUES\t\t(" . intval($contestID) . ", " . intval($userID) . ", " . intval($groupID) . ", '" . escapeString($state) . "', " . TIME_NOW . ")"; WCF::getDB()->sendQuery($sql); // get new id $sponsorID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_contest_sponsor", 'sponsorID'); // update entry $sql = "UPDATE\twcf" . WCF_N . "_contest\n\t\t\tSET\tsponsors = sponsors + 1\n\t\t\tWHERE\tcontestID = " . intval($contestID); WCF::getDB()->sendQuery($sql); // sent event require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; ContestEventEditor::create($contestID, $userID, $groupID, __CLASS__, array('state' => $state, 'sponsorID' => $sponsorID, 'owner' => ContestOwner::get($userID, $groupID)->getName())); return new ContestSponsorEditor($sponsorID); }
/** * Updates this participant. * * @param integer $contestID * @param integer $userID * @param integer $groupID * @param string $state */ public function update($contestID, $userID, $groupID, $state) { $sql = "UPDATE\twcf" . WCF_N . "_contest_participant\n\t\t\tSET\tcontestID = " . intval($contestID) . ", \n\t\t\t\tuserID = " . intval($userID) . ", \n\t\t\t\tgroupID = " . intval($groupID) . ", \n\t\t\t\tstate = '" . escapeString($state) . "'\n\t\t\tWHERE\tparticipantID = " . intval($this->participantID); WCF::getDB()->sendQuery($sql); // send event require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; ContestEventEditor::create($contestID, $userID, $groupID, __CLASS__, array('state' => $state, 'participantID' => $this->participantID, 'owner' => ContestOwner::get($userID, $groupID)->getName())); }
/** * Creates a new entry comment. * * @param integer $solutionID * @param string $comment * @param integer $userID * @param string $username * @param integer $time * @return ContestSolutionCommentEditor */ public static function create($solutionID, $comment, $userID, $username, $time = TIME_NOW) { $sql = "INSERT INTO\twcf" . WCF_N . "_contest_solution_comment\n\t\t\t\t\t(solutionID, userID, username, comment, time)\n\t\t\tVALUES\t\t(" . intval($solutionID) . ", " . intval($userID) . ", '" . escapeString($username) . "', '" . escapeString($comment) . "', " . $time . ")"; WCF::getDB()->sendQuery($sql); // get id $commentID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_contest_solution_comment", 'commentID'); // update entry $sql = "UPDATE\twcf" . WCF_N . "_contest_solution\n\t\t\tSET\tcomments = comments + 1\n\t\t\tWHERE\tsolutionID = " . intval($solutionID); WCF::getDB()->sendQuery($sql); // sent event require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; ContestEventEditor::create($solutionID, $userID, $groupID = 0, __CLASS__, array('commentID' => $commentID, 'owner' => ContestOwner::get($userID, $groupID)->getName())); return new ContestSolutionCommentEditor($commentID); }
/** * Creates a new entry rating. * * @param integer $solutionID * @param integer $optionID * @param integer $score * @param integer $userID * @param integer $time * @return ContestSolutionRatingEditor */ public static function create($solutionID, $optionID, $score, $userID, $time = TIME_NOW) { $sql = "INSERT INTO\twcf" . WCF_N . "_contest_solution_rating\n\t\t\t\t\t(solutionID, userID, optionID, score, time)\n\t\t\tVALUES\t\t(" . intval($solutionID) . ", " . intval($userID) . ", " . intval($optionID) . ", " . intval($score) . ", " . $time . ")"; WCF::getDB()->sendQuery($sql); // get id $ratingID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_contest_solution_rating", 'ratingID'); // update entry $sql = "UPDATE\twcf" . WCF_N . "_contest_solution\n\t\t\tSET\tratings = ratings + 1\n\t\t\tWHERE\tsolutionID = " . intval($solutionID); WCF::getDB()->sendQuery($sql); // sent event require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; ContestEventEditor::create($solutionID, $userID, $groupID = 0, __CLASS__, array('ratingID' => $ratingID, 'owner' => ContestOwner::get($userID, $groupID)->getName())); return new ContestSolutionRatingEditor($ratingID); }
/** * Creates a new entry jurytalk. * * @param integer $contestID * @param string $message * @param integer $userID * @param string $username * @param integer $time * @return ContestJurytalkEditor */ public static function create($contestID, $message, $userID, $username, $time = TIME_NOW) { $sql = "INSERT INTO\twcf" . WCF_N . "_contest_jurytalk\n\t\t\t\t\t(contestID, userID, username, message, time)\n\t\t\tVALUES\t\t(" . intval($contestID) . ", " . intval($userID) . ", '" . escapeString($username) . "', '" . escapeString($message) . "', " . $time . ")"; WCF::getDB()->sendQuery($sql); // get id $jurytalkID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_contest_jurytalk", 'jurytalkID'); // update entry $sql = "UPDATE\twcf" . WCF_N . "_contest\n\t\t\tSET\tjurytalks = jurytalks + 1\n\t\t\tWHERE\tcontestID = " . intval($contestID); WCF::getDB()->sendQuery($sql); // sent event require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; ContestEventEditor::create($contestID, $userID, $groupID = 0, __CLASS__, array('jurytalkID' => $jurytalkID, 'owner' => ContestOwner::get($userID, $groupID = 0)->getName())); return new ContestJurytalkEditor($jurytalkID); }
/** * Creates a new contest entry. * * @param integer $userID * @param integer $groupID * @param string $subject * @param string $message * @param array $options * @param integer $classIDArray * @param integer $participants * @param integer $jurys * @param integer $prices * @param integer $sponsors * @param MessageAttachmentListEditor $attachmentList * @return ContestEditor */ public static function create($userID, $groupID, $subject, $message, $options = array(), $state = 'private', $classIDArray = array(), $participants = array(), $jurys = array(), $prices = array(), $sponsors = array(), $attachmentList = null) { // get number of attachments $attachmentsAmount = $attachmentList !== null ? count($attachmentList->getAttachments()) : 0; // save entry $sql = "INSERT INTO\twcf" . WCF_N . "_contest\n\t\t\t\t\t(userID, groupID, subject, message, time, attachments, enableSmilies, enableHtml,\n\t\t\t\t\tenableBBCodes, enableSolution, enableOpenSolution, enableParticipantCheck,\n\t\t\t\t\tenablePricechoice, priceExpireSeconds, enableSponsorCheck)\n\t\t\tVALUES\t\t(" . intval($userID) . ", " . intval($groupID) . ", '" . escapeString($subject) . "', '" . escapeString($message) . "', \n\t\t\t\t\t" . TIME_NOW . ", " . $attachmentsAmount . ",\n\t\t\t\t\t" . (isset($options['enableSmilies']) ? $options['enableSmilies'] : 1) . ",\n\t\t\t\t\t" . (isset($options['enableHtml']) ? $options['enableHtml'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enableBBCodes']) ? $options['enableBBCodes'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enableSolution']) ? $options['enableSolution'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enableOpenSolution']) ? $options['enableOpenSolution'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enableParticipantCheck']) ? $options['enableParticipantCheck'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enablePricechoice']) ? $options['enablePricechoice'] : 0) . ",\n\t\t\t\t\t" . (isset($options['priceExpireSeconds']) ? $options['priceExpireSeconds'] : 0) . ",\n\t\t\t\t\t" . (isset($options['enableSponsorCheck']) ? $options['enableSponsorCheck'] : 0) . ")"; WCF::getDB()->sendQuery($sql); // get id $contestID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_contest", 'contestID'); // sent event require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php'; require_once WCF_DIR . 'lib/data/contest/owner/ContestOwner.class.php'; ContestEventEditor::create($contestID, $userID, $groupID, __CLASS__, array('contestID' => $contestID, 'state' => $state, 'owner' => ContestOwner::get($userID, $groupID)->getName())); // get new object $entry = new self($contestID); // update classes if (count($classIDArray) > 0) { $entry->setClasses($classIDArray); } // update participants $entry->setParticipants($participants); // update jurys $entry->setJurys($jurys); // update prices $sponsorID = 0; if (count($sponsors) > 0 || count($prices) > 0) { if (count($prices)) { $sponsorID = $entry->setSponsors($sponsors, $userID, $groupID); } else { $entry->setSponsors($sponsors); $sponsorID = 0; } } // update prices $entry->setPrices($prices, $sponsorID); // update attachments if ($attachmentList !== null) { $attachmentList->updateContainerID($contestID); $attachmentList->findEmbeddedAttachments($message); } // return object return $entry; }
/** * Returns the title of this class. * * @return string */ public function __toString() { return "" . $this->owner->getName(); }
/** * Returns true, if the active user is member * * @return boolean */ public function isOwner() { return ContestOwner::get($this->userID, $this->groupID)->isCurrentUser(); }
/** * returns owner object * * @return ContestOwner */ public function getOwner() { return ContestOwner::get($this->userID, $this->groupID); }
/** * is winner? * * @return boolean */ public function isWinner() { return $this->winner ? $this->winner->isCurrentUser() : false; }