forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetting.php
More file actions
156 lines (136 loc) · 3.66 KB
/
Setting.php
File metadata and controls
156 lines (136 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace ProcessMaker\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Validation\Rule;
use ProcessMaker\Traits\SerializeToIso8601;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
/**
* Class Settings
*
* @package ProcessMaker\Models
*
* @property string id
* @property string key
* @property array config
* @property Carbon $updated_at
* @property Carbon $created_at
*
* @OA\Schema(
* schema="settingsEditable",
* @OA\Property(property="id", type="string", format="id"),
* @OA\Property(property="key", type="string"),
* @OA\Property(property="config", type="string"),
* ),
* @OA\Schema(
* schema="settings",
* allOf={@OA\Schema(ref="#/components/schemas/settingsEditable")},
* @OA\Property(property="created_at", type="string", format="date-time"),
* @OA\Property(property="updated_at", type="string", format="date-time"),
* )
*
*/
class Setting extends Model implements HasMedia
{
use SerializeToIso8601;
use HasMediaTrait;
protected $connection = 'processmaker';
//Disk
public const DISK_CSS = 'settings';
//collection media library
public const COLLECTION_CSS_LOGIN = 'login';
public const COLLECTION_CSS_LOGO = 'logo';
public const COLLECTION_CSS_ICON = 'icon';
protected $casts = [
'config' => 'array',
];
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [
'id',
'created_at',
'updated_at',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'key',
'config'
];
/**
* Validation rules
*
* @param $existing
*
* @return array
*/
public static function rules($existing = null)
{
$unique = Rule::unique('settings')->ignore($existing);
return [
'key' => ['required', $unique],
'config' => 'required',
];
}
/**
* Get setting by key
*
* @param $key
*
* @return null|Setting
*/
public static function byKey($key)
{
return self::where('key', $key)->first();
}
public static function getLogin()
{
//default login
$url = asset(env('LOGIN_LOGO_PATH', '/img/processmaker_login.png'));
//custom login
$setting = self::byKey('css-override');
if ($setting) {
$mediaFile = $setting->getMedia(self::COLLECTION_CSS_LOGIN);
foreach ($mediaFile as $media) {
$url = $media->getFullUrl();
}
}
return $url . '?id=' . bin2hex(random_bytes(16));
}
public static function getLogo()
{
//default logo
$url = asset(env('MAIN_LOGO_PATH', '/img/processmaker_logo.png'));
//custom logo
$setting = self::byKey('css-override');
if ($setting) {
$mediaFile = $setting->getMedia(self::COLLECTION_CSS_LOGO);
foreach ($mediaFile as $media) {
$url = $media->getFullUrl();
}
}
return $url;
}
public static function getIcon()
{
//default icon
$url = asset(env('ICON_PATH_PATH', '/img/processmaker_icon.png'));
//custom icon
$setting = self::byKey('css-override');
if ($setting) {
$mediaFile = $setting->getMedia(self::COLLECTION_CSS_ICON);
foreach ($mediaFile as $media) {
$url = $media->getFullUrl();
}
}
return $url . '?id=' . bin2hex(random_bytes(16));
}
}