Example #1
0
 public static function afterTopicInsert($tc)
 {
     $editor = new \app\lib\Editor(['editor' => Yii::$app->params['settings']['editor']]);
     $content = $editor->parse($tc->content);
     $pa = new PhpAnalysis();
     $pa->SetSource($tc->topic->title . strip_tags($content));
     $pa->resultType = 2;
     $pa->differMax = true;
     $pa->StartAnalysis();
     $tagNames = $pa->GetFinallyKeywords(3);
     $tagNames = explode(',', $tagNames);
     $tags = static::find()->select(['id', 'name'])->where(['in', 'name', $tagNames])->indexBy('name')->all();
     foreach ($tagNames as $tn) {
         if (!empty($tags) && !empty($tags[$tn])) {
             $tag = $tags[$tn];
             $tagTopic = new TagTopic(['tag_id' => $tag->id, 'topic_id' => $tc->topic_id]);
             $tagTopic->save(false);
             $tag->updateCounters(['topic_count' => 1]);
         } else {
             $tag = new static(['name' => $tn, 'topic_count' => 1]);
             $tag->save(false);
             $tagTopic = new TagTopic(['tag_id' => $tag->id, 'topic_id' => $tc->topic_id]);
             $tagTopic->save(false);
         }
     }
 }
Example #2
0
 public function actionIndex($name)
 {
     $tag = $this->findModel($name);
     $pages = new Pagination(['totalCount' => $tag['topic_count'], 'pageSize' => intval($this->settings['list_pagesize']), 'pageParam' => 'p']);
     return $this->render('index', ['tag' => $tag, 'topics' => TagTopic::getTopics($tag['id'], $pages), 'pages' => $pages]);
 }
Example #3
0
 public function afterDelete()
 {
     TopicContent::deleteAll(['topic_id' => $this->id]);
     Node::updateCounterInfo('deleteTopic', $this->node_id);
     UserInfo::updateCounterInfo('deleteTopic', $this->user_id);
     $count = Comment::afterTopicDelete($this->id);
     Siteinfo::updateCountersInfo(['topics' => -1, 'comments' => -$count]);
     Favorite::afterTopicDelete($this->id);
     Notice::afterTopicDelete($this->id);
     TagTopic::afterTopicDelete($this->id);
     (new History(['user_id' => $this->user_id, 'action' => History::ACTION_DELETE_TOPIC, 'target' => $this->id]))->save(false);
     return parent::afterDelete();
 }
Example #4
0
 public static function deleteTopicTags($topicId, $tagNames)
 {
     if ($oldTags = static::find(['id'])->where(['name' => $tagNames])->asArray()->all()) {
         $tagIds = ArrayHelper::getColumn($oldTags, 'id');
         TagTopic::deleteAll(['topic_id' => $topicId, 'tag_id' => $tagIds]);
         static::updateAll(['updated_at' => time(), 'topic_count' => new Expression('`topic_count` - 1')], ['and', ['id' => $tagIds], ['>', 'topic_count', 0]]);
     }
 }