PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/code/ryzom/tools/server/www/webtt/app/controllers/translations_controller.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 212 lines | 183 code | 12 blank | 17 comment | 27 complexity | 8436a887000500c9a30349510c396762 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. Ryzom Core Web-Based Translation Tool
  4. Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. ?>
  17. <?php
  18. class TranslationsController extends AppController {
  19. var $name = 'Translations';
  20. function index() {
  21. $this->Translation->recursive = 0;
  22. $conditions = null;
  23. if (isset($this->passedArgs['identifier_id']) && $identifier = $this->passedArgs['identifier_id'])
  24. $conditions = array('Translation.identifier_id' => $identifier);
  25. $this->set('translations', $this->paginate($conditions));
  26. }
  27. function view($id = null) {
  28. if (!$id) {
  29. $this->Session->setFlash(__('Invalid translation', true));
  30. $this->redirect(array('action' => 'index'));
  31. }
  32. $this->set('translation', $translation = $this->Translation->read(null, $id));
  33. if (isset($translation['Translation']['identifier_id']))
  34. {
  35. $this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $translation['Translation']['identifier_id']));
  36. $this->set('columnTranslations', $columnTranslations = $this->Translation->find('all', array('conditions' => array('Translation.parent_id' => $translation['Translation']['id']), 'order' => 'Translation.id')));
  37. }
  38. if ($identifier_id = $translation['Translation']['identifier_id'])
  39. $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
  40. }
  41. function add() {
  42. if (!empty($this->data)) {
  43. $this->Translation->create();
  44. if ($this->data['ChildTranslation'])
  45. {
  46. unset($translationText);
  47. foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
  48. {
  49. $ent['columns'][] = $childTranslation['translation_text'];
  50. $translationText .= $childTranslation['translation_text'] . "\t";
  51. }
  52. $this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
  53. }
  54. else
  55. $ent['string'] = $this->data['Translation']['translation_text'];
  56. sort($ent['columns']);
  57. $this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
  58. $this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
  59. $this->data['Identifier']['translated'] = 1;
  60. $res = $this->Translation->saveAll($this->data);
  61. $this->log($this->data);
  62. if ($res) {
  63. $this->Session->setFlash(__('The translation has been saved', true));
  64. if ($this->params['form']['Next'])
  65. {
  66. $identifier_id = $this->data['Translation']['identifier_id'];
  67. $identifier = $this->Translation->Identifier->read(null, $identifier_id);
  68. $identifierNeighbors = $this->Translation->Identifier->find('neighbors', array('field' => 'id', 'value' => $identifier_id, 'conditions' => array('translation_file_id' => $identifier['Identifier']['translation_file_id'])));
  69. if ($nextIdentifier = $identifierNeighbors['next'])
  70. $this->redirect(array('action' => 'add', 'identifier_id' => $nextIdentifier['Identifier']['id']));
  71. else
  72. $this->redirect(array('controller' => 'identifiers', 'action' => 'index', 'translation_file_id' => $identifier['Identifier']['translation_file_id']));
  73. }
  74. else
  75. $this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
  76. } else {
  77. $this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
  78. }
  79. }
  80. if (empty($this->passedArgs['identifier_id']))
  81. {
  82. $this->Session->setFlash(__('You need to choose identifier for translation', true));
  83. $this->redirect($this->referer());
  84. }
  85. else
  86. {
  87. $identifier_id = $this->passedArgs['identifier_id'];
  88. $this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $identifier_id));
  89. $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
  90. $this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
  91. if ($identifierColumns)
  92. $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'));
  93. }
  94. $users = $this->Translation->User->find('list');
  95. $this->set(compact('identifiers', 'users'));
  96. }
  97. function edit($id = null) {
  98. if (!$id && empty($this->data)) {
  99. $this->Session->setFlash(__('Invalid translation', true));
  100. $this->redirect(array('action' => 'index'));
  101. }
  102. if (!empty($this->data)) {
  103. if ($this->data['ChildTranslation'])
  104. {
  105. unset($translationText);
  106. foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
  107. {
  108. $ent['columns'][] = $childTranslation['translation_text'];
  109. $translationText .= $childTranslation['translation_text'] . "\t";
  110. }
  111. $this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
  112. }
  113. else
  114. $ent['string'] = $this->data['Translation']['translation_text'];
  115. $this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
  116. $this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
  117. $this->data['Identifier']['translated'] = 1;
  118. if ($this->Translation->saveAll($this->data)) {
  119. $this->Session->setFlash(__('The translation has been saved', true));
  120. $this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
  121. } else {
  122. $this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
  123. }
  124. }
  125. $this->set('translation', $translation_data = $this->Translation->read(null, $id));
  126. if (empty($this->data)) {
  127. $this->data = $translation_data;
  128. }
  129. $identifier_id= $translation_data['Translation']['identifier_id'];
  130. $this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
  131. $this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
  132. if ($identifierColumns)
  133. {
  134. $contain = array('Translation' => array(
  135. 'conditions' => array('Translation.parent_id' => $translation_data['Translation']['id']),
  136. ));
  137. $identifierColumnsAll = $this->Translation->IdentifierColumn->find('all', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id', 'contain' => $contain));
  138. foreach ($translation_data['ChildTranslation'] as $childTranslationKey => $childTranslation)
  139. {
  140. $mapChildTranslationsColumns[$childTranslation['identifier_column_id']] = $childTranslationKey;
  141. }
  142. $this->set(compact('mapChildTranslationsColumns'));
  143. $this->set('identifierColumnsDetails', Set::combine($identifierColumnsAll, '{n}.IdentifierColumn.id', '{n}.IdentifierColumn'));
  144. $this->set('identifierColumnTranslations', Set::combine($translation_data['ChildTranslation'], '{n}.identifier_column_id'));//, '{n}.identifier_column_id'));
  145. }
  146. $identifier = $this->Translation->Identifier->read(null, $this->data['Translation']['identifier_id']);
  147. $users = $this->Translation->User->find('list');
  148. $this->set(compact('identifiers', 'users', 'identifier'));
  149. }
  150. function delete($id = null) {
  151. if (!$id) {
  152. $this->Session->setFlash(__('Invalid id for translation', true));
  153. $this->redirect(array('action'=>'index'));
  154. }
  155. if ($this->Translation->delete($id)) {
  156. $this->Session->setFlash(__('Translation deleted', true));
  157. $this->redirect($this->referer());
  158. }
  159. $this->Session->setFlash(__('Translation was not deleted', true));
  160. $this->redirect(array('action' => 'index'));
  161. }
  162. function admin_index() {
  163. return $this->index();
  164. }
  165. function admin_setBest($id) {
  166. if (!$id) {
  167. $this->Session->setFlash(__('Invalid id for translation', true));
  168. $this->redirect($this->referer());
  169. }
  170. if ($this->Translation->setBest($id))
  171. $this->Session->setFlash(__('Set successful', true));
  172. else
  173. $this->Session->setFlash(__('Set error', true));
  174. $this->redirect($this->referer());
  175. }
  176. function admin_view($id = null) {
  177. return $this->view($id);
  178. }
  179. function admin_add() {
  180. return $this->add();
  181. }
  182. function admin_edit($id = null) {
  183. return $this->edit($id);
  184. }
  185. function admin_delete($id = null) {
  186. if (!$id) {
  187. $this->Session->setFlash(__('Invalid id for translation', true));
  188. $this->redirect(array('action'=>'index'));
  189. }
  190. if ($this->Translation->delete($id)) {
  191. $this->Session->setFlash(__('Translation deleted', true));
  192. $this->redirect(array('action'=>'index'));
  193. }
  194. $this->Session->setFlash(__('Translation was not deleted', true));
  195. $this->redirect(array('action' => 'index'));
  196. }
  197. }