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