|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Webcms2 admin module package. |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace AdminModule; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Tomáš Voslař <tomas.voslar at webcook.cz> |
|
11
|
|
|
* @package WebCMS2 |
|
12
|
|
|
*/ |
|
13
|
|
|
class TranslationsPresenter extends BasePresenter |
|
14
|
|
|
{ |
|
15
|
1 |
|
public function renderDefault() |
|
16
|
|
|
{ |
|
17
|
1 |
|
$this->reloadContent(); |
|
18
|
1 |
|
} |
|
19
|
|
|
|
|
20
|
1 |
|
protected function createComponentTranslationGrid($name) |
|
21
|
|
|
{ |
|
22
|
1 |
|
$grid = $this->createGrid($this, $name, "Translation"); |
|
23
|
|
|
|
|
24
|
1 |
|
$langs = $this->getAllLanguages(); |
|
25
|
|
|
|
|
26
|
|
|
$backend = array( |
|
27
|
1 |
|
'' => $this->translation['Pick filter'], |
|
28
|
1 |
|
0 => $this->translation['No'], |
|
29
|
1 |
|
1 => $this->translation['Yes'], |
|
30
|
1 |
|
); |
|
31
|
|
|
|
|
32
|
1 |
|
$grid->addColumnText('id', 'ID')->setSortable()->setFilterNumber(); |
|
33
|
1 |
|
$grid->addColumnText('key', 'Key')->setSortable()->setFilterText(); |
|
34
|
|
|
$grid->addColumnText('translation', 'Value')->setSortable()->setCustomRender(function ($item) { |
|
35
|
1 |
|
return '<div class="translation" contentEditable>'.$item->getTranslation().'</div>'; |
|
36
|
1 |
|
}); |
|
37
|
1 |
|
$grid->addColumnText('backend', 'Backend')->setReplacement(array( |
|
38
|
1 |
|
'1' => 'Yes', |
|
39
|
1 |
|
NULL => 'No', |
|
40
|
1 |
|
))->setFilterSelect($backend); |
|
41
|
|
|
|
|
42
|
1 |
|
$grid->addColumnText('translated', 'Translated')->setReplacement(array( |
|
43
|
1 |
|
'1' => 'Yes', |
|
44
|
1 |
|
NULL => 'No', |
|
45
|
1 |
|
))->setFilterSelect($backend); |
|
46
|
|
|
|
|
47
|
1 |
|
$grid->addColumnText('language', 'Language')->setCustomRender(function ($item) { |
|
48
|
1 |
|
return $item->getLanguage()->getName(); |
|
49
|
1 |
|
})->setSortable(); |
|
50
|
|
|
|
|
51
|
1 |
|
$grid->addFilterSelect('language', 'Language')->getControl()->setTranslator(null)->setItems($langs); |
|
52
|
|
|
|
|
53
|
1 |
|
$grid->addActionHref("deleteTranslation", 'Delete')->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-danger'), 'data-confirm' => 'Are you sure you want to delete the item?')); |
|
54
|
|
|
|
|
55
|
1 |
|
$grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); |
|
56
|
|
|
|
|
57
|
1 |
|
return $grid; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function actionDeleteTranslation($id) |
|
61
|
|
|
{ |
|
62
|
|
|
$translation = $this->em->find("WebCMS\Entity\Translation", $id); |
|
63
|
|
|
$this->em->remove($translation); |
|
64
|
|
|
$this->em->flush(); |
|
65
|
|
|
|
|
66
|
|
|
$this->flashMessage('Translation has been removed.', 'success'); |
|
67
|
|
|
|
|
68
|
|
|
$this->cleanCache(); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$this->forward('Languages:Translates'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function handleUpdateTranslation($idTranslation, $value) |
|
74
|
|
|
{ |
|
75
|
|
|
$value = strip_tags($value, '<strong><b><i><u>'); |
|
76
|
|
|
|
|
77
|
|
|
$translation = $this->em->find('WebCMS\Entity\Translation', trim($idTranslation)); |
|
78
|
|
|
$translation->setTranslation(trim($value)); |
|
79
|
|
|
|
|
80
|
|
|
$this->em->persist($translation); |
|
81
|
|
|
$this->em->flush(); |
|
82
|
|
|
|
|
83
|
|
|
$this->flashMessage('Translation has been added.', 'success'); |
|
84
|
|
|
|
|
85
|
|
|
$this->invalidateControl('flashMessages'); |
|
86
|
|
|
|
|
87
|
|
|
$this->forward('Languages:Translates'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function handleRegenerateTranslations() |
|
91
|
|
|
{ |
|
92
|
|
|
$translations = $this->em->getRepository('WebCMS\Entity\Translation')->findAll(); |
|
93
|
|
|
|
|
94
|
|
|
foreach ($translations as $t) { |
|
95
|
|
|
$t->setTranslation($t->getTranslation()); |
|
96
|
|
|
$t->setHash(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->em->flush(); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: