/** * return tag's model * @param int $id * @return Tags * @throws NotFoundHttpException */ public function getTag($id) { if (($model = Tags::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested post does not exist'); } }
/** * @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; }
/** * Finds the Tags model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tags the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tags::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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]); } } } }
/** * * @param integer $entityId Entity Id * @param integer $entityType Entity Type Id * @param string $tag Media tag */ public function removeAsset($entityId, $entityType, $tag) { $tag = Tags::findOne(['name' => $tag]); if ($tag) { \yii::trace('delete Media Tags Ids:' . $tag->Id); Tagmap::deleteAll(['entityId' => $entityId, 'entityType' => $entityType, 'tagId' => $tag->Id]); Tagassetmap::deleteAll(['tagId' => $tag->Id]); } }