|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Widget\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Application\Mvc\Controller; |
|
6
|
|
|
use Widget\Model\Widget; |
|
7
|
|
|
use Widget\Form\WidgetForm; |
|
8
|
|
|
|
|
9
|
|
|
class AdminController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
public function initialize() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->setAdminEnvironment(); |
|
15
|
|
|
$this->helper->activeMenu()->setActive('admin-widget'); |
|
16
|
|
|
|
|
17
|
|
|
$this->view->languages_disabled = true; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function indexAction() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->view->entries = Widget::find(); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$this->helper->title($this->helper->at('Manage Widgets'), true); |
|
26
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function addAction() |
|
30
|
|
|
{ |
|
31
|
|
|
$widget = new Widget(); |
|
32
|
|
|
$form = new WidgetForm(); |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
if ($this->request->isPost()) { |
|
35
|
|
|
$form->bind($this->request->getPost(), $widget); |
|
36
|
|
|
if ($form->isValid()) { |
|
37
|
|
|
if ($widget->save()) { |
|
38
|
|
|
$this->redirect($this->url->get() . 'widget/admin/edit/' . $widget->getId()); |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->flashErrors($widget); |
|
41
|
|
|
} |
|
42
|
|
|
} else { |
|
43
|
|
|
$this->flashErrors($form); |
|
44
|
|
|
} |
|
45
|
|
|
} else { |
|
46
|
|
|
$form->setEntity($widget); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->view->pick('admin/edit'); |
|
50
|
|
|
$this->view->setVar('form', $form); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$this->view->title = $this->helper->at('Adding widget'); |
|
|
|
|
|
|
53
|
|
|
$this->helper->title($this->view->title); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function editAction($id) |
|
58
|
|
|
{ |
|
59
|
|
|
$id = $this->filter->sanitize($id, "string"); |
|
60
|
|
|
$widget = Widget::findFirst(["id = '$id'"]); |
|
|
|
|
|
|
61
|
|
|
if (!$widget) { |
|
62
|
|
|
$this->redirect($this->url->get() . 'widget/admin/add'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$form = new WidgetForm(); |
|
66
|
|
|
$form->remove('id'); |
|
67
|
|
View Code Duplication |
if ($this->request->isPost()) { |
|
68
|
|
|
|
|
69
|
|
|
$form->bind($this->request->getPost(), $widget); |
|
70
|
|
|
if ($form->isValid()) { |
|
71
|
|
|
if ($widget->save()) { |
|
|
|
|
|
|
72
|
|
|
$this->redirect($this->url->get() . 'widget/admin/edit/' . $widget->getId()); |
|
|
|
|
|
|
73
|
|
|
} else { |
|
74
|
|
|
$this->flashErrors($widget); |
|
75
|
|
|
} |
|
76
|
|
|
} else { |
|
77
|
|
|
$this->flashErrors($form); |
|
78
|
|
|
} |
|
79
|
|
|
} else { |
|
80
|
|
|
$form->setEntity($widget); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->view->setVar('form', $form); |
|
|
|
|
|
|
84
|
|
|
$this->view->setVar('widget', $widget); |
|
85
|
|
|
|
|
86
|
|
|
$this->helper->title($this->helper->at('Editing widget'), true); |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function deleteAction($id) |
|
91
|
|
|
{ |
|
92
|
|
|
$id = $this->filter->sanitize($id, "string"); |
|
93
|
|
|
$model = Widget::findFirst(["id = '$id'"]); |
|
|
|
|
|
|
94
|
|
|
if ($model) { |
|
95
|
|
|
|
|
96
|
|
|
if ($this->request->isPost()) { |
|
97
|
|
|
$model->delete(); |
|
98
|
|
|
$this->redirect($this->url->get() . 'widget/admin/index'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: