id = (int) ( $data['id'] ?? 0 ); $this->source_type = $data['source_type']; $this->source_id = $data['source_id']; $this->subreddit = $data['subreddit'] ?? null; $this->title = $data['title'] ?? null; $this->content = $data['content'] ?? null; $this->author = $data['author'] ?? null; $this->score = (int) ( $data['score'] ?? 0 ); $this->comment_count = (int) ( $data['comment_count'] ?? 0 ); $this->permalink = $data['permalink'] ?? null; $this->collected_at = $data['collected_at'] ?? current_time( 'mysql' ); $this->metadata = $data['metadata'] ?? null; } public function get_id(): int { return $this->id; } public function get_source_type(): string { return $this->source_type; } public function get_source_id(): string { return $this->source_id; } public function get_subreddit(): ?string { return $this->subreddit; } public function get_title(): ?string { return $this->title; } public function get_content(): ?string { return $this->content; } public function get_author(): ?string { return $this->author; } public function get_score(): int { return $this->score; } public function get_comment_count(): int { return $this->comment_count; } public function get_permalink(): ?string { return $this->permalink; } public function get_collected_at(): string { return $this->collected_at; } public function get_metadata(): ?array { return $this->metadata; } /** * Convert to array for database insertion. * * @return array */ public function to_db_row(): array { return [ 'source_type' => $this->source_type, 'source_id' => $this->source_id, 'subreddit' => $this->subreddit, 'title' => $this->title, 'content' => $this->content, 'author' => $this->author, 'score' => $this->score, 'comment_count' => $this->comment_count, 'permalink' => $this->permalink, 'collected_at' => $this->collected_at, 'metadata_json' => null !== $this->metadata ? wp_json_encode( $this->metadata ) : null, ]; } }