PageRenderTime 25ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 164 lines | 135 code | 10 blank | 19 comment | 25 complexity | 64d8f6bbc7a3405ebbfbe4587973ab61 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 CommentsController extends AppController {
  19. var $name = 'Comments';
  20. function index() {
  21. $this->Comment->recursive = 0;
  22. $this->set('comments', $this->paginate());
  23. }
  24. function view($id = null) {
  25. if (!$id) {
  26. $this->Session->setFlash(__('Invalid comment', true));
  27. $this->redirect(array('action' => 'index'));
  28. }
  29. $this->set('comment', $this->Comment->read(null, $id));
  30. }
  31. function add() {
  32. if (!empty($this->data)) {
  33. $this->Comment->create();
  34. if ($this->Comment->save($this->data)) {
  35. $this->Session->setFlash(__('The comment has been saved', true));
  36. $this->redirect(array('action' => 'index'));
  37. } else {
  38. $this->Session->setFlash(__('The comment could not be saved. Please, try again.', true));
  39. }
  40. }
  41. if (empty($this->passedArgs['identifier_id']))
  42. {
  43. $this->Session->setFlash(__('You need to choose identifier to comment', true));
  44. $this->redirect(array('controller' => 'identifiers', 'action' => 'index'));
  45. }
  46. else
  47. {
  48. $identifier_id = $this->passedArgs['identifier_id'];
  49. $this->set('identifier', $identifier = $this->Comment->Identifier->read(null, $identifier_id));
  50. // $this->data['Translation.identifier_id'] = $identifier_id;
  51. }
  52. // $translations = $this->Comment->Translation->find('list');
  53. $identifiers = $this->Comment->Identifier->find('list');
  54. $users = $this->Comment->User->find('list');
  55. $this->set(compact('translations', 'identifiers', 'users'));
  56. }
  57. function edit($id = null) {
  58. if (!$id && empty($this->data)) {
  59. $this->Session->setFlash(__('Invalid comment', true));
  60. $this->redirect(array('action' => 'index'));
  61. }
  62. if (!empty($this->data)) {
  63. if ($this->Comment->save($this->data)) {
  64. $this->Session->setFlash(__('The comment has been saved', true));
  65. $this->redirect(array('action' => 'index'));
  66. } else {
  67. $this->Session->setFlash(__('The comment could not be saved. Please, try again.', true));
  68. }
  69. }
  70. $this->set('comment', $comment_data = $this->Comment->read(null, $id));
  71. if (empty($this->data)) {
  72. $this->data = $comment_data;
  73. }
  74. $translations = $this->Comment->Translation->find('list');
  75. $identifiers = $this->Comment->Identifier->find('list');
  76. $users = $this->Comment->User->find('list');
  77. $this->set(compact('translations', 'identifiers', 'users'));
  78. }
  79. function delete($id = null) {
  80. if (!$id) {
  81. $this->Session->setFlash(__('Invalid id for comment', true));
  82. $this->redirect(array('action'=>'index'));
  83. }
  84. if ($this->Comment->delete($id)) {
  85. $this->Session->setFlash(__('Comment deleted', true));
  86. $this->redirect(array('action'=>'index'));
  87. }
  88. $this->Session->setFlash(__('Comment was not deleted', true));
  89. $this->redirect(array('action' => 'index'));
  90. }
  91. function admin_index() {
  92. $this->Comment->recursive = 0;
  93. $this->set('comments', $this->paginate());
  94. }
  95. function admin_view($id = null) {
  96. if (!$id) {
  97. $this->Session->setFlash(__('Invalid comment', true));
  98. $this->redirect(array('action' => 'index'));
  99. }
  100. $this->set('comment', $this->Comment->read(null, $id));
  101. }
  102. function admin_add() {
  103. if (!empty($this->data)) {
  104. $this->Comment->create();
  105. if ($this->Comment->save($this->data)) {
  106. $this->Session->setFlash(__('The comment has been saved', true));
  107. $this->redirect(array('action' => 'index'));
  108. } else {
  109. $this->Session->setFlash(__('The comment could not be saved. Please, try again.', true));
  110. }
  111. }
  112. $translations = $this->Comment->Translation->find('list');
  113. $identifiers = $this->Comment->Identifier->find('list');
  114. $users = $this->Comment->User->find('list');
  115. $this->set(compact('translations', 'identifiers', 'users'));
  116. }
  117. function admin_edit($id = null) {
  118. if (!$id && empty($this->data)) {
  119. $this->Session->setFlash(__('Invalid comment', true));
  120. $this->redirect(array('action' => 'index'));
  121. }
  122. if (!empty($this->data)) {
  123. if ($this->Comment->save($this->data)) {
  124. $this->Session->setFlash(__('The comment has been saved', true));
  125. $this->redirect(array('action' => 'index'));
  126. } else {
  127. $this->Session->setFlash(__('The comment could not be saved. Please, try again.', true));
  128. }
  129. }
  130. $this->set('comment', $comment_data = $this->Comment->read(null, $id));
  131. if (empty($this->data)) {
  132. $this->data = $comment_data;
  133. }
  134. $translations = $this->Comment->Translation->find('list');
  135. $identifiers = $this->Comment->Identifier->find('list');
  136. $users = $this->Comment->User->find('list');
  137. $this->set(compact('translations', 'identifiers', 'users'));
  138. }
  139. function admin_delete($id = null) {
  140. if (!$id) {
  141. $this->Session->setFlash(__('Invalid id for comment', true));
  142. $this->redirect(array('action'=>'index'));
  143. }
  144. if ($this->Comment->delete($id)) {
  145. $this->Session->setFlash(__('Comment deleted', true));
  146. $this->redirect(array('action'=>'index'));
  147. }
  148. $this->Session->setFlash(__('Comment was not deleted', true));
  149. $this->redirect(array('action' => 'index'));
  150. }
  151. }