|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Yoeunes\Rateable\Services\Raty; |
|
4
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
5
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation; |
|
6
|
|
|
|
|
7
|
|
|
if (! function_exists('date_transformer')) { |
|
8
|
|
|
function date_transformer($value) |
|
9
|
|
|
{ |
|
10
|
|
|
$transformers = collect(config('rateable.date-transformers')); |
|
11
|
|
|
|
|
12
|
|
|
if ($transformers->isEmpty() || ! $transformers->has((string) $value)) { |
|
13
|
|
|
return $value; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
return $transformers->get($value); |
|
17
|
|
|
} |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
if (! function_exists('morph_type')) { |
|
21
|
|
|
function morph_type($rateable) |
|
22
|
|
|
{ |
|
23
|
|
|
if ($rateable instanceof Model) { |
|
24
|
|
|
$rateable = get_class($rateable); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return in_array($rateable, Relation::morphMap()) ? array_search($rateable, Relation::morphMap()) : $rateable; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (! function_exists('raty_js')) { |
|
32
|
|
|
function raty_js($version = null, $src = null) |
|
33
|
|
|
{ |
|
34
|
|
|
if (null === $version) { |
|
35
|
|
|
$version = config('rateable.raty.version'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (null === $src) { |
|
39
|
|
|
$src = 'https://cdnjs.cloudflare.com/ajax/libs/raty/'.$version.'/jquery.raty.min.js'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return '<script type="text/javascript" src="'.$src.'"></script>'; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (! function_exists('raty_css')) { |
|
47
|
|
|
function raty_css($version = null, $href = null) |
|
48
|
|
|
{ |
|
49
|
|
|
if (null === $version) { |
|
50
|
|
|
$version = config('rateable.raty.version'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (null === $href) { |
|
54
|
|
|
$href = 'https://cdnjs.cloudflare.com/ajax/libs/raty/'.$version.'/jquery.raty.min.css'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return '<link rel="stylesheet" type="text/css" href="'.$href.'">'; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (! function_exists('jquery')) { |
|
62
|
|
|
function jquery($version = '3.3.1', $src = null) |
|
63
|
|
|
{ |
|
64
|
|
|
if (null === $src) { |
|
65
|
|
|
$src = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/'.$version.'/jquery.min.js'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return '<script type="text/javascript" src="'.$src.'"></script>'; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (! function_exists('raty')) { |
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $element |
|
75
|
|
|
* |
|
76
|
|
|
* @return Raty |
|
77
|
|
|
*/ |
|
78
|
|
|
function raty($element = '#raty') |
|
79
|
|
|
{ |
|
80
|
|
|
return app('raty')->element($element); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|