Exemplo n.º 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]);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNewsHasTags()
 {
     return $this->hasMany(NewsHasTags::className(), ['tag_id' => 'id']);
 }