contentPostID = $row['ContentRepostContentPostID']; $this->repostedPostID = $row['RepostedPostID']; parent::__construct($row); } /************************************************************************** * CRUD Functions **************************************************************************/ public static function create($userID, $languageID, $text, $contentPostID, $repostedPostID) { if (!filter_var($contentPostID, FILTER_VALIDATE_INT)) { throw new \InvalidArgumentException("Invalid content post ID: $contentPostID"); } if (!filter_var($repostedPostID, FILTER_VALIDATE_INT)) { throw new \InvalidArgumentException("Invalid reposted post ID: $repostedPostID"); } $newPostID = parent::create($userID, $languageID, $text); safe_dbwrite(" UPDATE tig.ProfilePosts SET ContentRepostContentPostID = $contentPostID, RepostedPostID = $repostedPostID WHERE ID = $newPostID "); return $newPostID; } public static function readByContentPostID($id, $excludePostID = null) { if (!filter_var($id, FILTER_VALIDATE_INT)) { throw new \InvalidArgumentException("Invalid ID: $id"); } $rows = safe_dbread("SELECT * FROM tig.ProfilePosts WHERE ContentRepostContentPostID = $id"); $reposts = array(); while ($row = safe_fetch_assoc($rows)) { if ($row['ID'] != $excludePostID) { $reposts[] = new self($row); } } return $reposts; } /************************************************************************** * Getters \ Setters **************************************************************************/ public function getContentPost() { return Post::readByID($this->contentPostID); } public function getRepostedPost() { return Post::readByID($this->repostedPostID); } /************************************************************************** * Required by Post **************************************************************************/ public function getHtmlizedText() { return htmlspecialchars($this->text); } public function isRepostableByUser($userID) { if (!filter_var($userID, FILTER_VALIDATE_INT)) { throw new \InvalidArgumentException("Invalid user ID: $userID"); } // Users cannot repost their own repost if ($this->userID == $userID) { return false; } // Users cannot repost original posts they have created if ($this->getContentPost()->getUserID() == $userID) { return false; } // Users cannot repost on things they've already reposted. If they are // able to do this, they would show up multiple times in the Global // Perspectives listing. $relatedPosts = $this->getRelatedPosts(); foreach ($relatedPosts as $post) { if ($post->getUserID() == $userID) { return false; } } return true; } public function repost($userID, $languageID, $text) { return ContentRepost::create($userID, $languageID, $text, $this->contentPostID, $this->id); } /** * In this case, related posts are reposts about the same original content * post. * * @return array */ public function getRelatedPosts() { return self::readByContentPostID($this->contentPostID, $this->id); } }