|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Entities; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use Yajra\CMS\Entities\Traits\HasParameters; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @property string name |
|
11
|
|
|
* @property string type |
|
12
|
|
|
* @property string parameters |
|
13
|
|
|
* @property bool enabled |
|
14
|
|
|
* @property string manifest |
|
15
|
|
|
* @property bool protected |
|
16
|
|
|
*/ |
|
17
|
|
|
class Extension extends Model |
|
18
|
|
|
{ |
|
19
|
|
|
use HasParameters; |
|
20
|
|
|
const WIDGET_MENU = 1; |
|
21
|
|
|
const WIDGET_WYSIWYG = 2; |
|
22
|
|
|
const MENU_INTERNAL = 3; |
|
23
|
|
|
const MENU_EXTERNAL = 4; |
|
24
|
|
|
const MENU_ARTICLE = 5; |
|
25
|
|
|
const MENU_CATEGORY_LIST = 6; |
|
26
|
|
|
const MENU_CATEGORY_BLOG = 7; |
|
27
|
|
|
const WIDGET_BREADCRUMB = 8; |
|
28
|
|
|
const WIDGET_BLADE_VIEW = 9; |
|
29
|
|
|
const WIDGET_LOGIN = 10; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $fillable = ['name', 'type', 'enabled', 'parameters']; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get a widget by name. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $name |
|
40
|
|
|
* @return $this |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function widget($name) |
|
43
|
|
|
{ |
|
44
|
|
|
$builder = static::query(); |
|
45
|
|
|
|
|
46
|
|
|
return $builder->where('type', 'widget') |
|
47
|
|
|
->whereRaw('LOWER(name) = ?', [Str::lower($name)]) |
|
48
|
|
|
->first(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get manifest attribute. |
|
53
|
|
|
* |
|
54
|
|
|
* @return object |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getManifestAttribute() |
|
57
|
|
|
{ |
|
58
|
|
|
return json_decode($this->attributes['manifest'], true); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get version. |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getVersionAttribute() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->manifest['version'] ?? '0.0.0'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get description. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getDescriptionAttribute() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->manifest['description'] ?? 'No description'; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|