Пример #1
0
 /**
  * @param SiteModels $forum
  * @return boolean
  */
 public function create($forum)
 {
     // very, so much, stupid source code :)
     if ($this->validate()) {
         $user = Yii::$app->getUser()->getIdentity();
         // create post
         $post = new PostModels();
         $post->topic_id = 0;
         $post->message = $this->message;
         $post->save();
         if ($post->save()) {
             // create topic
             $topic = new TopicModels();
             $topic->forum_id = $forum->id;
             $topic->subject = $this->subject;
             $topic->post = $post;
             $topic->save();
             // update post.topic_id
             $post->link('topic', $topic);
             // update forum information
             $forum->updateCounters(['number_topics' => 1]);
             $forum->last_post_created_at = time();
             $forum->last_post_user_id = $post->id;
             $forum->last_post_username = $user->username;
             $forum->save();
             $this->topic = $topic;
             return true;
         }
     }
 }
 /**
  * @param $id
  * @return string
  */
 public function actionView($id)
 {
     /* @var SiteModels $forum */
     $forum = SiteModels::findOne(['id' => $id]);
     $query = TopicModels::find()->where(['forum_id' => $id])->orderBy(['sticked' => SORT_DESC])->addOrderBy(['last_post_created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => Yii::$app->config->get('display_topics_count')]]);
     $topics = $dataProvider->getModels();
     return $this->render('view', ['dataProvider' => $dataProvider, 'forum' => $forum, 'topics' => $topics]);
 }
Пример #3
0
 /**
  * @return ActiveQuery
  */
 public function getForum()
 {
     return $this->hasOne(SiteModels::className(), ['id' => 'forum_id']);
 }
 /**
  * @return ActiveQuery
  */
 public function getForums()
 {
     return $this->hasMany(SiteModels::className(), ['category_id' => 'id'])->inverseOf('category');
 }