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

Language PHP Lines 213
MD5 Hash 8436a887000500c9a30349510c396762 Estimated Cost $4,464 (why?)
Repository https://bitbucket.org/mattraykowski/ryzomcore_demoshard View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/*
	Ryzom Core Web-Based Translation Tool
	Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
?>
<?php
class TranslationsController extends AppController {

	var $name = 'Translations';

	function index() {
		$this->Translation->recursive = 0;
		$conditions = null;
		if (isset($this->passedArgs['identifier_id']) && $identifier = $this->passedArgs['identifier_id'])
			$conditions = array('Translation.identifier_id' => $identifier);
		$this->set('translations', $this->paginate($conditions));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid translation', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('translation', $translation = $this->Translation->read(null, $id));
		if (isset($translation['Translation']['identifier_id']))
		{
			$this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $translation['Translation']['identifier_id']));
			$this->set('columnTranslations', $columnTranslations = $this->Translation->find('all', array('conditions' => array('Translation.parent_id' => $translation['Translation']['id']), 'order' => 'Translation.id')));
		}
		if ($identifier_id = $translation['Translation']['identifier_id'])
			$this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Translation->create();
			if ($this->data['ChildTranslation'])
			{
				unset($translationText);
				foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
				{
					$ent['columns'][] = $childTranslation['translation_text'];
					$translationText .= $childTranslation['translation_text'] . "\t";
				}
				$this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
			}
			else
				$ent['string'] = $this->data['Translation']['translation_text'];
			sort($ent['columns']);
			$this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
			$this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
			$this->data['Identifier']['translated'] = 1;
			$res = $this->Translation->saveAll($this->data);
			$this->log($this->data);
			if ($res) {
				$this->Session->setFlash(__('The translation has been saved', true));
				if ($this->params['form']['Next'])
				{
					$identifier_id = $this->data['Translation']['identifier_id'];
					$identifier = $this->Translation->Identifier->read(null, $identifier_id);
					$identifierNeighbors = $this->Translation->Identifier->find('neighbors', array('field' => 'id', 'value' => $identifier_id, 'conditions' => array('translation_file_id' => $identifier['Identifier']['translation_file_id'])));
					if ($nextIdentifier = $identifierNeighbors['next'])
						$this->redirect(array('action' => 'add', 'identifier_id' => $nextIdentifier['Identifier']['id']));
					else
						$this->redirect(array('controller' => 'identifiers', 'action' => 'index', 'translation_file_id' => $identifier['Identifier']['translation_file_id']));
				}
				else
					$this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
			} else {
				$this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->passedArgs['identifier_id']))
		{
			$this->Session->setFlash(__('You need to choose identifier for translation', true));
			$this->redirect($this->referer());
		}
		else
		{
			$identifier_id = $this->passedArgs['identifier_id'];
			$this->set('identifier', $identifier = $this->Translation->Identifier->read(null, $identifier_id));
			$this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
			$this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
			if ($identifierColumns)
				$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'));
		}
		$users = $this->Translation->User->find('list');
		$this->set(compact('identifiers', 'users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid translation', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->data['ChildTranslation'])
			{
				unset($translationText);
				foreach ($this->data['ChildTranslation'] as $num => $childTranslation)
				{
					$ent['columns'][] = $childTranslation['translation_text'];
					$translationText .= $childTranslation['translation_text'] . "\t";
				}
				$this->data['Translation']['translation_text'] = substr($translationText, 0, -1);
			}
			else
				$ent['string'] = $this->data['Translation']['translation_text'];
			$this->data['Translation']['translation_hash'] = $this->Translation->makeHash($ent);
			$this->data['Identifier']['id'] = $this->data['Translation']['identifier_id'];
			$this->data['Identifier']['translated'] = 1;
			if ($this->Translation->saveAll($this->data)) {
				$this->Session->setFlash(__('The translation has been saved', true));
				$this->redirect(array('controller' => 'identifiers', 'action' => 'view', $this->data['Translation']['identifier_id']));
			} else {
				$this->Session->setFlash(__('The translation could not be saved. Please, try again.', true));
			}
		}
		$this->set('translation', $translation_data = $this->Translation->read(null, $id));
		if (empty($this->data)) {
			$this->data = $translation_data;
		}
		$identifier_id= $translation_data['Translation']['identifier_id'];
		$this->set('identifierNeighbours', $this->Translation->Identifier->getNeighbours($identifier_id));
		$this->set('identifierColumns', $identifierColumns = $this->Translation->IdentifierColumn->find('list', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id')));
		if ($identifierColumns)
		{
			$contain = array('Translation' => array(
				'conditions' => array('Translation.parent_id' => $translation_data['Translation']['id']),
			));
			$identifierColumnsAll = $this->Translation->IdentifierColumn->find('all', array('conditions' => array('identifier_id' => $identifier_id), 'order' => 'IdentifierColumn.id', 'contain' => $contain));
			foreach ($translation_data['ChildTranslation'] as $childTranslationKey => $childTranslation)
			{
				$mapChildTranslationsColumns[$childTranslation['identifier_column_id']] = $childTranslationKey;
				
			}
			$this->set(compact('mapChildTranslationsColumns'));
			$this->set('identifierColumnsDetails', Set::combine($identifierColumnsAll, '{n}.IdentifierColumn.id', '{n}.IdentifierColumn'));
			$this->set('identifierColumnTranslations', Set::combine($translation_data['ChildTranslation'], '{n}.identifier_column_id'));//, '{n}.identifier_column_id'));
		}
		$identifier = $this->Translation->Identifier->read(null, $this->data['Translation']['identifier_id']);
		$users = $this->Translation->User->find('list');
		$this->set(compact('identifiers', 'users', 'identifier'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for translation', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Translation->delete($id)) {
			$this->Session->setFlash(__('Translation deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Translation was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function admin_index() {
		return $this->index();
	}

	function admin_setBest($id) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for translation', true));
			$this->redirect($this->referer());
		}
		if ($this->Translation->setBest($id))
			$this->Session->setFlash(__('Set successful', true));
		else
			$this->Session->setFlash(__('Set error', true));
		$this->redirect($this->referer());
	}

	function admin_view($id = null) {
		return $this->view($id);
	}

	function admin_add() {
		return $this->add();
	}

	function admin_edit($id = null) {
		return $this->edit($id);
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for translation', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Translation->delete($id)) {
			$this->Session->setFlash(__('Translation deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Translation was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
Back to Top