1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\Models; |
4
|
|
|
|
5
|
|
|
use A17\Twill\Models\Behaviors\HasFiles; |
6
|
|
|
use A17\Twill\Models\Behaviors\HasMedias; |
7
|
|
|
use A17\Twill\Models\Behaviors\HasPresenter; |
8
|
|
|
use A17\Twill\Models\Behaviors\HasRelated; |
9
|
|
|
use Illuminate\Database\Eloquent\Model as BaseModel; |
10
|
|
|
|
11
|
|
|
class Block extends BaseModel |
12
|
|
|
{ |
13
|
|
|
use HasMedias, HasFiles, HasPresenter, HasRelated; |
|
|
|
|
14
|
|
|
|
15
|
|
|
public $timestamps = false; |
16
|
|
|
|
17
|
|
|
protected $fillable = [ |
18
|
|
|
'blockable_id', |
19
|
|
|
'blockable_type', |
20
|
|
|
'position', |
21
|
|
|
'content', |
22
|
|
|
'type', |
23
|
|
|
'child_key', |
24
|
|
|
'parent_id', |
25
|
|
|
'editor_name', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
protected $casts = [ |
29
|
|
|
'content' => 'array', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
protected $with = ['medias']; |
33
|
|
|
|
34
|
|
|
public function scopeEditor($query, $name = 'default') |
35
|
|
|
{ |
36
|
|
|
return $name === 'default' ? |
37
|
|
|
$query->where('editor_name', $name)->orWhereNull('editor_name') : |
38
|
|
|
$query->where('editor_name', $name); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function blockable() |
42
|
|
|
{ |
43
|
|
|
return $this->morphTo(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function children() |
47
|
|
|
{ |
48
|
|
|
return $this->hasMany('A17\Twill\Models\Block', 'parent_id'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function input($name) |
52
|
|
|
{ |
53
|
|
|
return $this->content[$name] ?? null; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function translatedInput($name, $forceLocale = null) |
57
|
|
|
{ |
58
|
|
|
$value = $this->content[$name] ?? null; |
|
|
|
|
59
|
|
|
|
60
|
|
|
$locale = $forceLocale ?? ( |
61
|
|
|
config('translatable.use_property_fallback', false) && (!array_key_exists(app()->getLocale(), $value ?? [])) |
|
|
|
|
62
|
|
|
? config('translatable.fallback_locale') |
63
|
|
|
: app()->getLocale() |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
return $value[$locale] ?? null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function browserIds($name) |
70
|
|
|
{ |
71
|
|
|
return isset($this->content['browsers']) ? ($this->content['browsers'][$name] ?? []) : []; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function checkbox($name) |
75
|
|
|
{ |
76
|
|
|
return isset($this->content[$name]) && ($this->content[$name][0] ?? $this->content[$name] ?? false); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getPresenterAttribute() |
80
|
|
|
{ |
81
|
|
|
if (($presenter = config('twill.block_editor.block_presenter_path')) != null) { |
82
|
|
|
return $presenter; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getTable() |
89
|
|
|
{ |
90
|
|
|
return config('twill.blocks_table', 'twill_blocks'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|