This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/app/models/Ban.php
2013-10-26 18:06:58 -05:00

49 lines
1.2 KiB
PHP
Executable File

<?php
class Ban extends Rails\ActiveRecord\Base
{
protected $duration;
protected function callbacks()
{
return [
'before_create' => ['_save_level'],
'after_create' => ['_save_to_record', '_update_level'],
'after_destroy' => ['_restore_level']
];
}
protected function _restore_level()
{
User::find($this->user_id)->updateAttribute('level', $this->old_level);
}
protected function _save_level()
{
$this->old_level = User::find($this->user_id)->level;
}
protected function _update_level()
{
$user = User::find($this->user_id);
$user->level = CONFIG()->user_levels['Blocked'];
$user->save();
}
protected function _save_to_record()
{
UserRecord::create(['user_id' => $this->user_id, 'reported_by' => $this->banned_by, 'is_positive' => false, 'body' => "Blocked: ".$this->reason]);
}
public function setDuration($dur)
{
$seconds = $dur * 60*60*24;
$this->expires_at = date('Y-m-d H:i:s', time() + $seconds);
$this->duration = $dur;
}
public function duration()
{
return $this->duration;
}
}