Beispiel #1
0
 /**
  * Create post
  * @param integer $id
  * @return boolean
  */
 public function create($id)
 {
     $user = Yii::$app->getUser()->getIdentity();
     $topic = Topic::findOne($id);
     $this->_topic = $topic;
     $post = new Post();
     $post->topic_id = $this->_topic->id;
     $post->message = $this->message;
     $post->save();
     $this->_topic->updateCounters(['number_posts' => 1]);
     $this->_topic->last_post_id = $post->id;
     $this->_topic->last_post_user_id = $user->id;
     $this->_topic->last_post_created_at = time();
     $this->_topic->last_post_username = $user->username;
     $this->_post = $post;
     if ($this->_topic->save()) {
         return true;
     }
     return false;
 }