コード例 #1
0
ファイル: Tag.php プロジェクト: frenzelgmbh/sblog
 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();
             }
         }
     }
 }
コード例 #2
0
ファイル: Post.php プロジェクト: frenzelgmbh/sblog
 /**
  * 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;
     }
 }