PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 130 lines | 104 code | 7 blank | 19 comment | 22 complexity | a64d58cc7754e6649f421bfae7b4ecd4 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 IdentifiersController extends AppController {
  19. var $name = 'Identifiers';
  20. function index() {
  21. $this->Identifier->recursive = 0;
  22. $conditions = null;
  23. if (isset($this->passedArgs['language']) && $lang = $this->passedArgs['language'])
  24. $conditions = array('Identifier.language_id' => $lang);
  25. if (isset($this->passedArgs['translation_file_id']) && $translation_file_id = $this->passedArgs['translation_file_id'])
  26. $conditions = array('Identifier.translation_file_id' => $translation_file_id);
  27. $this->set('identifiers', $this->paginate($conditions));
  28. }
  29. function admin_withoutBestTranslation()
  30. {
  31. if (isset($this->passedArgs['imported_translation_file_id']) && $imported_translation_file_id = $this->passedArgs['imported_translation_file_id'])
  32. {
  33. $identifier_ids = $this->Identifier->withoutBestTranslation(array('ImportedTranslationFile.id' => $this->passedArgs['imported_translation_file_id']));
  34. if ($identifier_ids === false)
  35. {
  36. $this->Session->setFlash(__('Error: no conditions specified', true));
  37. }
  38. else
  39. {
  40. $conditions = array('Identifier.id' => $identifier_ids, 'BestTranslation.id' => NULL);
  41. $this->set('identifiers', $this->paginate($conditions));
  42. }
  43. // $this->log($this->Identifier->withoutBestTranslation(array('ImportedTranslationFile.id' => $this->passedArgs['imported_translation_file_id'])));
  44. // TOTHINK: try to achieve that with custom find with pagination
  45. }
  46. else
  47. {
  48. $this->Session->setFlash(__('No imported file specified', true));
  49. $this->redirect($this->referer());
  50. }
  51. $this->render('index');
  52. }
  53. function view($id = null) {
  54. if (!$id) {
  55. $this->Session->setFlash(__('Invalid identifier', true));
  56. $this->redirect(array('action' => 'index'));
  57. }
  58. $this->set('identifier', $identifier = $this->Identifier->read(null, $id));
  59. if ($identifier)
  60. $this->set('identifierNeighbours', $this->Identifier->getNeighbours($id));
  61. }
  62. function admin_index() {
  63. $this->Identifier->recursive = 0;
  64. $this->set('identifiers', $this->paginate());
  65. }
  66. function admin_view($id = null) {
  67. if (!$id) {
  68. $this->Session->setFlash(__('Invalid identifier', true));
  69. $this->redirect(array('action' => 'index'));
  70. }
  71. $this->set('identifier', $identifier = $this->Identifier->read(null, $id));
  72. if ($identifier)
  73. $this->set('identifierNeighbours', $this->Identifier->getNeighbours($id));
  74. }
  75. function admin_add() {
  76. if (!empty($this->data)) {
  77. $this->Identifier->create();
  78. if ($this->Identifier->save($this->data)) {
  79. $this->Session->setFlash(__('The identifier has been saved', true));
  80. $this->redirect(array('action' => 'index'));
  81. } else {
  82. $this->Session->setFlash(__('The identifier could not be saved. Please, try again.', true));
  83. }
  84. }
  85. $languages = $this->Identifier->Language->find('list');
  86. $this->set(compact('languages'));
  87. }
  88. function admin_edit($id = null) {
  89. if (!$id && empty($this->data)) {
  90. $this->Session->setFlash(__('Invalid identifier', true));
  91. $this->redirect(array('action' => 'index'));
  92. }
  93. if (!empty($this->data)) {
  94. if ($this->Identifier->save($this->data)) {
  95. $this->Session->setFlash(__('The identifier has been saved', true));
  96. $this->redirect(array('action' => 'index'));
  97. } else {
  98. $this->Session->setFlash(__('The identifier could not be saved. Please, try again.', true));
  99. }
  100. }
  101. $this->set('identifier', $identifier_data = $this->Identifier->read(null, $id));
  102. if (empty($this->data)) {
  103. $this->data = $identifier_data;
  104. }
  105. $languages = $this->Identifier->Language->find('list');
  106. $this->set(compact('languages'));
  107. }
  108. function admin_delete($id = null) {
  109. if (!$id) {
  110. $this->Session->setFlash(__('Invalid id for identifier', true));
  111. $this->redirect(array('action'=>'index'));
  112. }
  113. if ($this->Identifier->delete($id)) {
  114. $this->Session->setFlash(__('Identifier deleted', true));
  115. $this->redirect(array('action'=>'index'));
  116. }
  117. $this->Session->setFlash(__('Identifier was not deleted', true));
  118. $this->redirect(array('action' => 'index'));
  119. }
  120. }