Passed
Push — master ( 57dc21...a78050 )
by Karel
06:15
created

PageBlockController::addBlockBottom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Chuckbe\Chuckcms\Controllers;
4
5
use Chuckbe\Chuckcms\Models\Page;
6
use Chuckbe\Chuckcms\Models\PageBlock;
7
use Chuckbe\Chuckcms\Chuck\PageBlockRepository;
8
use Chuckbe\Chuckcms\Models\Resource;
9
use Chuckbe\Chuckcms\Models\Repeater;
10
use Chuckbe\Chuckcms\Models\Template;
11
12
use File;
13
14
use Illuminate\Http\Request;
15
use Illuminate\Foundation\Bus\DispatchesJobs;
16
use Illuminate\Routing\Controller as BaseController;
17
use Illuminate\Foundation\Validation\ValidatesRequests;
18
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
19
20
class PageBlockController extends BaseController
21
{
22
    use AuthorizesRequests, DispatchesJobs, 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
     * @return array $pageblock
51
     */
52
    public function show(Request $request)
53
    {
54
        // AUTHORIZE ... COMES HERE
55
        $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...
56
        $pageblock = $this->pageBlockRepository->getRenderedByPageBlock($pageblock);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pageblock seems to be never defined.
Loading history...
57
        return $pageblock;
58
    }
59
60
    /**
61
     * Show the application dashboard.
62
     *
63
     * @param  Request $request
64
     * @return array $pageblock
65
     */
66
    public function update(Request $request)
67
    {
68
        // AUTHORIZE ... COMES HERE
69
        $pageblock = $this->pageblock->getById($request->get('pageblock_id'));
70
        $pageblock = $this->pageBlockRepository->updateBody($pageblock, $request->get('html'));
71
        return $pageblock;
72
    }
73
74
    /**
75
     * Move the resource one place up.
76
     *
77
     * @param  Request $request
78
     * @return array $pageblock
79
     */
80
    public function moveUp(Request $request)
81
    {
82
        // AUTHORIZE ... COMES HERE
83
        $pageblock = $this->pageBlockRepository->moveUpById($request->get('pageblock_id'));
84
        return $pageblock;
85
    }
86
87
    /**
88
     * Move the resource one place down.
89
     *
90
     * @param  Request $request
91
     * @return array $pageblock
92
     */
93
    public function moveDown(Request $request)
94
    {
95
        // AUTHORIZE ... COMES HERE
96
        $pageblock = $this->pageBlockRepository->moveDownById($request->get('pageblock_id'));
97
        return $pageblock;
98
    }
99
100
    /**
101
     * Delete the resource from the page.
102
     *
103
     * @param  Request $request
104
     * @return string $tatus
105
     */
106
    public function delete(Request $request)
107
    {
108
        // AUTHORIZE ... COMES HERE
109
        $status = $this->pageBlockRepository->deleteById($request->get('pageblock_id'));
110
        return $status;
111
    }
112
113
    /**
114
     * Add Block From Location To Top of Page and Store to Database
115
     *
116
     * @param  Request $request
117
     * @return string
118
     */
119
    public function addBlockTop(Request $request)
120
    {
121
        // AUTHORIZE ... COMES HERE
122
        $contents = File::get($request['location']);
123
        $page = $this->page->getById($request['page_id']);
124
        $this->pageblock->addBlockTop($contents, $page, $request['name']);
125
        //return $pageblock;
126
        return 'success';
127
    }
128
129
    /**
130
     * Add Block From Location To Bottom of Page and Store to Database
131
     *
132
     * @param  Request $request
133
     * @return string
134
     */
135
    public function addBlockBottom(Request $request)
136
    {
137
        // AUTHORIZE ... COMES HERE
138
        $contents = File::get($request['location']);
139
        $page = $this->page->getById($request['page_id']);
140
        $this->pageblock->addBlockBottom($contents, $page, $request['name']);
141
        //return $pageblock;
142
        return 'success';
143
    }
144
}
145