2015-02-05 21:52:16 -06:00
|
|
|
<?php namespace FireflyIII\Models;
|
|
|
|
|
2016-01-01 14:49:27 -06:00
|
|
|
use Carbon\Carbon;
|
2015-05-23 01:46:46 -05:00
|
|
|
use Crypt;
|
2016-01-01 14:49:27 -06:00
|
|
|
use FireflyIII\User;
|
2015-02-05 21:52:16 -06:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2016-01-01 14:49:27 -06:00
|
|
|
* FireflyIII\Models\Preference
|
2015-02-11 00:35:10 -06:00
|
|
|
*
|
2016-01-01 14:49:27 -06:00
|
|
|
* @property integer $id
|
|
|
|
* @property Carbon $created_at
|
|
|
|
* @property Carbon $updated_at
|
|
|
|
* @property integer $user_id
|
|
|
|
* @property string $name
|
|
|
|
* @property string $name_encrypted
|
|
|
|
* @property string $data
|
|
|
|
* @property string $data_encrypted
|
|
|
|
* @property-read User $user
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2015-02-05 22:04:06 -06:00
|
|
|
class Preference extends Model
|
|
|
|
{
|
2015-02-05 21:52:16 -06:00
|
|
|
|
2015-02-07 06:15:40 -06:00
|
|
|
protected $fillable = ['user_id', 'data', 'name'];
|
2015-05-23 10:11:16 -05:00
|
|
|
protected $hidden = ['data_encrypted', 'name_encrypted'];
|
2015-02-07 06:15:40 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-02-05 22:14:27 -06:00
|
|
|
public function getDataAttribute($value)
|
|
|
|
{
|
2015-05-23 01:46:46 -05:00
|
|
|
if (is_null($this->data_encrypted)) {
|
|
|
|
return json_decode($value);
|
|
|
|
}
|
|
|
|
$data = Crypt::decrypt($this->data_encrypted);
|
|
|
|
|
|
|
|
return json_decode($data);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-02-07 06:15:40 -06:00
|
|
|
public function getDates()
|
|
|
|
{
|
|
|
|
return ['created_at', 'updated_at'];
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
2015-02-05 22:14:27 -06:00
|
|
|
public function setDataAttribute($value)
|
|
|
|
{
|
2015-05-24 08:13:07 -05:00
|
|
|
$this->attributes['data'] = '';
|
2015-05-23 01:46:46 -05:00
|
|
|
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-02-05 22:14:27 -06:00
|
|
|
public function user()
|
|
|
|
{
|
2015-02-05 22:35:00 -06:00
|
|
|
return $this->belongsTo('FireflyIII\User');
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
2015-02-05 21:52:16 -06:00
|
|
|
|
|
|
|
}
|