Пример #1
0
 /**
  * @return string
  */
 public function actionList()
 {
     $name = Yii::$app->getRequest()->get('name');
     $tagModel = '';
     if (isset($name)) {
         /** @var Tag $tagModel */
         $tagModel = Tag::findOne(['name' => $name]);
         if (!$tagModel) {
             throw new NotFoundHttpException();
         }
     }
     $query = Topic::find()->select('*')->from('topic t')->with('tags', 'firstPostUser', 'lastPostUser');
     if (isset($name)) {
         $query->innerJoin('tag_topic_assignment tta', 'tta.topic_id = t.id')->where(['tta.tag_name' => $name]);
     }
     $sort_by = Yii::$app->getRequest()->get('sort_by');
     if (!$sort_by || $sort_by == 'new') {
         $query->orderBy(['t.last_post_created_at' => SORT_DESC]);
     } elseif ($sort_by == 'unanwser') {
         $query->andWhere(['t.number_posts' => 0])->orderBy(['t.last_post_created_at' => SORT_DESC]);
     } elseif ($sort_by == 'own') {
         $id = Yii::$app->getUser()->getId();
         $query->andWhere(['t.first_post_user_id' => $id])->orderBy(['t.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('list', ['dataProvider' => $dataProvider, 'tagModel' => $tagModel, 'topics' => $topics]);
 }
Пример #2
0
 /**
  * @return boolean
  */
 public function create()
 {
     // very, so much, stupid source code :)
     if ($this->validate()) {
         $user = Yii::$app->getUser()->getIdentity();
         // create post
         $post = new Post();
         $post->topic_id = 0;
         $post->message = $this->message;
         $post->save();
         if ($post->save()) {
             // create topic
             $topic = new Topic();
             $topic->subject = $this->subject;
             $topic->post = $post;
             $topic->save();
             // update post.topic_id
             $post->link('topic', $topic);
             $tagNames = explode(',', $this->tags);
             foreach ($tagNames as $tagName) {
                 /** @var Tag $tagModel */
                 $tagModel = Tag::findOne($tagName);
                 $topic->link('tags', $tagModel);
             }
             $this->topic = $topic;
             return true;
         }
     }
     return false;
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $name = Yii::$app->getRequest()->get('name');
     if ($name !== '') {
         $tagModel = Tag::findOne(['name' => $name]);
         echo $this->render('sidebar', ['tagModel' => $tagModel]);
     } else {
         echo $this->render('sidebar');
     }
 }
Пример #4
0
 /**
  * @return string
  */
 public function actionTag()
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $query = Yii::$app->getRequest()->get('query');
         if ($query != null) {
             $rows = Tag::find()->where(['like', 'name', $query])->limit(5)->asArray()->all();
             $tags = array_unique(ArrayHelper::getColumn($rows, 'name'));
             $tags = array_values($tags);
             return $tags;
         }
     }
     throw new NotFoundHttpException();
 }
Пример #5
0
 /**
  * @return ActiveQuery
  */
 public function getTags()
 {
     return $this->hasMany(Tag::className(), ['name' => 'tag_name'])->viaTable('tag_topic_assignment', ['topic_id' => 'id']);
 }
Пример #6
0
        <p>топиков отмеченны тегом</p>
        <a class="tag-url" href="<?php 
    echo Url::toRoute(['/topic/default/list', 'name' => $tagModel->name]);
    ?>
"><?php 
    echo Yii::$app->formatter->asText($tagModel->name);
    ?>
</a>
    </div>
    <?php 
}
?>
    <div class="sidebar-module">
        <h4>Список тегов</h4>
        <div class="interesting-tags">
            <?php 
foreach (Tag::getNamesList() as $name) {
    ?>
                <a class="tag-url" href="<?php 
    echo Url::toRoute(['/topic/default/list', 'name' => $name]);
    ?>
"><?php 
    echo $name;
    ?>
</a>
            <?php 
}
?>
        </div>
    </div>
</div>