1 | <?php |
||
2 | |||
3 | namespace Chuckbe\Chuckcms\Controllers; |
||
4 | |||
5 | use Chuckbe\Chuckcms\Chuck\PageBlockRepository; |
||
6 | |||
7 | use Chuckbe\Chuckcms\Models\Page; |
||
8 | use Chuckbe\Chuckcms\Models\PageBlock; |
||
9 | use Chuckbe\Chuckcms\Models\Redirect; |
||
10 | use Chuckbe\Chuckcms\Models\Repeater; |
||
11 | use Chuckbe\Chuckcms\Models\Template; |
||
12 | |||
13 | use Illuminate\Http\Request; |
||
14 | use Illuminate\Foundation\Bus\DispatchesJobs; |
||
15 | use Illuminate\Routing\Controller as BaseController; |
||
16 | use Illuminate\Foundation\Validation\ValidatesRequests; |
||
17 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||
18 | |||
19 | class FrontEndController extends BaseController |
||
20 | { |
||
21 | use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
||
22 | |||
23 | private $page; |
||
24 | private $pageblock; |
||
25 | private $pageBlockRepository; |
||
26 | private $redirect; |
||
27 | private $repeater; |
||
28 | private $template; |
||
29 | /** |
||
30 | * Create a new controller instance. |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function __construct( |
||
35 | Page $page, |
||
36 | PageBlock $pageblock, |
||
37 | PageBlockRepository $pageBlockRepository, |
||
38 | Redirect $redirect, |
||
39 | Repeater $repeater, |
||
40 | Template $template) |
||
41 | { |
||
42 | $this->page = $page; |
||
43 | $this->pageblock = $pageblock; |
||
44 | $this->pageBlockRepository = $pageBlockRepository; |
||
45 | $this->redirect = $redirect; |
||
46 | $this->repeater = $repeater; |
||
47 | $this->template = $template; |
||
48 | } |
||
49 | |||
50 | public function index($slug = null) |
||
51 | { |
||
52 | if($slug == null){ |
||
53 | $page = $this->page->where('isHp', 1)->firstOrFail(); |
||
54 | } elseif($slug !== null){ |
||
55 | |||
56 | $redirect = $this->redirect->where('slug', $slug)->first(); |
||
57 | if($redirect !== null){ |
||
58 | return redirect($redirect->to, $redirect->type); |
||
59 | } |
||
60 | |||
61 | $repeater = $this->repeater->where('url', $slug)->first(); |
||
62 | if($repeater !== null){ |
||
63 | $templateHintpath = explode('::', (string)$repeater->page)[0]; |
||
64 | $template = $this->template->where('active', 1)->where('hintpath', $templateHintpath)->first(); |
||
65 | return view((string)$repeater->page, compact('template', 'repeater')); |
||
66 | } |
||
67 | |||
68 | $page = $this->page->where('slug->'.app()->getLocale(), $slug)->first(); |
||
69 | if($page == null){ |
||
70 | foreach(\LaravelLocalization::getSupportedLocales() as $localeCode => $properties){ |
||
71 | $page = $this->page->where('slug->'.$localeCode, $slug)->first(); |
||
72 | if($page !== null && $localeCode == app()->getLocale()) { |
||
73 | break; |
||
74 | } |
||
75 | |||
76 | if($page !== null && $localeCode !== app()->getLocale()){ |
||
77 | //dd(app()->getLocale()); |
||
78 | app()->setLocale($localeCode); |
||
79 | \LaravelLocalization::setLocale($localeCode); |
||
80 | |||
81 | return redirect($localeCode.'/'.$slug); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if($page == null) { |
||
87 | abort(404); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $ogpageblocks = $this->pageblock->getAllByPageId($page->id); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
92 | $pageblocks = $this->pageBlockRepository->getRenderedByPageBlocks($ogpageblocks); |
||
93 | |||
94 | if($page->page !== null) { |
||
95 | $template = $this->template->where('active', 1)->where('hintpath', explode('::', $page->page)[0])->first(); |
||
96 | |||
97 | return view($page->page, compact('template', 'page', 'pageblocks')); |
||
98 | } |
||
99 | |||
100 | $template = $this->template->where('active', 1)->where('id', $page->template_id)->first(); |
||
101 | |||
102 | return view($template->hintpath . '::templates.' . $template->slug . '.page', compact('template', 'page', 'pageblocks')); |
||
103 | } |
||
104 | } |
||
105 |