1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model as EloquentModel; |
6
|
|
|
|
7
|
|
|
class Preference extends EloquentModel |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* [$fillable description]. |
11
|
|
|
* |
12
|
|
|
* @var [type] |
13
|
|
|
*/ |
14
|
|
|
protected $fillable = ['key', 'value', 'type']; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* [getDefault description]. |
18
|
|
|
* |
19
|
|
|
* @param \Timegridio\Concierge\Traits\Preferenceable $model [description] |
|
|
|
|
20
|
|
|
* @param [type] $key [description] |
|
|
|
|
21
|
|
|
* |
22
|
|
|
* @return [type] [description] |
|
|
|
|
23
|
|
|
*/ |
24
|
1 |
|
public static function getDefault($model, $key) |
25
|
|
|
{ |
26
|
1 |
|
$class = get_class($model); |
27
|
1 |
|
$value = config("preferences.{$class}.{$key}.value"); |
28
|
1 |
|
$type = config("preferences.{$class}.{$key}.type"); |
29
|
|
|
|
30
|
1 |
|
return new self([ |
31
|
1 |
|
'key' => $key, |
32
|
1 |
|
'value' => $value, |
33
|
1 |
|
'type' => $type, |
34
|
1 |
|
'preferenceable_type' => $class, |
35
|
1 |
|
'preferenceable_id' => $model, |
36
|
1 |
|
]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* [question description]. |
41
|
|
|
* |
42
|
|
|
* @return [type] [description] |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function question() |
45
|
|
|
{ |
46
|
|
|
return trans("preferences.{$this->preferenceable_type}.question.{$this->key}"); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* [help description]. |
51
|
|
|
* |
52
|
|
|
* @return [type] [description] |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
public function help() |
55
|
|
|
{ |
56
|
|
|
return trans("preferences.{$this->preferenceable_type}.help.{$this->key}"); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* [scopeForKey description]. |
61
|
|
|
* |
62
|
|
|
* @param [type] $query [description] |
|
|
|
|
63
|
|
|
* @param [type] $key [description] |
|
|
|
|
64
|
|
|
* |
65
|
|
|
* @return [type] [description] |
|
|
|
|
66
|
|
|
*/ |
67
|
7 |
|
public function scopeForKey($query, $key) |
68
|
|
|
{ |
69
|
7 |
|
return $query->where('key', $key); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Value getter. |
74
|
|
|
* |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
7 |
|
public function value() |
78
|
|
|
{ |
79
|
7 |
|
return $this->value; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Type getter. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
7 |
|
public function type() |
88
|
|
|
{ |
89
|
7 |
|
return $this->type; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|