示例#1
0
 public static function fillTags($content, $id_news)
 {
     if ($tagList = KeywordDetector::detect($content)) {
         foreach ($tagList as $tagName) {
             $tagName = NewsParserComponent::replace4byte($tagName);
             $tag = Tags::findOne(['name' => $tagName]);
             if (!$tag) {
                 $tag = new Tags();
                 $tag->name = $tagName;
                 $tag->cnt = 0;
                 $tag->save();
             }
             $nht = new NewsHasTags();
             $nht->news_id = $id_news;
             $nht->tag_id = $tag->id;
             if ($nht->save()) {
                 $tag->updateCounters(['cnt' => 1]);
             }
         }
     }
 }
示例#2
0
文件: Tags.php 项目: iryska/nagginua
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNewsHasTags()
 {
     return $this->hasMany(NewsHasTags::className(), ['tag_id' => 'id']);
 }