本文整理汇总了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);
}