Files
firefly-iii/app/Models/Preference.php

82 lines
1.6 KiB
PHP
Raw Normal View History

2015-02-06 04:52:16 +01:00
<?php namespace FireflyIII\Models;
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
/**
* Class Preference
*
* @codeCoverageIgnore
2015-02-11 07:35:10 +01:00
* @package FireflyIII\Models
*/
2015-02-06 05:04:06 +01:00
class Preference extends Model
{
2015-02-06 04:52:16 +01:00
2015-02-07 13:15:40 +01:00
protected $fillable = ['user_id', 'data', 'name'];
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
/**
* @return array
*/
2015-02-07 13:15:40 +01:00
public function getDates()
{
return ['created_at', 'updated_at'];
}
2015-05-23 08:46:46 +02:00
/**
* @param $value
*
* @return float|int
*/
public function getNameAttribute($value)
{
if (is_null($this->name_encrypted)) {
return $value;
}
$value = Crypt::decrypt($this->name_encrypted);
return $value;
}
2015-02-11 07:35:10 +01:00
/**
* @param $value
*/
2015-02-06 05:14:27 +01:00
public function setDataAttribute($value)
{
2015-05-23 08:46:46 +02:00
$this->attributes['data'] = '';//json_encode($value);
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
}
/**
* @param $value
*/
public function setNameAttribute($value)
{
$this->attributes['name_encrypted'] = Crypt::encrypt($value);
$this->attributes['name'] = $value;
2015-02-06 05:14:27 +01:00
}
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
}