/** * Creates a postinside a topic * @param Topic $topic * @param Member $member * @param array $data Post data: subject, content. * @return self */ public static function createInTopic($topic, $member, $data) { $post = new static(); $post->topic = $topic; $post->member = $member; $post->subject = array_get($data, 'subject', $topic->subject); $post->content = array_get($data, 'content'); $post->save(); TopicFollow::follow($topic, $member); $member->touchActivity(); return $post; }
private function followExistingPosts() { /* * Follow exisiting posts */ $migrated = []; foreach (Post::all() as $post) { $code = $post->topic_id . '!' . $post->member_id; if (isset($migrated[$code])) { continue; } $migrated[$code] = true; TopicFollow::insert(['topic_id' => $post->topic_id, 'member_id' => $post->member_id, 'created_at' => $post->created_at, 'updated_at' => $post->updated_at]); } }
/** * Creates a topic and a post inside a channel * @param Channel $channel * @param Member $member * @param array $data Topic and post data: subject, content. * @return self */ public static function createInChannel($channel, $member, $data) { $topic = new static(); $topic->subject = array_get($data, 'subject'); $topic->channel = $channel; $topic->start_member = $member; $post = new Post(); $post->topic = $topic; $post->member = $member; $post->content = array_get($data, 'content'); Db::transaction(function () use($topic, $post) { $topic->save(); $post->save(); }); TopicFollow::follow($topic, $member); $member->touchActivity(); return $topic; }
public function onFollow() { try { if (!($user = Auth::getUser())) { throw new ApplicationException('You should be logged in.'); } $this->page['member'] = $member = $this->getMember(); $this->page['topic'] = $topic = $this->getTopic(); TopicFollow::toggle($topic, $member); $member->touchActivity(); } catch (Exception $ex) { if (Request::ajax()) { throw $ex; } else { Flash::error($ex->getMessage()); } } }
/** * Returns true if this member is following this topic. * @param Topic $topic * @return boolean */ public function isFollowing($topic) { return TopicFollow::check($topic, $this); }