From 336ee2e9f032a5f0cc5978b81a09263eda459d88 Mon Sep 17 00:00:00 2001 From: iv Date: Wed, 26 Mar 2025 00:08:00 +0300 Subject: [PATCH] feat: add AccountThreshold model --- models/AccountThreshold.php | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 models/AccountThreshold.php diff --git a/models/AccountThreshold.php b/models/AccountThreshold.php new file mode 100644 index 0000000..daa8251 --- /dev/null +++ b/models/AccountThreshold.php @@ -0,0 +1,47 @@ + 0], + [['max_notifications', 'cooldown_period'], 'integer', 'min' => 0], + [['last_notification_at'], 'safe'], + [['account_id'], 'exist', 'targetClass' => Account::class, 'targetAttribute' => 'id'], + [['last_notification_at'], 'date', 'format' => 'php:Y-m-d H:i:s'], + ]; + } + + public static function tableName() + { + return 'account_thresholds'; + } + + public function getAccount() + { + return $this->hasOne(Account::class, ['id' => 'account_id']); + } + + public function getNotifications() + { + return $this->hasMany(Notification::class, ['threshold_id' => 'id']); + } + + public function beforeSave($insert) + { + if (parent::beforeSave($insert)) { + if ($insert) { + $this->last_notification_at = null; + } + return true; + } + return false; + } +} \ No newline at end of file