|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\BasePageController; |
|
6
|
|
|
use App\Models\User; |
|
7
|
|
|
use Blacklight\Contents; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
|
|
10
|
|
|
class AdminContentController extends BasePageController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @throws \Exception |
|
14
|
|
|
*/ |
|
15
|
|
|
public function index() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->setAdminPrefs(); |
|
18
|
|
|
$contentList = (new Contents())->getAll(); |
|
19
|
|
|
$this->smarty->assign('contentlist', $contentList); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
$meta_title = 'Content List'; |
|
22
|
|
|
|
|
23
|
|
|
$content = $this->smarty->fetch('content-list.tpl'); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$this->smarty->assign(compact('meta_title', 'content')); |
|
26
|
|
|
|
|
27
|
|
|
$this->adminrender(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Request $request |
|
32
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
|
33
|
|
|
* @throws \Exception |
|
34
|
|
|
*/ |
|
35
|
|
|
public function create(Request $request) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setAdminPrefs(); |
|
38
|
|
|
$contents = new Contents(); |
|
39
|
|
|
$meta_title = 'Content Add'; |
|
40
|
|
|
|
|
41
|
|
|
// Set the current action. |
|
42
|
|
|
$action = $request->input('action') ?? 'view'; |
|
43
|
|
|
|
|
44
|
|
|
$content = [ |
|
45
|
|
|
'id' => '', |
|
46
|
|
|
'title' => '', |
|
47
|
|
|
'url' => '', |
|
48
|
|
|
'body' => '', |
|
49
|
|
|
'metadescription' => '', |
|
50
|
|
|
'metakeywords' => '', |
|
51
|
|
|
'contenttype' => '', |
|
52
|
|
|
'showinmenu' => '', |
|
53
|
|
|
'status' => '', |
|
54
|
|
|
'ordinal' => '', |
|
55
|
|
|
'created_at' => '', |
|
56
|
|
|
'role' => '', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
switch ($action) { |
|
60
|
|
|
case 'add': |
|
61
|
|
|
$meta_title = 'Content Add'; |
|
62
|
|
|
$content['showinmenu'] = '1'; |
|
63
|
|
|
$content['status'] = '1'; |
|
64
|
|
|
$content['contenttype'] = '2'; |
|
65
|
|
|
break; |
|
66
|
|
|
|
|
67
|
|
|
case 'submit': |
|
68
|
|
|
// Validate and add or update. |
|
69
|
|
|
if ($request->missing('id') || empty($request->input('id'))) { |
|
70
|
|
|
$returnid = $contents->add($request->all()); |
|
71
|
|
|
} else { |
|
72
|
|
|
$content = $contents->update($request->all()); |
|
73
|
|
|
$returnid = $content['id']; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return redirect('admin/content-add?id='.$returnid); |
|
77
|
|
|
break; |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
case 'view': |
|
80
|
|
|
default: |
|
81
|
|
|
if ($request->has('id')) { |
|
82
|
|
|
$meta_title = 'Content Edit'; |
|
83
|
|
|
$id = $request->input('id'); |
|
84
|
|
|
|
|
85
|
|
|
$content = $contents->getByID($id, User::ROLE_ADMIN); |
|
86
|
|
|
} |
|
87
|
|
|
break; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$this->smarty->assign('status_ids', [1, 0]); |
|
91
|
|
|
$this->smarty->assign('status_names', ['Enabled', 'Disabled']); |
|
92
|
|
|
|
|
93
|
|
|
$this->smarty->assign('yesno_ids', [1, 0]); |
|
94
|
|
|
$this->smarty->assign('yesno_names', ['Yes', 'No']); |
|
95
|
|
|
|
|
96
|
|
|
$contenttypelist = [1 => 'Useful Link', 2 => 'Article', 3 => 'Homepage']; |
|
97
|
|
|
$this->smarty->assign('contenttypelist', $contenttypelist); |
|
98
|
|
|
|
|
99
|
|
|
$this->smarty->assign('content', $content); |
|
100
|
|
|
|
|
101
|
|
|
$rolelist = [1 => 'Everyone', 2 => 'Logged in Users', 3 => 'Admins']; |
|
102
|
|
|
$this->smarty->assign('rolelist', $rolelist); |
|
103
|
|
|
|
|
104
|
|
|
$content = $this->smarty->fetch('content-add.tpl'); |
|
105
|
|
|
|
|
106
|
|
|
$this->smarty->assign(compact('meta_title', 'content')); |
|
107
|
|
|
|
|
108
|
|
|
$this->adminrender(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param \Illuminate\Http\Request $request |
|
113
|
|
|
* |
|
114
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
|
115
|
|
|
*/ |
|
116
|
|
|
public function destroy(Request $request) |
|
117
|
|
|
{ |
|
118
|
|
|
if ($request->has('id')) { |
|
119
|
|
|
$contents = new Contents(); |
|
120
|
|
|
$contents->delete($request->input('id')); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$referrer = $request->server('HTTP_REFERER'); |
|
124
|
|
|
|
|
125
|
|
|
return redirect($referrer); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.