PageBlockController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 145
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A show() 0 7 1
A moveDown() 0 6 1
A addBlockTop() 0 12 2
A delete() 0 6 1
A addBlockBottom() 0 12 2
A update() 0 7 1
A moveUp() 0 6 1
1
<?php
2
3
namespace Chuckbe\Chuckcms\Controllers;
4
5
use Chuckbe\Chuckcms\Chuck\PageBlockRepository;
6
use Chuckbe\Chuckcms\Models\Page;
7
use Chuckbe\Chuckcms\Models\PageBlock;
8
use Chuckbe\Chuckcms\Models\Repeater;
9
use Chuckbe\Chuckcms\Models\Resource;
10
use Chuckbe\Chuckcms\Models\Template;
11
use File;
12
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
13
use Illuminate\Foundation\Bus\DispatchesJobs;
14
use Illuminate\Foundation\Validation\ValidatesRequests;
15
use Illuminate\Http\Request;
16
use Illuminate\Routing\Controller as BaseController;
17
18
class PageBlockController extends BaseController
19
{
20
    use AuthorizesRequests;
21
    use DispatchesJobs;
22
    use ValidatesRequests;
23
24
    protected $template;
25
    protected $page;
26
    protected $pageblock;
27
    protected $pageBlockRepository;
28
    protected $resource;
29
    protected $repeater;
30
31
    /**
32
     * Create a new controller instance.
33
     *
34
     * @return void
35
     */
36
    public function __construct(Template $template, Page $page, PageBlock $pageblock, PageBlockRepository $pageBlockRepository, Resource $resource, Repeater $repeater)
37
    {
38
        $this->template = $template;
39
        $this->page = $page;
40
        $this->pageblock = $pageblock;
41
        $this->pageBlockRepository = $pageBlockRepository;
42
        $this->resource = $resource;
43
        $this->repeater = $repeater;
44
    }
45
46
    /**
47
     * Get rendered pageblock html as a string.
48
     *
49
     * @param Request $request
50
     *
51
     * @return array $pageblock
52
     */
53
    public function show(Request $request)
54
    {
55
        // AUTHORIZE ... COMES HERE
56
        $pb = $this->pageblock->where('id', $request->get('pageblock_id'))->first();
0 ignored issues
show
Unused Code introduced by
The assignment to $pb is dead and can be removed.
Loading history...
57
        $pageblock = $this->pageBlockRepository->getRenderedByPageBlock($pageblock);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pageblock seems to be never defined.
Loading history...
58
59
        return $pageblock;
60
    }
61
62
    /**
63
     * Show the application dashboard.
64
     *
65
     * @param Request $request
66
     *
67
     * @return array $pageblock
68
     */
69
    public function update(Request $request)
70
    {
71
        // AUTHORIZE ... COMES HERE
72
        $pageblock = $this->pageblock->getById($request->get('pageblock_id'));
73
        $pageblock = $this->pageBlockRepository->updateBody($pageblock, $request->get('html'));
74
75
        return $pageblock;
76
    }
77
78
    /**
79
     * Move the resource one place up.
80
     *
81
     * @param Request $request
82
     *
83
     * @return array $pageblock
84
     */
85
    public function moveUp(Request $request)
86
    {
87
        // AUTHORIZE ... COMES HERE
88
        $pageblock = $this->pageBlockRepository->moveUpById($request->get('pageblock_id'));
89
90
        return $pageblock;
91
    }
92
93
    /**
94
     * Move the resource one place down.
95
     *
96
     * @param Request $request
97
     *
98
     * @return array $pageblock
99
     */
100
    public function moveDown(Request $request)
101
    {
102
        // AUTHORIZE ... COMES HERE
103
        $pageblock = $this->pageBlockRepository->moveDownById($request->get('pageblock_id'));
104
105
        return $pageblock;
106
    }
107
108
    /**
109
     * Delete the resource from the page.
110
     *
111
     * @param Request $request
112
     *
113
     * @return string $tatus
114
     */
115
    public function delete(Request $request)
116
    {
117
        // AUTHORIZE ... COMES HERE
118
        $status = $this->pageBlockRepository->deleteById($request->get('pageblock_id'));
119
120
        return $status;
121
    }
122
123
    /**
124
     * Add Block From Location To Top of Page and Store to Database.
125
     *
126
     * @param Request $request
127
     *
128
     * @return string
129
     */
130
    public function addBlockTop(Request $request)
131
    {
132
        if ($request->has('lang')) {
133
            app()->setLocale($request->get('lang'));
0 ignored issues
show
introduced by
The method setLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

133
            app()->/** @scrutinizer ignore-call */ setLocale($request->get('lang'));
Loading history...
134
        }
135
136
        // AUTHORIZE ... COMES HERE
137
        $contents = File::get($request['location']);
138
        $page = $this->page->getById($request['page_id']);
139
        $this->pageblock->addBlockTop($contents, $page, $request['name']);
140
        //return $pageblock;
141
        return 'success';
142
    }
143
144
    /**
145
     * Add Block From Location To Bottom of Page and Store to Database.
146
     *
147
     * @param Request $request
148
     *
149
     * @return string
150
     */
151
    public function addBlockBottom(Request $request)
152
    {
153
        if ($request->has('lang')) {
154
            app()->setLocale($request->get('lang'));
155
        }
156
157
        // AUTHORIZE ... COMES HERE
158
        $contents = File::get($request['location']);
159
        $page = $this->page->getById($request['page_id']);
160
        $this->pageblock->addBlockBottom($contents, $page, $request['name']);
161
        //return $pageblock;
162
        return 'success';
163
    }
164
}
165