PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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