/** * Nominate a photo * @since Version 3.9.1 * @param \Railpage\Images\Image $imageObject * @param \DateTime $dateWeek * @param \Railpage\Users\User $userObject * @return boolean */ public function NominateImage(Image $imageObject, DateTime $dateWeek, User $userObject) { $query = "SELECT id FROM image_weekly WHERE datefrom = ?"; if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { $dateWeek->add(new DateInterval("P7D")); } } if ($this->db->fetchOne($query, $dateWeek->format("Y-m-d"))) { throw new Exception("We already have an image nominated for the week starting " . $dateWeek->format("Y-m-d")); } if ($this->db->fetchOne("SELECT id FROM image_weekly WHERE image_id = ?", $imageObject->id)) { throw new Exception("This photo has already been nominated for Photo of the Week"); } $data = ["image_id" => $imageObject->id, "datefrom" => $dateWeek->format("Y-m-d"), "added_by" => $userObject->id]; $this->db->insert("image_weekly", $data); try { if (isset($imageObject->author->User) && $imageObject->author->User instanceof User) { $Message = new Message(); $Message->setAuthor($userObject); $Message->setRecipient($imageObject->author->User); $Message->subject = "Photo of the Week"; $Message->body = sprintf("Your [url=%s]photo[/url] has been nominated for Photo of the Week. \n\nRegards,\n%s\n\nThis is an automated message.", $imageObject->url, $userObject->username); $Message->send(); } } catch (Exception $e) { // throw it away } return true; }
/** * Commit changes to this warning * * @since Version 3.8.7 * @return void */ public function commit() { $this->validate(); $data = array("new_warning_level" => trim($this->level), "old_warning_level" => $this->level - trim($this->adjustment), "warn_reason" => trim($this->reason), "actiontaken" => trim($this->action), "mod_comments" => trim($this->comments), "user_id" => $this->Recipient->id, "warned_by" => $this->Issuer->id, "warn_date" => $this->Date->getTimestamp()); $this->db->insert("phpbb_warnings", $data); $this->id = $this->db->lastInsertId(); $this->Recipient->warning_level = $this->level; $this->Recipient->commit(); $Message = new Message(); $Message->setRecipient($this->Recipient); $Message->setAuthor($this->Issuer); $Message->subject = "You have received an official warning from Railpage"; $Message->body = sprintf("%s,\n\nYou have been issued a warning for breaching our Terms of Use or Rules for Posting.\n\n[b]Reason[/b]\n%s\n\n[b]Action taken[/b]\n%s\n\nRegards,\n%s\n\nRailpage Moderator Team.", $this->Recipient->username, $this->reason, $this->action, $this->Issuer->username); $Message->send(); }
/** * Ignore this correction * @since Version 3.8.7 * @throws \Exception if $this->Resolution->User is not an instance of \Railpage\Users\User * @return boolean * @param string $reason */ public function ignore($reason = NULL) { if (!$this->Resolution->User instanceof User) { throw new Exception("Cannot ignore correction - User resolving this correction not specified"); } $this->Resolution->Date = new DateTime(); $data = array("status" => self::STATUS_IGNORED, "resolved_by" => $this->Resolution->User->id, "resolved_date" => $this->Resolution->Date->format("Y-m-d H:i:s")); $where = array("correction_id = ?" => $this->id); $this->db->update("loco_unit_corrections", $data, $where); /** * Send a PM to the author of the correction */ $Message = new Message(); $Message->setAuthor($this->Resolution->User); $Message->setRecipient($this->User); $Message->subject = "Your Locomotives database correction was not accepted"; $Message->body = "Your suggested correction for [url=" . $this->Loco->url->url . "]" . $this->Loco->number . "[/url] in [url=" . $this->Loco->Class->url->url . "]" . $this->Loco->Class->name . "[/url] was not accepted by " . $this->Resolution->User->username . "."; if (!empty($this->text)) { $Message->body .= "\n\n[quote=Your suggestion]" . $this->text . "[/quote]"; } if (!is_null($reason)) { $Message->body .= "\n\n" . $reason; } $Message->body .= "\n\nThis is an automated message - there is no need to reply."; $Message->send(); return true; }
/** * Close this correction * @since Version 3.9.1 * @param string $action * @param \Railpage\Users\User $Staff * @param string $comments * @return void */ private function close($action = false, User $Staff, $comments = NULL) { $this->status = $action == "reject" ? self::STATUS_REJECTED : self::STATUS_CLOSED; $this->DateClosed = new DateTime(); $this->commit(); $verb = $action == "reject" ? "not accepted" : "accepted"; $Message = new Message(); $Message->setAuthor($Staff); $Message->setRecipient($this->Author); $Message->subject = "Your Locations correction was " . $verb; $Message->body = "Your suggested correction for [url=" . $this->Location->url->url . "]" . strval($this->Location) . "[/url] in [url=" . $this->Location->Region->url->url . "]" . strval($this->Location->Region) . "[/url] was " . $verb . " by " . $Staff->username . "."; if (!empty($this->comments)) { $Message->body .= "\n\n[quote=Your suggestion]" . $this->comments . "[/quote]"; } if (!is_null($comments)) { $Message->body .= "\n\n" . $comments; } $Message->body .= "\n\nThis is an automated message - there is no need to reply."; $Message->send(); return; }
/** * close the correction * @since Version 3.9.1 * @param string $type * @param string $reason * @return void */ private function closeCorrection($type, $reason) { if (!isset($this->Resolution->User) || !$this->Resolution->User instanceof User) { throw new Exception("Cannot close correction - User resolving this correction not specified"); } $this->Resolution->Date = new DateTime(); $data = array("status" => $type == "accept" ? self::STATUS_CLOSED : self::STATUS_IGNORED, "resolved_by" => $this->Resolution->User->id, "resolved_date" => $this->Resolution->Date->format("Y-m-d H:i:s")); $where = array("correction_id = ?" => $this->id); $this->db->update("loco_unit_corrections", $data, $where); /** * Send a PM to the author of the correction */ $Message = new Message(); $Message->setAuthor($this->Resolution->User); $Message->setRecipient($this->User); $Message->subject = $type == "accept" ? "Your Locomotives database correction has been accepted" : "Your Locomotives database correction was not accepted"; $action = $type == "accept" ? "has been accepted" : "was not accepted"; if ($this->Object instanceof Locomotive) { $Message->body = "Your suggested correction for [url=" . $this->Object->url->url . "]" . strval($this->Object) . "[/url] in [url=" . $this->Object->Class->url->url . "]" . $this->Object->Class->name . "[/url] " . $action . " by " . $this->Resolution->User->username . "."; } else { $Message->body = "Your suggested correction for [url=" . $this->Object->url . "]" . strval($this->Object) . "[/url] " . $action . " by " . $this->Resolution->User->username . "."; } if (!empty($this->text)) { $Message->body .= "\n\n[quote=Your suggestion]" . $this->text . "[/quote]"; } if (!is_null($reason)) { $Message->body .= "\n\n" . $reason; } $Message->body .= "\n\nThis is an automated message - there is no need to reply."; $Message->send(); }