1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Uccello\Core\Models\Domain; |
4
|
|
|
use Uccello\Core\Models\Module; |
5
|
|
|
|
6
|
|
|
if (!function_exists('uccello')) { |
7
|
|
|
/** |
8
|
|
|
* Return an instance of Uccello\Core\Helpers\Uccello |
9
|
|
|
* |
10
|
|
|
* @return void |
11
|
|
|
*/ |
12
|
|
|
function uccello() |
13
|
|
|
{ |
14
|
|
|
return app('uccello'); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if (!function_exists('uctrans')) { |
19
|
|
|
/** |
20
|
|
|
* Retrieve prefix and translate the given message. If the default translation does not exist try to find a fallback one. |
21
|
|
|
* |
22
|
|
|
* @param string $key |
23
|
|
|
* @param Module|null $module |
24
|
|
|
* @param array $replace |
25
|
|
|
* @param string $locale |
26
|
|
|
* @return \Illuminate\Contracts\Translation\Translator|string|array|null |
27
|
|
|
* |
28
|
|
|
* @see Uccello\Core\Helpers\Uccello |
29
|
|
|
*/ |
30
|
|
|
function uctrans($key = null, ? Module $module = null, $replace = [ ], $locale = null) |
31
|
|
|
{ |
32
|
|
|
return app('uccello')->trans($key, $module, $replace, $locale); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (!function_exists('ucdomain')) { |
37
|
|
|
/** |
38
|
|
|
* Get a module instance by name or id |
39
|
|
|
* |
40
|
|
|
* @param string|int $slugOrId |
41
|
|
|
* @return Domain|null |
42
|
|
|
*/ |
43
|
|
|
function ucdomain($slugOrId): ?Domain |
44
|
|
|
{ |
45
|
|
|
return app('uccello')->getDomain($slugOrId); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!function_exists('ucmodule')) { |
50
|
|
|
/** |
51
|
|
|
* Get a module instance by name or id |
52
|
|
|
* |
53
|
|
|
* @param string|int $name |
54
|
|
|
* @return Module|null |
55
|
|
|
*/ |
56
|
|
|
function ucmodule($nameOrId): ?Module |
57
|
|
|
{ |
58
|
|
|
return app('uccello')->getModule($nameOrId); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!function_exists('ucroute')) { |
63
|
|
|
/** |
64
|
|
|
* Makes route automaticaly and add domain and module parameter. |
65
|
|
|
* |
66
|
|
|
* @param array|string $name |
67
|
|
|
* @param Domain|string|null $domain |
68
|
|
|
* @param Module|string|null $module |
69
|
|
|
* @param mixed $parameters |
70
|
|
|
* @param boolean $absolute |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
function ucroute($name, $domain = null, $module = null, $parameters = [ ], $absolute = true) : string |
74
|
|
|
{ |
75
|
|
|
return app('uccello')->route($name, $domain, $module, $parameters, $absolute); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (!function_exists('uclog')) { |
80
|
|
|
/** |
81
|
|
|
* Use logging |
82
|
|
|
* |
83
|
|
|
* @param mixed $message |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
function uclog($message, $type='info') |
87
|
|
|
{ |
88
|
|
|
Log::$type($message); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (!function_exists('uitype')) { |
93
|
|
|
/** |
94
|
|
|
* Get an uitype instance by name or id |
95
|
|
|
* |
96
|
|
|
* @param string|int $nameOrId |
97
|
|
|
* @return Uitype|null |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
function uitype($nameOrId) |
100
|
|
|
{ |
101
|
|
|
return app('uccello')->getUitype($nameOrId); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if (!function_exists('displaytype')) { |
106
|
|
|
/** |
107
|
|
|
* Get a display type instance by name or id |
108
|
|
|
* |
109
|
|
|
* @param string|int $nameOrId |
110
|
|
|
* @return Displaytype|null |
|
|
|
|
111
|
|
|
*/ |
112
|
|
|
function displaytype($nameOrId) |
113
|
|
|
{ |
114
|
|
|
return app('uccello')->getDisplaytype($nameOrId); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (!function_exists('capability')) { |
119
|
|
|
/** |
120
|
|
|
* Get a capability instance by name or id |
121
|
|
|
* |
122
|
|
|
* @param string|int $nameOrId |
123
|
|
|
* @return Capabillity|null |
|
|
|
|
124
|
|
|
*/ |
125
|
|
|
function capability($nameOrId) |
126
|
|
|
{ |
127
|
|
|
return app('uccello')->getCapability($nameOrId); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (!function_exists('ucasset')) { |
132
|
|
|
/** |
133
|
|
|
* Get complete path to asset |
134
|
|
|
* |
135
|
|
|
* @param string $path |
136
|
|
|
* @param string $package |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
function ucasset($path, $package = 'uccello/uccello') |
140
|
|
|
{ |
141
|
|
|
return asset("vendor/$package/$path"); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if (!function_exists('ucattribute')) { |
146
|
|
|
/** |
147
|
|
|
* Returns a record attribute value. |
148
|
|
|
* It is able to follow a complex path according to models definition (e.g. 'domain.parent.name') |
149
|
|
|
* |
150
|
|
|
* @param Object $record |
151
|
|
|
* @param string $attribute |
152
|
|
|
* @return string|Object|Array|null |
153
|
|
|
*/ |
154
|
|
|
function ucattribute($record, $attribute) |
155
|
|
|
{ |
156
|
|
|
return app('uccello')->getRecordAttribute($record, $attribute); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (!function_exists('ucnotify')) { |
161
|
|
|
/** |
162
|
|
|
* Uses flash session to display a notification. |
163
|
|
|
* |
164
|
|
|
* @param string $message |
165
|
|
|
* @param string $type |
166
|
|
|
* @return void |
167
|
|
|
*/ |
168
|
|
|
function ucnotify($message, $type = 'info') { |
169
|
|
|
session()->flash('notification-'.$type, $message); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (!function_exists('ucrecord')) { |
174
|
|
|
/** |
175
|
|
|
* Retrieves a record by its id or uuid |
176
|
|
|
* |
177
|
|
|
* @param int|string $idOrUuid |
178
|
|
|
* @param string $className |
179
|
|
|
* @return mixed |
180
|
|
|
*/ |
181
|
|
|
function ucrecord($idOrUuid, $className = null) |
182
|
|
|
{ |
183
|
|
|
return app('uccello')->getRecordByIdOrUuid($idOrUuid, $className); |
|
|
|
|
184
|
|
|
} |
185
|
|
|
} |