diff --git a/src/Posts/Post.php b/src/Posts/Post.php index 6ae2685..a36e929 100644 --- a/src/Posts/Post.php +++ b/src/Posts/Post.php @@ -34,6 +34,27 @@ return $query->num_rows === 1 ? new static($query->fetch_assoc()[Posts::ID->value]) : null; } + /** + * Create and return a shallow copy of a Post + * + * @param Post $post + * @return static + */ + public static function clone(Post $post): static { + $clone = Post::new($post->post_title); + + foreach (Posts::cases() as $column) { + // ID column has to be unique, skip it + if ($column === Posts::ID) { + continue; + } + + $clone->{$column->value} = $post->{$column->value}; + } + + return $clone; + } + /** * Create a new post * @@ -166,9 +187,14 @@ set (DateTimeImmutable $post_modified_gmt) => $this->set(Posts::POST_MODIFIED_GMT->value, $post_modified_gmt->format(static::DATETIME_FORMAT), $post_modified_gmt); } - public Post|false|null $post_parent { - get => $this->get(Posts::POST_PARENT->value) !== 0 ? new self($this->get(Posts::POST_PARENT->value)) : null; - set (Post|false|null $post_parent) => $this->set(Posts::POST_PARENT->value, $post_parent ? $post_parent->id : 0, $post_parent); + public string $post_content_filtered { + get => $this->get(Posts::POST_CONTENT_FILTERED->value); + set (string $post_content_filtered) => $this->set(Posts::POST_CONTENT_FILTERED->value, $post_content_filtered); + } + + public ?Post $post_parent { + get => $this->get(Posts::POST_PARENT->value) !== 0 ? new self($this->get(Posts::POST_PARENT->value)) : null; + set (?Post $post_parent) => $this->set(Posts::POST_PARENT->value, $post_parent ? $post_parent->id : 0, $post_parent); } public string $guid {