1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace KielD01\LaravelMaterialDashboardPro; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use KielD01\LaravelMaterialDashboardPro\Helpers\MenuBuilder; |
10
|
|
|
|
11
|
|
|
class MaterialDashboardPro |
12
|
|
|
{ |
13
|
|
|
private Request $request; |
14
|
|
|
private array $menu = []; |
15
|
|
|
private string $pageTitle = 'Page'; |
16
|
|
|
private $user = null; |
17
|
|
|
|
18
|
|
|
private string $backgroundUrl = 'https://picsum.photos/2880/1920?blur=2'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param Request $request |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Request $request) |
24
|
|
|
{ |
25
|
|
|
$this->request = $request; |
26
|
|
|
$this->setMenu(); |
27
|
|
|
$this->setUser($this->request->user()); |
28
|
|
|
$this->setBackgroundUrl(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getRandomBackgroundUrl(): string |
32
|
|
|
{ |
33
|
|
|
return $this->backgroundUrl; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
private function setMenu(): void |
40
|
|
|
{ |
41
|
|
|
/** @var MenuBuilder $menuBuilder */ |
42
|
|
|
$menuBuilder = resolve(MenuBuilder::class); |
43
|
|
|
$this->menu = $menuBuilder->build(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Model|null $user |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
|
|
private function setUser(?Model $user): static |
51
|
|
|
{ |
52
|
|
|
$this->user = $user; |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setBackgroundUrl(): static |
58
|
|
|
{ |
59
|
|
|
$this->backgroundUrl = config('mdp.core.static.login_image', $this->backgroundUrl); |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function hasUser(string $guard = null) |
65
|
|
|
{ |
66
|
|
|
return $this->request->user($guard) ?? false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getUser() |
70
|
|
|
{ |
71
|
|
|
return $this->user; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getPageTitle(): string |
75
|
|
|
{ |
76
|
|
|
return $this->pageTitle; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setPageTitle(string $pageTitle): static |
80
|
|
|
{ |
81
|
|
|
$this->pageTitle = $pageTitle; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getMenu(): array |
87
|
|
|
{ |
88
|
|
|
return $this->menu; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|