|
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
|
|
|
* [preferenceable description]. |
|
18
|
|
|
* |
|
19
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
20
|
|
|
*/ |
|
21
|
|
|
public function preferenceable() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->morphTo(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* [__toString description]. |
|
28
|
|
|
* |
|
29
|
|
|
* @return string [description] |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __toString() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->attributes['value']; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* [getDefault description]. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Timegridio\Concierge\Traits\Preferenceable $model [description] |
|
|
|
|
|
|
40
|
|
|
* @param [type] $key [description] |
|
|
|
|
|
|
41
|
|
|
* |
|
42
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
1 |
|
public static function getDefault($model, $key) |
|
45
|
|
|
{ |
|
46
|
1 |
|
$class = get_class($model); |
|
47
|
1 |
|
$value = config("preferences.{$class}.{$key}.value"); |
|
48
|
1 |
|
$type = config("preferences.{$class}.{$key}.type"); |
|
49
|
|
|
|
|
50
|
1 |
|
return new self([ |
|
51
|
1 |
|
'key' => $key, |
|
52
|
1 |
|
'value' => $value, |
|
53
|
1 |
|
'type' => $type, |
|
54
|
1 |
|
'preferenceable_type' => $class, |
|
55
|
1 |
|
'preferenceable_id' => $model, |
|
56
|
1 |
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* [question description]. |
|
61
|
|
|
* |
|
62
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
63
|
|
|
*/ |
|
64
|
|
|
public function question() |
|
65
|
|
|
{ |
|
66
|
|
|
return trans("preferences.{$this->preferenceable_type}.question.{$this->key}"); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* [help description]. |
|
71
|
|
|
* |
|
72
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
73
|
|
|
*/ |
|
74
|
|
|
public function help() |
|
75
|
|
|
{ |
|
76
|
|
|
return trans("preferences.{$this->preferenceable_type}.help.{$this->key}"); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* [scopeForKey description]. |
|
81
|
|
|
* |
|
82
|
|
|
* @param [type] $query [description] |
|
|
|
|
|
|
83
|
|
|
* @param [type] $key [description] |
|
|
|
|
|
|
84
|
|
|
* |
|
85
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function scopeForKey($query, $key) |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $query->where('key', $key); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* [value description]. |
|
94
|
|
|
* |
|
95
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function value() |
|
98
|
|
|
{ |
|
99
|
1 |
|
switch ($this->type) { |
|
|
|
|
|
|
100
|
1 |
|
case 'string': |
|
101
|
|
|
return (string) $this->value; |
|
|
|
|
|
|
102
|
|
|
break; |
|
|
|
|
|
|
103
|
1 |
|
case 'bool': |
|
104
|
|
|
return (bool) $this->value; |
|
|
|
|
|
|
105
|
|
|
break; |
|
|
|
|
|
|
106
|
1 |
|
case 'int': |
|
107
|
|
|
return (int) $this->value; |
|
|
|
|
|
|
108
|
|
|
break; |
|
|
|
|
|
|
109
|
1 |
|
case 'float': |
|
110
|
|
|
return (float) $this->value; |
|
|
|
|
|
|
111
|
|
|
break; |
|
|
|
|
|
|
112
|
1 |
|
case 'json': |
|
113
|
|
|
return json_decode($this->value); |
|
|
|
|
|
|
114
|
|
|
break; |
|
|
|
|
|
|
115
|
1 |
|
case 'array': |
|
116
|
|
|
return unserialize($this->value); |
|
|
|
|
|
|
117
|
|
|
break; |
|
|
|
|
|
|
118
|
1 |
|
default: |
|
119
|
1 |
|
break; |
|
120
|
1 |
|
} |
|
121
|
|
|
|
|
122
|
1 |
|
return $this->value; |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.