1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Http\Controllers\Back; |
4
|
|
|
|
5
|
|
|
use Thinktomorrow\Chief\App\Http\Controllers\Controller; |
6
|
|
|
use Thinktomorrow\Chief\Common\Relations\RelatedCollection; |
7
|
|
|
use Thinktomorrow\Chief\Pages\Application\CreatePage; |
8
|
|
|
use Thinktomorrow\Chief\Pages\Page; |
9
|
|
|
use Thinktomorrow\Chief\Pages\PageRepository; |
|
|
|
|
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use Illuminate\Http\Response; |
12
|
|
|
use Thinktomorrow\Chief\App\Http\Requests\PageCreateRequest; |
13
|
|
|
use Thinktomorrow\Chief\Pages\Application\UpdatePage; |
14
|
|
|
use Thinktomorrow\Chief\App\Http\Requests\PageUpdateRequest; |
15
|
|
|
|
16
|
|
|
class PagesController extends Controller |
17
|
|
|
{ |
18
|
|
|
public function index() |
19
|
|
|
{ |
20
|
|
|
$published = Page::unarchived()->published()->paginate(10); |
21
|
|
|
$drafts = Page::unarchived()->where('published', 0)->paginate(10); |
22
|
|
|
$archived = Page::archived()->paginate(10); |
23
|
|
|
|
24
|
|
|
return view('chief::back.pages.index', compact('published', 'drafts', 'archived')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Show the form for creating a new resource. |
29
|
|
|
* |
30
|
|
|
* @return Response |
31
|
|
|
*/ |
32
|
1 |
|
public function create() |
33
|
|
|
{ |
34
|
1 |
|
$page = new Page(); |
35
|
1 |
|
$page->existingRelationIds = collect([]); |
|
|
|
|
36
|
1 |
|
$relations = RelatedCollection::availableChildren($page)->flattenForGroupedSelect()->toArray(); |
37
|
|
|
|
38
|
1 |
|
return view('chief::back.pages.create', ['page' => $page, 'relations' => $relations]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Store a newly created resource in storage. |
43
|
|
|
* |
44
|
|
|
* @param Request $request |
45
|
|
|
* @return Response |
46
|
|
|
*/ |
47
|
2 |
|
public function store(PageCreateRequest $request) |
48
|
|
|
{ |
49
|
2 |
|
$page = app(CreatePage::class)->handle($request->trans); |
50
|
|
|
|
51
|
2 |
|
return redirect()->route('chief.back.pages.index')->with('messages.success', $page->title .' is aangemaakt'); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Show the form for editing the specified resource. |
56
|
|
|
* |
57
|
|
|
* @param int $id |
58
|
|
|
* @return Response |
59
|
|
|
*/ |
60
|
|
|
public function edit($id) |
61
|
|
|
{ |
62
|
|
|
$page = Page::findOrFail($id); |
63
|
|
|
$page->injectTranslationForForm(); |
64
|
|
|
|
65
|
|
|
$page->existingRelationIds = RelatedCollection::relationIds($page->children()); |
|
|
|
|
66
|
|
|
$relations = RelatedCollection::availableChildren($page)->flattenForGroupedSelect()->toArray(); |
67
|
|
|
|
68
|
|
|
return view('chief::back.pages.edit', compact('page', 'relations')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Update the specified resource in storage. |
73
|
|
|
* |
74
|
|
|
* @param Request $request |
75
|
|
|
* @param int $id |
76
|
|
|
* @return Response |
77
|
|
|
*/ |
78
|
2 |
|
public function update(PageUpdateRequest $request, $id) |
79
|
|
|
{ |
80
|
2 |
|
$page = app(UpdatePage::class)->handle($id, $request->trans, $request->relations); |
81
|
|
|
|
82
|
2 |
|
return redirect()->route('chief.back.pages.index')->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$page->title .'" werd aangepast'); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Remove the specified resource from storage. |
87
|
|
|
* |
88
|
|
|
* @param int $id |
89
|
|
|
* @return Response |
90
|
|
|
*/ |
91
|
1 |
|
public function destroy($id) |
92
|
|
|
{ |
93
|
1 |
|
$page = Page::findOrFail($id); |
94
|
1 |
|
if (request()->get('deleteconfirmation') !== 'DELETE' && (!$page->isPublished() || $page->isArchived())) { |
95
|
|
|
return redirect()->back()->with('messages.warning', 'fout'); |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
if ($page->isDraft() || $page->isArchived()) { |
99
|
1 |
|
$page->delete(); |
100
|
|
|
} |
101
|
1 |
|
if ($page->isPublished()) { |
102
|
|
|
$page->archive(); |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
$message = 'Het item werd verwijderd.'; |
106
|
|
|
|
107
|
1 |
|
return redirect()->route('chief.back.pages.index')->with('messages.warning', $message); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function publish(Request $request) |
111
|
|
|
{ |
112
|
|
|
$page = Page::findOrFail($request->get('id')); |
113
|
|
|
$published = true === !$request->checkboxStatus; // string comp. since bool is passed as string |
114
|
|
|
|
115
|
|
|
($published) ? $page->publish() : $page->draft(); |
116
|
|
|
|
117
|
|
|
return redirect()->back(); |
118
|
|
|
|
119
|
|
|
// return response()->json([ |
120
|
|
|
// 'message' => $published ? 'nieuwsartikel werd online gezet' : 'nieuwsartikel werd offline gehaald', |
121
|
|
|
// 'published'=> $published, |
122
|
|
|
// 'id'=> $page->id |
123
|
|
|
// ],200); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// public function upload($id, Request $request) |
127
|
|
|
// { |
128
|
|
|
// $page = page::find($id); |
129
|
|
|
// $page->addFile($request->file('image'), $request->type, $request->get('locale')); |
130
|
|
|
// |
131
|
|
|
// return redirect()->back(); |
132
|
|
|
// } |
133
|
|
|
} |
134
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths