當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Tag::updateAllCounters方法代碼示例

本文整理匯總了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]);
 }
開發者ID:feijilei,項目名稱:simpleforum,代碼行數:10,代碼來源:TagTopic.php

示例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);
 }
開發者ID:CrystalEller,項目名稱:yii2ebooks,代碼行數:31,代碼來源:Book.php


注:本文中的app\models\Tag::updateAllCounters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。