Discussion::class, 'foreign_key' => 'discussion_id', 'assoc_foreign_key' => 'discussion_id' ]; $config['belongs_to']['posting'] = [ 'class_name' => Posting::class, 'foreign_key' => 'parent_id', 'assoc_foreign_key' => 'posting_id' ]; $config['belongs_to']['user'] = [ 'class_name' => User::class, 'foreign_key' => 'user_id', 'assoc_foreign_key' => 'user_id' ]; $config['has_many']['reactions'] = [ 'class_name' => PostingReaction::class, 'foreign_key' => 'posting_id', 'assoc_foreign_key' => 'posting_id' ]; $config['additional_fields']['author']['get'] = 'getAuthor'; $config['registered_callbacks']['after_create'][] = 'onCreate'; $config['registered_callbacks']['after_delete'][] = 'onDelete'; parent::configure($config); } public function getAuthor(): ?MemberDTO { if ($this->anonymous && $this->user_id !== User::findCurrent()->user_id) { return MemberDTO::fromArray(); } $user = $this->user; if ($user) { return MemberDTO::fromUser($user, $this->range_id); } return null; } public static function getRecentPosts($range_id, int $last_visit = 0): array { $query = [ "SELECT forum_discussions.*, COUNT(DISTINCT forum_postings.posting_id) AS 'posts' FROM forum_topics JOIN forum_discussions USING(topic_id) JOIN forum_postings USING(discussion_id) WHERE forum_topics.range_id = :range_id AND forum_postings.user_id != :user_id ", [ 'range_id' => $range_id, 'user_id' => User::findCurrent()->user_id ] ]; if ($last_visit) { $query[0] .= " AND forum_postings.mkdate > :last_visit"; $query[1]["last_visit"] = $last_visit; } return \DBManager::get()->fetchAll( $query[0]." GROUP BY discussion_id ORDER BY forum_postings.mkdate DESC", $query[1] ); } public function getOpenGraphURLs(): array { $content = preg_replace("~(.*)~si", '', $this['content']); return array_filter(OpenGraph::extract($content)->toArray(), fn($og) => $og['is_opengraph']); } public function onCreate(): void { $postingNotification = new PostingNotification($this); $postingNotification->notifySubscribers(); } public function onDelete(): void { PostingReaction::deleteBySQL("posting_id = ?", [$this->posting_id]); } }