|
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 Application\Mvc\Helper\CmsCache; |
|
11
|
|
|
use Cms\Model\Translate; |
|
12
|
|
|
use Cms\Scanner; |
|
13
|
|
|
|
|
14
|
|
|
class TranslateController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function initialize() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->setAdminEnvironment(); |
|
20
|
|
|
$this->helper->activeMenu()->setActive('admin-translate'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function indexAction() |
|
24
|
|
|
{ |
|
25
|
|
|
$model = new Translate(); |
|
26
|
|
|
if ($this->request->isPost()) { |
|
27
|
|
|
$post = $this->request->getPost(); |
|
28
|
|
|
if (!empty($post)) { |
|
29
|
|
|
foreach ($post as $key => $value) { |
|
30
|
|
|
$key = str_replace('_', ' ', $key); // При отправке формы POST-запросом, все пробелы заменяются на "_". Меняем обратно. |
|
31
|
|
|
$phrase = $model->findByPhraseAndLang($key); |
|
32
|
|
|
if ($phrase) { |
|
33
|
|
|
$phrase->setTranslation($value); |
|
34
|
|
|
$phrase->update(); |
|
35
|
|
|
} else { |
|
36
|
|
|
$phraseNew = new Translate(); |
|
37
|
|
|
$phraseNew->setPhrase($key); |
|
38
|
|
|
$phraseNew->setLang(LANG); |
|
39
|
|
|
$phraseNew->setTranslation($value); |
|
40
|
|
|
$phraseNew->create(); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
CmsCache::getInstance()->save('translates', Translate::buildCmsTranslatesCache()); |
|
46
|
|
|
$this->flash->success($this->helper->at('Saved has been successful')); |
|
47
|
|
|
|
|
48
|
|
|
$lang = LANG; |
|
49
|
|
|
$key = HOST_HASH . md5("Translate::findByLang($lang)"); |
|
50
|
|
|
$this->cache->delete($key); |
|
51
|
|
|
|
|
52
|
|
|
return $this->redirect($this->url->get() . 'cms/translate?lang=' . LANG); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$scanner = new Scanner(); |
|
56
|
|
|
$phrases = $scanner->search(); |
|
57
|
|
|
|
|
58
|
|
|
$this->view->phrases = $phrases; |
|
|
|
|
|
|
59
|
|
|
$this->view->model = $model; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
} |
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: