Beispiel #1
0
 /**
  * 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;
 }
 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]);
     }
 }
Beispiel #3
0
 public function onQuote()
 {
     if (!($user = Auth::getUser())) {
         throw new ApplicationException('You should be logged in.');
     }
     if (!($post = PostModel::find(post('post')))) {
         throw new ApplicationException('Unable to find that post.');
     }
     $result = $post->toArray();
     $result['author'] = $post->member ? $post->member->username : '******';
     return $result;
 }
Beispiel #4
0
 public function onUpdate()
 {
     $this->page['member'] = $member = $this->getMember();
     $topic = $this->getTopic();
     $post = PostModel::find(post('post'));
     if (!$post->canEdit()) {
         throw new ApplicationException('Permission denied.');
     }
     /*
      * Supported modes: edit, view, delete, save
      */
     $mode = post('mode', 'edit');
     if ($mode == 'save') {
         if (!$topic || !$topic->canPost()) {
             throw new ApplicationException('You cannot edit posts or make replies.');
         }
         $post->save(post());
         // First post will update the topic subject
         if ($topic->first_post->id == $post->id) {
             $topic->save(['subject' => post('subject')]);
         }
     } elseif ($mode == 'delete') {
         $post->delete();
     }
     $this->page['mode'] = $mode;
     $this->page['post'] = $post;
     $this->page['topic'] = $topic;
 }