|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2011 - 2014 Oleksandr Torosh (http://wezoom.net) |
|
4
|
|
|
* @author Oleksandr Torosh <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Publication\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Application\Mvc\Controller; |
|
10
|
|
|
use Publication\Form\TypeForm; |
|
11
|
|
|
use Publication\Model\Type; |
|
12
|
|
|
|
|
13
|
|
|
class TypeController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
public function initialize() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->setAdminEnvironment(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function indexAction() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->view->entries = Type::find(); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$this->helper->title('Manage Types of Publication', true); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
public function addAction() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->view->pick(array('type/edit')); |
|
31
|
|
|
|
|
32
|
|
|
$form = new TypeForm(); |
|
33
|
|
|
$model = new Type(); |
|
34
|
|
|
|
|
35
|
|
|
if ($this->request->isPost()) { |
|
36
|
|
|
$post = $this->request->getPost(); |
|
37
|
|
|
$form->bind($post, $model); |
|
38
|
|
|
|
|
39
|
|
|
if ($form->isValid()) { |
|
40
|
|
|
if ($model->create()) { |
|
41
|
|
|
$form->bind($post, $model); |
|
42
|
|
|
$model->updateFields($post); |
|
43
|
|
|
if ($model->update()) { |
|
44
|
|
|
$this->flash->success('Type created'); |
|
45
|
|
|
return $this->redirect($this->url->get() . 'publication/type/edit/' . $model->getId() . '?lang=' . LANG); |
|
46
|
|
|
} else { |
|
47
|
|
|
$this->flashErrors($model); |
|
48
|
|
|
} |
|
49
|
|
|
} else { |
|
50
|
|
|
$this->flashErrors($model); |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
$this->flashErrors($form); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
58
|
|
|
$this->view->form = $form; |
|
|
|
|
|
|
59
|
|
|
$this->helper->title($this->helper->at('Adding Type of Publication')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function editAction($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$form = new TypeForm(); |
|
65
|
|
|
$model = Type::findFirst($id); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if ($this->request->isPost()) { |
|
68
|
|
|
$post = $this->request->getPost(); |
|
69
|
|
|
$form->bind($post, $model); |
|
70
|
|
|
|
|
71
|
|
|
if ($form->isValid()) { |
|
72
|
|
|
$model->updateFields($post); |
|
|
|
|
|
|
73
|
|
|
if ($model->update()) { |
|
|
|
|
|
|
74
|
|
|
$this->flash->success('Type created'); |
|
75
|
|
|
return $this->redirect($this->url->get() . 'publication/type/edit/' . $model->getId() . '?lang=' . LANG); |
|
|
|
|
|
|
76
|
|
|
} else { |
|
77
|
|
|
$this->flashErrors($model); |
|
78
|
|
|
} |
|
79
|
|
|
} else { |
|
80
|
|
|
$this->flashErrors($form); |
|
81
|
|
|
} |
|
82
|
|
|
} else { |
|
83
|
|
|
$form->setEntity($model); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
87
|
|
|
$this->view->form = $form; |
|
|
|
|
|
|
88
|
|
|
$this->helper->title($this->helper->at('Manage Type of Publication')); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function deleteAction($id) |
|
92
|
|
|
{ |
|
93
|
|
|
$model = Type::findFirst($id); |
|
|
|
|
|
|
94
|
|
|
$count = Type::count(); |
|
95
|
|
|
if ($count == 1) { |
|
96
|
|
|
$this->flash->error($this->helper->at('Can not Delete the last Publication Type')); |
|
97
|
|
|
return; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ($this->request->isPost()) { |
|
101
|
|
|
$model->delete(); |
|
|
|
|
|
|
102
|
|
|
$this->redirect($this->url->get() . 'publication/type'); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
106
|
|
|
$this->helper->title($this->helper->at('Delete Type')); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
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: