| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Models; |
| 4 |
|
| 5 |
use FluentSupport\App\Services\Helper; |
| 6 |
|
| 7 |
class Attachment extends Model |
| 8 |
{ |
| 9 |
protected $table = 'fs_attachments'; |
| 10 |
|
| 11 |
protected $hidden = ['full_url', 'file_path']; |
| 12 |
|
| 13 |
protected $appends = ['secureUrl']; |
| 14 |
|
| 15 |
/** |
| 16 |
* The attributes that are mass assignable. |
| 17 |
* |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
protected $fillable = [ |
| 21 |
'ticket_id', |
| 22 |
'person_id', |
| 23 |
'conversation_id', |
| 24 |
'file_type', |
| 25 |
'file_path', |
| 26 |
'full_url', |
| 27 |
'title', |
| 28 |
'driver', |
| 29 |
'file_size', |
| 30 |
'status', |
| 31 |
'settings' |
| 32 |
]; |
| 33 |
|
| 34 |
public static function boot() |
| 35 |
{ |
| 36 |
parent::boot(); |
| 37 |
|
| 38 |
static::creating(function ($model) { |
| 39 |
$uid = wp_generate_uuid4(); |
| 40 |
$model->file_hash = md5($uid . wp_rand(0, 1000)); |
| 41 |
}); |
| 42 |
} |
| 43 |
|
| 44 |
public function setSettingsAttribute($settings) |
| 45 |
{ |
| 46 |
$this->attributes['settings'] = \maybe_serialize($settings); |
| 47 |
} |
| 48 |
|
| 49 |
public function getSettingsAttribute($settings) |
| 50 |
{ |
| 51 |
return Helper::safeUnserialize($settings); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Accessor to get dynamic full_name attribute |
| 56 |
* @return string |
| 57 |
*/ |
| 58 |
public function getSecureUrlAttribute() |
| 59 |
{ |
| 60 |
return add_query_arg([ |
| 61 |
'fst_file' => $this->file_hash, |
| 62 |
'secure_sign' => md5($this->id . date('YmdH')) |
| 63 |
], site_url('/index.php')); |
| 64 |
} |
| 65 |
} |
| 66 |
|