Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / webtt / app / controllers / translations_controller.php
blob875799e104d843247fa70bdc7330cb68c79c7898
1 <?php
2 /*
3 Ryzom Core Web-Based Translation Tool
4 Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 <?php
21 class TranslationsController extends AppController {
23 var $name = 'Translations';
25 function index() {
26 $this->Translation->recursive = 0;
27 $conditions = null;
28 if (isset($this->passedArgs['identifier_id']) && $identifier = $this->passedArgs['identifier_id'])
29 $conditions = array('Translation.identifier_id' => $identifier);
30 $this->set('translations', $this->paginate($conditions));
33 function view($id = null) {
34 if (!$id) {
35 $this->Session->setFlash(__('Invalid translation', true));
36 $this->redirect(array('action' => 'index'));
38 $this->set('translation', $translation = $this->Translation->read(null, $id));
39 if (isset($translation['Translation']['identifier_id']))
41 $this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $translation['Translation']['identifier_id']));
42 $this->set('columnTranslations', $columnTranslations = $this->Translation->find('all', array('conditions' => array('Translation.parent_id' => $translation['Translation']['id']), 'order' => 'Translation.id')));
44 if ($identifier_id = $translation['Translation']['identifier_id'])
45 $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
48 function add() {
49 if (!empty($this->data)) {
50 $this->Translation->create();
51 if ($this->data['ChildTranslation'])
53 unset($translationText);
54 foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
56 $ent['columns'][] = $childTranslation['translation_text'];
57 $translationText .= $childTranslation['translation_text'] . "\t";
59 $this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
61 else
62 $ent['string'] = $this->data['Translation']['translation_text'];
63 sort($ent['columns']);
64 $this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
65 $this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
66 $this->data['Identifier']['translated'] = 1;
67 $res = $this->Translation->saveAll($this->data);
68 $this->log($this->data);
69 if ($res) {
70 $this->Session->setFlash(__('The translation has been saved', true));
71 if ($this->params['form']['Next'])
73 $identifier_id = $this->data['Translation']['identifier_id'];
74 $identifier = $this->Translation->Identifier->read(null, $identifier_id);
75 $identifierNeighbors = $this->Translation->Identifier->find('neighbors', array('field' => 'id', 'value' => $identifier_id, 'conditions' => array('translation_file_id' => $identifier['Identifier']['translation_file_id'])));
76 if ($nextIdentifier = $identifierNeighbors['next'])
77 $this->redirect(array('action' => 'add', 'identifier_id' => $nextIdentifier['Identifier']['id']));
78 else
79 $this->redirect(array('controller' => 'identifiers', 'action' => 'index', 'translation_file_id' => $identifier['Identifier']['translation_file_id']));
81 else
82 $this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
83 } else {
84 $this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
87 if (empty($this->passedArgs['identifier_id']))
89 $this->Session->setFlash(__('You need to choose identifier for translation', true));
90 $this->redirect($this->referer());
92 else
94 $identifier_id = $this->passedArgs['identifier_id'];
95 $this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $identifier_id));
96 $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
97 $this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
98 if ($identifierColumns)
99 $this->set('identifierColumnsDetails', Set::combine($this->Translation->IdentifierColumn->find('all', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')), '{n}.IdentifierColumn.id', '{n}.IdentifierColumn'));
101 $users = $this->Translation->User->find('list');
102 $this->set(compact('identifiers', 'users'));
105 function edit($id = null) {
106 if (!$id && empty($this->data)) {
107 $this->Session->setFlash(__('Invalid translation', true));
108 $this->redirect(array('action' => 'index'));
110 if (!empty($this->data)) {
111 if ($this->data['ChildTranslation'])
113 unset($translationText);
114 foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
116 $ent['columns'][] = $childTranslation['translation_text'];
117 $translationText .= $childTranslation['translation_text'] . "\t";
119 $this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
121 else
122 $ent['string'] = $this->data['Translation']['translation_text'];
123 $this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
124 $this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
125 $this->data['Identifier']['translated'] = 1;
126 if ($this->Translation->saveAll($this->data)) {
127 $this->Session->setFlash(__('The translation has been saved', true));
128 $this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
129 } else {
130 $this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
133 $this->set('translation', $translation_data = $this->Translation->read(null, $id));
134 if (empty($this->data)) {
135 $this->data = $translation_data;
137 $identifier_id= $translation_data['Translation']['identifier_id'];
138 $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
139 $this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
140 if ($identifierColumns)
142 $contain = array('Translation' => array(
143 'conditions' => array('Translation.parent_id' => $translation_data['Translation']['id']),
145 $identifierColumnsAll = $this->Translation->IdentifierColumn->find('all', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id', 'contain' => $contain));
146 foreach ($translation_data['ChildTranslation'] as $childTranslationKey => $childTranslation)
148 $mapChildTranslationsColumns[$childTranslation['identifier_column_id']] = $childTranslationKey;
151 $this->set(compact('mapChildTranslationsColumns'));
152 $this->set('identifierColumnsDetails', Set::combine($identifierColumnsAll, '{n}.IdentifierColumn.id', '{n}.IdentifierColumn'));
153 $this->set('identifierColumnTranslations', Set::combine($translation_data['ChildTranslation'], '{n}.identifier_column_id'));//, '{n}.identifier_column_id'));
155 $identifier = $this->Translation->Identifier->read(null, $this->data['Translation']['identifier_id']);
156 $users = $this->Translation->User->find('list');
157 $this->set(compact('identifiers', 'users', 'identifier'));
160 function delete($id = null) {
161 if (!$id) {
162 $this->Session->setFlash(__('Invalid id for translation', true));
163 $this->redirect(array('action'=>'index'));
165 if ($this->Translation->delete($id)) {
166 $this->Session->setFlash(__('Translation deleted', true));
167 $this->redirect($this->referer());
169 $this->Session->setFlash(__('Translation was not deleted', true));
170 $this->redirect(array('action' => 'index'));
172 function admin_index() {
173 return $this->index();
176 function admin_setBest($id) {
177 if (!$id) {
178 $this->Session->setFlash(__('Invalid id for translation', true));
179 $this->redirect($this->referer());
181 if ($this->Translation->setBest($id))
182 $this->Session->setFlash(__('Set successful', true));
183 else
184 $this->Session->setFlash(__('Set error', true));
185 $this->redirect($this->referer());
188 function admin_view($id = null) {
189 return $this->view($id);
192 function admin_add() {
193 return $this->add();
196 function admin_edit($id = null) {
197 return $this->edit($id);
200 function admin_delete($id = null) {
201 if (!$id) {
202 $this->Session->setFlash(__('Invalid id for translation', true));
203 $this->redirect(array('action'=>'index'));
205 if ($this->Translation->delete($id)) {
206 $this->Session->setFlash(__('Translation deleted', true));
207 $this->redirect(array('action'=>'index'));
209 $this->Session->setFlash(__('Translation was not deleted', true));
210 $this->redirect(array('action' => 'index'));