Esempio n. 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);
         }
     }
 }
Esempio n. 2
0
 public static function addTopicTags($topicId, $tagNames)
 {
     $tags = static::find()->select(['id', 'name'])->where(['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' => $topicId]);
             $tagTopic->save(false);
             //				$tag->updateCounters(['topic_count' => 1]);
             static::updateAll(['updated_at' => time(), 'topic_count' => new Expression('`topic_count` + 1')], ['id' => $tag->id]);
         } else {
             $tag = new static(['name' => $tn, 'topic_count' => 1]);
             $tag->save(false);
             $tagTopic = new TagTopic(['tag_id' => $tag->id, 'topic_id' => $topicId]);
             $tagTopic->save(false);
         }
     }
 }