Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / webtt / app / controllers / votes_controller.php
blob7a0e0bb9e134cd1098096a0f03f27a269cabc1f8
1 <?php
2 /*
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/>.
20 <?php
21 class VotesController extends AppController {
23 var $name = 'Votes';
25 function index() {
26 $this->Vote->recursive = 0;
27 $conditions = null;
28 if (isset($this->passedArgs['translation_id']) && $translation_id = $this->passedArgs['translation_id'])
29 $conditions = array('Vote.translation_id' => $translation_id);
30 $this->set('votes', $this->paginate($conditions));
33 function view($id = null) {
34 if (!$id) {
35 $this->Session->setFlash(__('Invalid vote', true));
36 $this->redirect(array('action' => 'index'));
38 $this->set('vote', $this->Vote->read(null, $id));
41 function add() {
42 if (!empty($this->data)) {
43 $this->Vote->create();
44 if ($this->Vote->save($this->data)) {
45 $this->Session->setFlash(__('The vote has been saved', true));
46 $this->redirect(array('action' => 'index'));
47 } else {
48 $this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
51 $translations = $this->Vote->Translation->find('list');
52 $users = $this->Vote->User->find('list');
53 $this->set(compact('translations', 'users'));
56 function vote() {
57 if (empty($this->passedArgs['translation_id']))
59 $this->Session->setFlash(__('You need to choose translation for your vote', true));
60 $this->redirect(array('controller' => 'translations', 'action' => 'index'));
62 else
64 $translation_id = $this->passedArgs['translation_id'];
65 $translation = $this->Vote->Translation->read(null, $translation_id);
66 if (!$translation)
68 $this->Session->setFlash(__("Translation doesn't exist.", true));
69 $this->redirect(array('controller' => 'translations', 'action' => 'index'));
71 $vote = array("Vote" => array(
72 'translation_id' => $translation_id,
73 'user_id' => $this->Auth->user('id'),
76 $this->Vote->create();
77 $this->Vote->save($vote);
78 $this->Session->setFlash(__('Vote added', true));
79 $this->redirect($this->referer());
83 function edit($id = null) {
84 if (!$id && empty($this->data)) {
85 $this->Session->setFlash(__('Invalid vote', true));
86 $this->redirect(array('action' => 'index'));
88 if (!empty($this->data)) {
89 if ($this->Vote->save($this->data)) {
90 $this->Session->setFlash(__('The vote has been saved', true));
91 $this->redirect(array('action' => 'index'));
92 } else {
93 $this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
96 if (empty($this->data)) {
97 $this->data = $this->Vote->read(null, $id);
99 $translations = $this->Vote->Translation->find('list');
100 $users = $this->Vote->User->find('list');
101 $this->set(compact('translations', 'users'));
104 function delete($id = null) {
105 if (!$id) {
106 $this->Session->setFlash(__('Invalid id for vote', true));
107 $this->redirect(array('action'=>'index'));
109 if ($this->Vote->delete($id)) {
110 $this->Session->setFlash(__('Vote deleted', true));
111 $this->redirect(array('action'=>'index'));
113 $this->Session->setFlash(__('Vote was not deleted', true));
114 $this->redirect(array('action' => 'index'));
116 function admin_index() {
117 $this->Vote->recursive = 0;
118 $this->set('votes', $this->paginate());
121 function admin_view($id = null) {
122 if (!$id) {
123 $this->Session->setFlash(__('Invalid vote', true));
124 $this->redirect(array('action' => 'index'));
126 $this->set('vote', $this->Vote->read(null, $id));
129 function admin_add() {
130 if (!empty($this->data)) {
131 $this->Vote->create();
132 if ($this->Vote->save($this->data)) {
133 $this->Session->setFlash(__('The vote has been saved', true));
134 $this->redirect(array('action' => 'index'));
135 } else {
136 $this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
139 $translations = $this->Vote->Translation->find('list');
140 $users = $this->Vote->User->find('list');
141 $this->set(compact('translations', 'users'));
144 function admin_edit($id = null) {
145 if (!$id && empty($this->data)) {
146 $this->Session->setFlash(__('Invalid vote', true));
147 $this->redirect(array('action' => 'index'));
149 if (!empty($this->data)) {
150 if ($this->Vote->save($this->data)) {
151 $this->Session->setFlash(__('The vote has been saved', true));
152 $this->redirect(array('action' => 'index'));
153 } else {
154 $this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
157 if (empty($this->data)) {
158 $this->data = $this->Vote->read(null, $id);
160 $translations = $this->Vote->Translation->find('list');
161 $users = $this->Vote->User->find('list');
162 $this->set(compact('translations', 'users'));
165 function admin_delete($id = null) {
166 if (!$id) {
167 $this->Session->setFlash(__('Invalid id for vote', true));
168 $this->redirect(array('action'=>'index'));
170 if ($this->Vote->delete($id)) {
171 $this->Session->setFlash(__('Vote deleted', true));
172 $this->redirect(array('action'=>'index'));
174 $this->Session->setFlash(__('Vote was not deleted', true));
175 $this->redirect(array('action' => 'index'));