/** * Commit changes to this competition * @since Version 3.9.1 * @return \Railpage\Images\Competition */ public function commit() { $this->validate(); $data = array("title" => $this->title, "theme" => $this->theme, "description" => $this->description, "slug" => $this->slug, "status" => $this->status, "author" => $this->Author->id, "voting_date_open" => $this->VotingDateOpen instanceof DateTime ? $this->VotingDateOpen->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "voting_date_close" => $this->VotingDateClose instanceof DateTime ? $this->VotingDateClose->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "submissions_date_open" => $this->SubmissionsDateOpen instanceof DateTime ? $this->SubmissionsDateOpen->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "submissions_date_close" => $this->SubmissionsDateClose instanceof DateTime ? $this->SubmissionsDateClose->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "meta" => json_encode($this->meta)); if (filter_var($this->id, FILTER_VALIDATE_INT)) { $where = array("id = ?" => $this->id); $this->db->update("image_competition", $data, $where); } if (!filter_var($this->id, FILTER_VALIDATE_INT)) { $this->db->insert("image_competition", $data); $this->id = $this->db->lastInsertId(); } /** * Clear the cache */ $regkey = sprintf(self::CACHE_KEY, $this->id); $Redis = AppCore::GetRedis(); $Memcached = AppCore::GetMemcached(); $Redis->delete($regkey); $Memcached->delete($regkey); /** * Check our themes and see if we need to mark this theme as used */ $themes = (new Competitions())->getSuggestedThemes(); foreach ($themes as $key => $theme) { $theme['theme'] = ContentUtility::FormatTitle($theme['theme']); if ((!isset($theme['used']) || $theme['used'] === false) && $theme['theme'] === $this->theme) { $themes[$key]['used'] = true; } } $Config = new Config(); $Config->set("image.competition.suggestedthemes", json_encode($themes), "Photo competition themes"); $this->url = Utility\Url::makeCompetitionUrls($this); return $this; }
/** * Suggest a theme to add * @since Version 3.9.1 * @return \Railpage\Images\Competitions * @param string $theme The short descriptive text for the theme (eg "At night", "Close up", etc) * @param boolean $winner True/false flag indicating if this theme has been suggested by a competition winner */ public function suggestTheme($theme, $winner = null) { if (!$this->Author instanceof User) { throw new Exception("You have not set the author of this theme (hint: Competitions::setAuthor()"); } if (empty($theme)) { throw new Exception("You haven't entered any text..."); } $theme = ContentUtility::FormatTitle($theme); $themes = $this->getSuggestedThemes(); array_unshift($themes, ["user" => ["id" => $this->Author->id, "username" => $this->Author->username], "theme" => $theme, "winner" => $winner]); $Config = new Config(); $Config->set("image.competition.suggestedthemes", json_encode($themes), "Photo competition themes"); return $this; }