|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net) |
|
4
|
|
|
* @author Aleksandr Torosh <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Cms\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Application\Mvc\Controller; |
|
10
|
|
|
use Cms\Form\LanguageForm; |
|
11
|
|
|
use Cms\Model\Language; |
|
12
|
|
|
|
|
13
|
|
|
class LanguageController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
public function initialize() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->setAdminEnvironment(); |
|
19
|
|
|
$this->helper->activeMenu()->setActive('admin-language'); |
|
20
|
|
|
$this->view->languages_disabled = true; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function indexAction() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->view->entries = Language::find(array( |
|
|
|
|
|
|
27
|
|
|
'order' => 'primary DESC, sortorder ASC', |
|
28
|
|
|
)); |
|
29
|
|
|
|
|
30
|
|
|
$this->view->title = $this->helper->at('Manage Languages'); |
|
|
|
|
|
|
31
|
|
|
$this->helper->title($this->view->title); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function addAction() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->view->pick(array('language/edit')); |
|
37
|
|
|
$form = new LanguageForm(); |
|
38
|
|
|
$model = new Language(); |
|
39
|
|
|
|
|
40
|
|
|
if ($this->request->isPost()) { |
|
41
|
|
|
$form->bind($this->request->getPost(), $model); |
|
42
|
|
|
if ($form->isValid()) { |
|
43
|
|
|
if ($model->save()) { |
|
44
|
|
|
$this->cache->delete(Language::cacheKey()); |
|
45
|
|
|
$this->flash->success($this->helper->at('Updated has been successful')); |
|
46
|
|
|
return $this->redirect($this->url->get() . 'cms/language'); |
|
47
|
|
|
} else { |
|
48
|
|
|
$this->flashErrors($model); |
|
49
|
|
|
} |
|
50
|
|
|
} else { |
|
51
|
|
|
$this->flashErrors($form); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
56
|
|
|
$this->view->form = $form; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$this->view->title = $this->helper->at('Adding language'); |
|
|
|
|
|
|
59
|
|
|
$this->helper->title($this->view->title); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function editAction($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$form = new LanguageForm(); |
|
65
|
|
|
$model = Language::findFirst($id); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if ($this->request->isPost()) { |
|
68
|
|
|
$form->bind($this->request->getPost(), $model); |
|
69
|
|
|
if ($form->isValid()) { |
|
70
|
|
|
($this->request->getPost('primary') != null) ? $model->setPrimary(1) : $model->setPrimary(0); |
|
|
|
|
|
|
71
|
|
|
if ($model->save()) { |
|
|
|
|
|
|
72
|
|
|
$model->setOnlyOnePrimary(); |
|
|
|
|
|
|
73
|
|
|
$this->flash->success($this->helper->at('Updated has been successful')); |
|
74
|
|
|
$this->cache->delete(Language::cacheKey()); |
|
75
|
|
|
return $this->redirect($this->url->get() . 'cms/language/edit/' . $model->getId()); |
|
|
|
|
|
|
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
|
|
|
|
|
89
|
|
|
$this->view->title = 'Editing language'; |
|
|
|
|
|
|
90
|
|
|
$this->helper->title($this->view->title); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function deleteAction($id) |
|
94
|
|
|
{ |
|
95
|
|
|
$model = Language::findFirst($id); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
if ($this->request->isPost()) { |
|
98
|
|
|
$this->cache->delete(Language::cacheKey()); |
|
99
|
|
|
$model->delete(); |
|
|
|
|
|
|
100
|
|
|
return $this->redirect($this->url->get() . 'cms/language'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
104
|
|
|
$this->view->title = $this->helper->at('Removing language'); |
|
|
|
|
|
|
105
|
|
|
$this->helper->title($this->view->title); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
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: