示例#1
0
 /**
  * @depends test_createUser
  */
 public function test_createComp($User)
 {
     $Comp = new Competition();
     $Comp->title = "Test competition";
     $Comp->theme = "Test comp theme";
     $Comp->setAuthor($User);
     $Comp->SubmissionsDateOpen = (new DateTime())->add(new DateInterval("P1D"));
     $Comp->SubmissionsDateClose = (new DateTime())->add(new DateInterval("P3D"));
     $Comp->VotingDateOpen = (new DateTime())->add(new DateInterval("P5D"));
     $Comp->VotingDateClose = (new DateTime())->add(new DateInterval("P10D"));
     $Comp->commit();
     $Comp = new Competition($Comp->id);
     $this->assertEquals(Competitions::STATUS_CLOSED, $Comp->status);
     $this->assertFalse(!filter_var($Comp->id, FILTER_VALIDATE_INT));
     $this->assertFalse($Comp->canUserVote($User));
     $this->assertFalse($Comp->canUserSubmitPhoto($User));
     $Comp->SubmissionsDateOpen = (new DateTime())->sub(new DateInterval("P1D"));
     $Comp->SubmissionsDateClose = (new DateTime())->add(new DateInterval("P3D"));
     $Comp->VotingDateOpen = (new DateTime())->add(new DateInterval("P5D"));
     $Comp->VotingDateClose = (new DateTime())->add(new DateInterval("P10D"));
     $this->assertTrue(CompetitionUtility::isSubmissionWindowOpen($Comp));
     $this->assertFalse(CompetitionUtility::isVotingWindowOpen($Comp));
     $Comp->status = Competitions::STATUS_OPEN;
     $Comp->commit();
     $DummyUser = new User();
     $this->assertFalse($Comp->canUserVote($DummyUser));
     $this->assertFalse($Comp->canUserSubmitPhoto($DummyUser));
     return $Comp;
 }
示例#2
0
 /**
  * Notify the winner
  * @since Version 3.9.1
  * @return \Railpage\Gallery\Competition
  * @param \Railpage\Images\Competition
  * @todo Check recipient preferences for email notifications
  */
 public static function notifyWinner(Competition $compObject)
 {
     if (isset($compObject->meta['winnernotified']) && $compObject->meta['winnernotified'] === true) {
         return $this;
     }
     if ($Photo = $compObject->getWinningPhoto()) {
         /**
          * Create a news article
          */
         CompetitionUtility::createNewsArticle_Winner($compObject);
         /**
          * Create a site message
          */
         CompetitionUtility::createSiteNotificationForWinner($compObject);
         /**
          * Create an email
          */
         $Notification = new Notification();
         $Notification->AddRecipient($Photo->Author->id, $Photo->Author->username, $Photo->Author->contact_email);
         $Notification->subject = sprintf("Photo competition: %s", $compObject->title);
         /**
          * Set our email body
          */
         $body = sprintf("Hi %s,\n\nCongratulations! You won the <a href='%s'>%s</a> photo competition!\n\nAs the winner of this competition, you get to <a href='%s'>select a theme</a> for the next competition. You have seven days to do so, before we automatically select one.\n\nThanks\nThe Railpage team.", $Photo->Author->username, $compObject->url->canonical, $compObject->title, "https://www.railpage.com.au" . $compObject->url->suggestsubject);
         if (function_exists("wpautop") && function_exists("format_post")) {
             $body = wpautop(format_post($body));
         }
         /**
          * Assemble some template vars for our email
          */
         foreach ($Photo->Image->sizes as $size) {
             $hero = $size['source'];
             if ($size['width'] >= 600) {
                 break;
             }
         }
         $Smarty = AppCore::getSmarty();
         $Smarty->Assign("email", array("subject" => $Notification->subject, "hero" => array("image" => $hero, "title" => sprintf("Winning photo: Yours! <em>%s</em>", $Photo->Image->title), "link" => $compObject->url->url, "author" => $Photo->Author->username), "body" => $body));
         $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("template.generic"));
         $Notification->commit();
         /**
          * Update the winnernotified flag
          */
         $compObject->meta['winnernotified'] = true;
         $compObject->commit();
     }
     return $compObject;
 }
示例#3
0
 /**
  * Notify participants that this competition is open for voting
  * @since Version 3.9.1
  * @return \Railpage\Images\Competition
  * @todo Check recipient preferences for email notifications
  */
 private function notifyVotingOpen()
 {
     /**
      * Return if we're not within the voting bounds
      */
     if (!Utility\CompetitionUtility::isVotingWindowOpen($this)) {
         return $this;
     }
     $body = sprintf("Hi [username],\n\nWe wanted to let you know that the <a href='%s'>%s</a> photo competition is open for voting until %s.\n\nYou've received this email because you've participated in a previous photo competition.\n\nThanks\nThe Railpage team.", $this->url->email, $this->title, $this->VotingDateClose->format("F jS"));
     $notificationOptions = array("flag" => __FUNCTION__, "subject" => sprintf("Voting open: %s", $this->title), "body" => $body);
     Utility\CompetitionUtility::sendNotification($this, $notificationOptions);
     return $this;
 }
示例#4
0
 /**
  * Create a photo competition object from an ID or URL slug
  * @since Version 3.10.0
  * @param string|int $id
  * @return \Railpage\Images\Competition
  */
 public static function CreatePhotoComp($id)
 {
     //$Database = AppCore::GetDatabase();
     $cacheHandler = AppCore::getRedis();
     $Registry = Registry::getInstance();
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $lookup = Utility\CompetitionUtility::getIDFromSlug($id);
         if (!filter_var($lookup, FILTER_VALIDATE_INT)) {
             throw new Exception("Could not find a competition ID from URL slug " . $id);
         }
         $id = $lookup;
     }
     $regkey = sprintf(Competition::CACHE_KEY, $id);
     try {
         $Competition = $Registry->get($regkey);
     } catch (Exception $e) {
         #if (!$Competition = $cacheHandler->fetch($regkey)) {
         $Competition = new Competition($id);
         $cacheHandler->save($regkey, $Competition, strtotime("+1 day"));
         #}
         $Registry->set($regkey, $Competition);
     }
     return $Competition;
 }