/** * Creates a new Tags model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Tags(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * * @param string $tag Tagname * @return \common\models\Tags */ public static function loadTagmodel($tag, $issystem = false, $runValidation = true) { if (($model = Tags::findOne(['name' => $tag])) !== null) { } else { //$model = new tagTraiagTrail(); $model = new Tags(); $model->name = $tag; if ($issystem) { $model->issystem = 1; } $model->save($runValidation); } return $model; }
/** * @param string $name * @param string $tagGroup * @param string $entity * @param int $entityId * * @return bool */ public static function addTag($name, $tagGroup, $entity, $entityId) { if (!($tag = Tags::findOne(['name' => $name, 'tag_group' => $tagGroup]))) { $tag = new Tags(); $tag->name = $name; $tag->tag_group = $tagGroup; $tag->save(); } if ($tag) { if (!($tagEntity = TagEntity::findOne(['tag_id' => $tag->id, 'entity' => $entity, 'entity_id' => $entityId]))) { $tagEntity = new TagEntity(); $tagEntity->tag_id = $tag->id; $tagEntity->entity = $entity; $tagEntity->entity_id = $entityId; $tagEntity->save(); } if ($tagEntity) { return true; } } return false; }
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]); } } } }