예제 #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
 /**
  * Send out a notification to site admins to cast a deciding vote in the event of a tied competition
  * @since Version 3.10.0
  * @param \Railpage\Images\Competition $photoComp
  * @return void
  */
 public static function NotifyTied(Competition $photoComp)
 {
     if (isset($photoComp->meta['notifytied']) && $photoComp->meta['notifytied'] >= strtotime("-1 day")) {
         return;
     }
     $photoComp->meta['notifytied'] = time();
     $photoComp->commit();
     $Smarty = AppCore::GetSmarty();
     // User who will cast the deciding vote
     $Decider = UserFactory::CreateUser(45);
     // Create the push notification
     $Push = new Notification();
     $Push->transport = Notifications::TRANSPORT_PUSH;
     $Push->subject = "Tied photo competition";
     $Push->body = sprintf("The %s photo competition is tied. Cast a deciding vote ASAP.", $photoComp->title);
     $Push->setActionUrl($photoComp->url->tied)->addRecipient($Decider->id, $Decider->username, $Decider->username);
     $Push->commit()->dispatch();
     // Create an email notification as a backup
     $Email = new Notification();
     $Email->subject = "Tied competition: " . $photoComp->title;
     $Email->addRecipient($Decider->id, $Decider->username, $Decider->username);
     $tpl = $Smarty->ResolveTemplate("template.generic");
     $email = array("subject" => $Email->subject, "subtitle" => "Photo competitions", "body" => sprintf("<p>The <a href='%s'>%s</a>photo competition is tied and requires a deciding vote. <a href='%s'>Cast it ASAP</a>.</p>", $photoComp->url->canonical, $photoComp->title, $photoComp->url->tied));
     $Smarty->Assign("email", $email);
     $Email->body = $Smarty->fetch($tpl);
     $Email->commit();
     return;
 }