/** * @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; }
/** * Notify previous participants that this competition is open for submissions * @since Version 3.9.1 * @return \Railpage\Images\Competition * @todo Check recipient preferences for email notifications */ public function notifySubmissionsOpen() { /** * Return if we're not within the submissions bounds */ if (!Utility\CompetitionUtility::isSubmissionWindowOpen($this)) { return $this; } /** * If we've recently sent a reminder, exit. No sense in nagging */ $datekey = sprintf("%sDate", __FUNCTION__); if (isset($this->meta[$datekey])) { if (strtotime($this->meta[$datekey]) >= strtotime("5 days ago")) { return $this; } $this->meta[__FUNCTION__] = false; } /** * Assemble our options to send to the mailer */ $body = sprintf("Hi [username],\n\nWe wanted to let you know that a new photo competition, <a href='%s'>%s</a>, is open for submissions 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->SubmissionsDateClose->format("F jS")); $notificationOptions = array("flag" => __FUNCTION__, "subject" => sprintf("Submissions open: %s", $this->title), "body" => $body, "excludeCurrentContestants" => true); /** * Dispatch */ Utility\CompetitionUtility::sendNotification($this, $notificationOptions); /** * Update our reminder date sent */ $this->meta[$datekey] = date(DateTime::ISO8601); $this->commit(); return $this; }