/**
  * 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);
 }
    /**
     * 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()));
        }
    }
Exemplo n.º 7
0
 public function testReflectionAPI()
 {
     require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php';
     $this->deleteArray[] = $event = ContestEventEditor::create($contestID = 0, $userID = 0, $groupID = 0, $eventName = __METHOD__ . '.eventName');
     $this->callAllMethodsWithoutRequiredParameters($event);
 }
Exemplo n.º 8
0
 /**
  * updates state
  *
  * @param	$state		string
  */
 public function updateState($state)
 {
     // update data
     $sql = "UPDATE\twcf" . WCF_N . "_contest\n\t\t\tSET\tstate = '" . escapeString($state) . "'\n\t\t\tWHERE\tcontestID = " . intval($this->contestID);
     WCF::getDB()->sendQuery($sql);
     // if state is changed to closed, then update timestamps, when winners have to pick prices
     if ($state == 'closed') {
         // winners cannot choose prices on their own, so give prices now
         if ($this->enablePricechoice) {
             $nextSolution = $this->updatePickTimes();
         } else {
             $this->updatePricechoices();
             // notify all participants that contest is finished
             if (false) {
                 require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php';
                 $owner = $this->getOwner();
                 ContestEventEditor::create($contestID, $owner->userID, $owner->groupID, 'ContestState', array('priceID' => $priceID, 'owner' => $owner->getName()));
             }
         }
     }
 }
    /**
     * Sends notification
     */
    public function sendPickNotification()
    {
        // use notification api
        if (false) {
            require_once WCF_DIR . 'lib/data/contest/event/ContestEventEditor.class.php';
            $owner = $this->getOwner();
            ContestEventEditor::create($contestID, $owner->userID, $owner->groupID, 'ContestPriceExpire', array('priceID' => $priceID, 'owner' => $owner->getName()));
        }
        // use mail if participant is single user
        // TODO: remove after notification api is implemented
        // TODO: missing translation
        if ($this->getOwner()->userID) {
            require_once WCF_DIR . 'lib/data/mail/Mail.class.php';
            $mail = new Mail($this->getOwner()->email, 'easy-coding Gewinnspiel - du hast gewonnen', 'Hallo ' . $this->getOwner()->getName() . ',
du gehörst zu den glücklichen Gewinnern beim easy-coding Gewinnspiel.
Bitte suche dir innerhalb von 24h auf folgender Seite einen Preis aus: ' . PAGE_URL . '/index.php?page=ContestPrice&contestID=' . $this->contestID . '

Vielen Dank für die Teilnahme beim Gewinnspiel,

Torben Brodt');
            $mail->addBCC(MAIL_ADMIN_ADDRESS);
            $mail->send();
        }
    }