/** * @return void */ public function resaveTags() { // delete all tag relations $this->deleteTags(); // save tags and tag relations foreach ($this->tags as $tag) { // try to receive tag from db $model = Tag::model()->name($tag->name)->userId(Yii::app()->user->id)->find(); if (!is_object($model)) { $model = $tag; } // save tag $model->name = $tag->name; $model->save(); // save relation $relation = new EntryHasTag(); $relation->entryId = $this->id; $relation->tagId = $model->id; $relation->save(); } }
/** * @return void */ public function resaveTags() { // delete all tag relations $this->deleteTags(); // save tags and tag relations foreach ($this->tags as $tag) { /* @var WebUser $webUser */ /** @noinspection PhpUndefinedFieldInspection */ $webUser = Yii::app()->user; // try to receive tag from db $model = Tag::model()->name($tag->name)->userId($webUser->id)->find(); if (!is_object($model)) { $model = $tag; } // save tag $model->name = $tag->name; $model->save(); // save relation $relation = new EntryHasTag(); $relation->entryId = $this->id; $relation->tagId = $model->id; $relation->save(); } }