public static function addTags($tags) { if (count($tags) > 0) { $inTags = preg_replace('/(\\S+)/i', '\'\\1\'', $tags); $sql = "UPDATE {{%tag}} SET frequency=frequency+1 WHERE name IN (" . join(",", $inTags) . ' ) '; Yii::$app->db->createCommand($sql)->execute(); foreach ($tags as $name) { $model = static::find()->where('name=:name', array(':name' => $name))->one(); if ($model === null) { $tag = new Tag(); $tag->name = $name; $tag->frequency = 1; $tag->save(); } } } }
/** * This is invoked after the record is deleted. */ public function afterDelete() { if (parent::beforeDelete()) { Comment::deleteAll('comment_id=' . $this->id . ' AND comment_table="' . self::MODULE_BLOG . '"'); Tag::updateFrequency($this->tags, ''); } else { return false; } }