| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\App\Models; |
| 4 |
|
| 5 |
use FluentBoards\App\Services\Constant; |
| 6 |
|
| 7 |
class Activity extends Model |
| 8 |
{ |
| 9 |
protected $table = 'fbs_activities'; |
| 10 |
|
| 11 |
protected $guarded = ['id']; |
| 12 |
|
| 13 |
protected $fillable = [ |
| 14 |
'object_id', |
| 15 |
'object_type', |
| 16 |
'action', |
| 17 |
'column', |
| 18 |
'old_value', |
| 19 |
'new_value', |
| 20 |
'description', |
| 21 |
'settings', |
| 22 |
'created_by' |
| 23 |
]; |
| 24 |
|
| 25 |
public static function boot() |
| 26 |
{ |
| 27 |
parent::boot(); |
| 28 |
static::creating(function ($model) { |
| 29 |
$model->created_by = $model->created_by ?: get_current_user_id(); |
| 30 |
$model->created_at = current_time('mysql'); |
| 31 |
$model->updated_at = current_time('mysql'); |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
public function setSettingsAttribute($settings) |
| 36 |
{ |
| 37 |
$this->attributes['settings'] = \maybe_serialize($settings); |
| 38 |
} |
| 39 |
|
| 40 |
public function getSettingsAttribute($settings) |
| 41 |
{ |
| 42 |
return \maybe_unserialize($settings); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* One2One: Activity belongs to one Task |
| 47 |
* @return \FluentBoards\Framework\Database\Orm\Relations\BelongsTo |
| 48 |
*/ |
| 49 |
public function board() |
| 50 |
{ |
| 51 |
return $this->belongsTo(Board::class, 'object_id', 'id'); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* One2One: Activity belongs to one Task |
| 56 |
* @return \FluentBoards\Framework\Database\Orm\Relations\BelongsTo |
| 57 |
*/ |
| 58 |
public function task() |
| 59 |
{ |
| 60 |
return $this->belongsTo(Task::class, 'object_id', 'id'); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* One2One: Activity belongs to one User |
| 65 |
* @return \FluentBoards\Framework\Database\Orm\Relations\BelongsTo |
| 66 |
*/ |
| 67 |
public function user() |
| 68 |
{ |
| 69 |
return $this->belongsTo(User::class, 'created_by', 'ID'); |
| 70 |
} |
| 71 |
|
| 72 |
public function scopeType($query, $type) |
| 73 |
{ |
| 74 |
return $query->where('object_type', $type); |
| 75 |
} |
| 76 |
} |
| 77 |
|