2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* Preference.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
2016-05-20 08:57:45 +02:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Models;
|
2015-02-06 04:52:16 +01:00
|
|
|
|
2015-05-23 08:46:46 +02:00
|
|
|
use Crypt;
|
2015-02-06 04:52:16 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
2016-01-01 21:49:27 +01:00
|
|
|
* FireflyIII\Models\Preference
|
2015-02-11 07:35:10 +01:00
|
|
|
*
|
2016-01-28 22:06:16 +01:00
|
|
|
* @property integer $id
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property integer $user_id
|
|
|
|
* @property string $name
|
|
|
|
* @property string $name_encrypted
|
|
|
|
* @property string $data
|
|
|
|
* @property string $data_encrypted
|
|
|
|
* @property-read \FireflyIII\User $user
|
2016-03-12 07:36:23 +01:00
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereNameEncrypted($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereData($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereDataEncrypted($value)
|
|
|
|
* @mixin \Eloquent
|
2015-02-11 07:35:10 +01:00
|
|
|
*/
|
2015-02-06 05:04:06 +01:00
|
|
|
class Preference extends Model
|
|
|
|
{
|
2015-02-06 04:52:16 +01:00
|
|
|
|
2016-01-28 22:06:16 +01:00
|
|
|
protected $dates = ['created_at', 'updated_at'];
|
2015-02-07 13:15:40 +01:00
|
|
|
protected $fillable = ['user_id', 'data', 'name'];
|
2015-05-23 17:11:16 +02:00
|
|
|
protected $hidden = ['data_encrypted', 'name_encrypted'];
|
2016-01-15 23:12:52 +01:00
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-02-06 05:14:27 +01:00
|
|
|
public function getDataAttribute($value)
|
|
|
|
{
|
2015-05-23 08:46:46 +02:00
|
|
|
if (is_null($this->data_encrypted)) {
|
|
|
|
return json_decode($value);
|
|
|
|
}
|
|
|
|
$data = Crypt::decrypt($this->data_encrypted);
|
|
|
|
|
|
|
|
return json_decode($data);
|
2015-02-06 05:14:27 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
2015-02-06 05:14:27 +01:00
|
|
|
public function setDataAttribute($value)
|
|
|
|
{
|
2015-05-24 15:13:07 +02:00
|
|
|
$this->attributes['data'] = '';
|
2015-05-23 08:46:46 +02:00
|
|
|
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
|
|
|
|
}
|
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-02-06 05:14:27 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2015-02-06 05:35:00 +01:00
|
|
|
return $this->belongsTo('FireflyIII\User');
|
2015-02-06 05:14:27 +01:00
|
|
|
}
|
2015-02-06 04:52:16 +01:00
|
|
|
|
|
|
|
}
|