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/>.
21 class CommentsController
extends AppController
{
23 var $name = 'Comments';
26 $this->Comment
->recursive
= 0;
27 $this->set('comments', $this->paginate());
30 function view($id = null) {
32 $this->Session
->setFlash(__('Invalid comment', true));
33 $this->redirect(array('action' => 'index'));
35 $this->set('comment', $this->Comment
->read(null, $id));
39 if (!empty($this->data
)) {
40 $this->Comment
->create();
41 if ($this->Comment
->save($this->data
)) {
42 $this->Session
->setFlash(__('The comment has been saved', true));
43 $this->redirect(array('action' => 'index'));
45 $this->Session
->setFlash(__('The comment could not be saved. Please, try again.', true));
48 if (empty($this->passedArgs
['identifier_id']))
50 $this->Session
->setFlash(__('You need to choose identifier to comment', true));
51 $this->redirect(array('controller' => 'identifiers', 'action' => 'index'));
55 $identifier_id = $this->passedArgs
['identifier_id'];
56 $this->set('identifier', $identifier = $this->Comment
->Identifier
->read(null, $identifier_id));
57 // $this->data['Translation.identifier_id'] = $identifier_id;
59 // $translations = $this->Comment->Translation->find('list');
60 $identifiers = $this->Comment
->Identifier
->find('list');
61 $users = $this->Comment
->User
->find('list');
62 $this->set(compact('translations', 'identifiers', 'users'));
65 function edit($id = null) {
66 if (!$id && empty($this->data
)) {
67 $this->Session
->setFlash(__('Invalid comment', true));
68 $this->redirect(array('action' => 'index'));
70 if (!empty($this->data
)) {
71 if ($this->Comment
->save($this->data
)) {
72 $this->Session
->setFlash(__('The comment has been saved', true));
73 $this->redirect(array('action' => 'index'));
75 $this->Session
->setFlash(__('The comment could not be saved. Please, try again.', true));
78 $this->set('comment', $comment_data = $this->Comment
->read(null, $id));
79 if (empty($this->data
)) {
80 $this->data
= $comment_data;
82 $translations = $this->Comment
->Translation
->find('list');
83 $identifiers = $this->Comment
->Identifier
->find('list');
84 $users = $this->Comment
->User
->find('list');
85 $this->set(compact('translations', 'identifiers', 'users'));
88 function delete($id = null) {
90 $this->Session
->setFlash(__('Invalid id for comment', true));
91 $this->redirect(array('action'=>'index'));
93 if ($this->Comment
->delete($id)) {
94 $this->Session
->setFlash(__('Comment deleted', true));
95 $this->redirect(array('action'=>'index'));
97 $this->Session
->setFlash(__('Comment was not deleted', true));
98 $this->redirect(array('action' => 'index'));
100 function admin_index() {
101 $this->Comment
->recursive
= 0;
102 $this->set('comments', $this->paginate());
105 function admin_view($id = null) {
107 $this->Session
->setFlash(__('Invalid comment', true));
108 $this->redirect(array('action' => 'index'));
110 $this->set('comment', $this->Comment
->read(null, $id));
113 function admin_add() {
114 if (!empty($this->data
)) {
115 $this->Comment
->create();
116 if ($this->Comment
->save($this->data
)) {
117 $this->Session
->setFlash(__('The comment has been saved', true));
118 $this->redirect(array('action' => 'index'));
120 $this->Session
->setFlash(__('The comment could not be saved. Please, try again.', true));
123 $translations = $this->Comment
->Translation
->find('list');
124 $identifiers = $this->Comment
->Identifier
->find('list');
125 $users = $this->Comment
->User
->find('list');
126 $this->set(compact('translations', 'identifiers', 'users'));
129 function admin_edit($id = null) {
130 if (!$id && empty($this->data
)) {
131 $this->Session
->setFlash(__('Invalid comment', true));
132 $this->redirect(array('action' => 'index'));
134 if (!empty($this->data
)) {
135 if ($this->Comment
->save($this->data
)) {
136 $this->Session
->setFlash(__('The comment has been saved', true));
137 $this->redirect(array('action' => 'index'));
139 $this->Session
->setFlash(__('The comment could not be saved. Please, try again.', true));
142 $this->set('comment', $comment_data = $this->Comment
->read(null, $id));
143 if (empty($this->data
)) {
144 $this->data
= $comment_data;
146 $translations = $this->Comment
->Translation
->find('list');
147 $identifiers = $this->Comment
->Identifier
->find('list');
148 $users = $this->Comment
->User
->find('list');
149 $this->set(compact('translations', 'identifiers', 'users'));
152 function admin_delete($id = null) {
154 $this->Session
->setFlash(__('Invalid id for comment', true));
155 $this->redirect(array('action'=>'index'));
157 if ($this->Comment
->delete($id)) {
158 $this->Session
->setFlash(__('Comment deleted', true));
159 $this->redirect(array('action'=>'index'));
161 $this->Session
->setFlash(__('Comment was not deleted', true));
162 $this->redirect(array('action' => 'index'));