本文整理匯總了PHP中app\models\Tag::updateAllCounters方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tag::updateAllCounters方法的具體用法?PHP Tag::updateAllCounters怎麽用?PHP Tag::updateAllCounters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Tag
的用法示例。
在下文中一共展示了Tag::updateAllCounters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: afterTopicDelete
public static function afterTopicDelete($topicId)
{
$tagTopics = static::find()->select(['tag_id'])->where(['topic_id' => $topicId])->asArray()->all();
if (empty($tagTopics)) {
return;
}
$tagIds = ArrayHelper::getColumn($tagTopics, 'tag_id');
Tag::updateAllCounters(['topic_count' => -1], ['and', ['id' => $tagIds], ['>', 'topic_count', 0]]);
static::deleteAll(['topic_id' => $topicId]);
}
示例2: afterSave
public function afterSave($insert, $changedAttributes)
{
if (!$insert) {
Yii::$app->db->createCommand()->delete('author_book', ['bookId' => $this->id])->execute();
Yii::$app->db->createCommand()->delete('book_format', ['bookId' => $this->id])->execute();
Yii::$app->db->createCommand()->delete('book_tag', ['bookId' => $this->id])->execute();
}
if (!empty($this->authors)) {
$authorInsert = [];
foreach ($this->authors as $author) {
array_push($authorInsert, [$author, $this->id]);
}
Yii::$app->db->createCommand()->batchInsert('author_book', ['authorId', 'bookId'], $authorInsert)->execute();
}
if (!empty($this->formats)) {
$formatInsert = [];
foreach ($this->formats as $format) {
array_push($formatInsert, [$format, $this->id]);
}
Yii::$app->db->createCommand()->batchInsert('book_format', ['formatId', 'bookId'], $formatInsert)->execute();
}
if (!empty($this->tags)) {
$tagInsert = [];
foreach ($this->tags as $tag) {
array_push($tagInsert, [$tag, $this->id]);
}
Yii::$app->db->createCommand()->batchInsert('book_tag', ['tagId', 'bookId'], $tagInsert)->execute();
Tag::updateAllCounters(['frequency' => 1], ['id' => array_map('intval', $this->tags)]);
}
parent::afterSave($insert, $changedAttributes);
}