2011-06-09 16:23:29 +00:00
|
|
|
<?php
|
2011-08-21 00:54:22 +00:00
|
|
|
/*
|
|
|
|
Ryzom Core Web-Based Translation Tool
|
|
|
|
Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
?>
|
|
|
|
<?php
|
2011-06-09 16:23:29 +00:00
|
|
|
class VotesController extends AppController {
|
|
|
|
|
|
|
|
var $name = 'Votes';
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
$this->Vote->recursive = 0;
|
2011-08-21 00:54:22 +00:00
|
|
|
$conditions = null;
|
|
|
|
if (isset($this->passedArgs['translation_id']) && $translation_id = $this->passedArgs['translation_id'])
|
|
|
|
$conditions = array('Vote.translation_id' => $translation_id);
|
|
|
|
$this->set('votes', $this->paginate($conditions));
|
2011-06-09 16:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
if (!$id) {
|
|
|
|
$this->Session->setFlash(__('Invalid vote', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
$this->set('vote', $this->Vote->read(null, $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
$this->Vote->create();
|
|
|
|
if ($this->Vote->save($this->data)) {
|
|
|
|
$this->Session->setFlash(__('The vote has been saved', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$translations = $this->Vote->Translation->find('list');
|
|
|
|
$users = $this->Vote->User->find('list');
|
|
|
|
$this->set(compact('translations', 'users'));
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:49:25 +00:00
|
|
|
function vote() {
|
2011-08-21 00:54:22 +00:00
|
|
|
if (empty($this->passedArgs['translation_id']))
|
2011-07-14 14:49:25 +00:00
|
|
|
{
|
|
|
|
$this->Session->setFlash(__('You need to choose translation for your vote', true));
|
|
|
|
$this->redirect(array('controller' => 'translations', 'action' => 'index'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-21 00:54:22 +00:00
|
|
|
$translation_id = $this->passedArgs['translation_id'];
|
2011-07-14 14:49:25 +00:00
|
|
|
$translation = $this->Vote->Translation->read(null, $translation_id);
|
|
|
|
if (!$translation)
|
|
|
|
{
|
|
|
|
$this->Session->setFlash(__("Translation doesn't exist.", true));
|
|
|
|
$this->redirect(array('controller' => 'translations', 'action' => 'index'));
|
|
|
|
}
|
|
|
|
$vote = array("Vote" => array(
|
|
|
|
'translation_id' => $translation_id,
|
2011-08-21 00:54:22 +00:00
|
|
|
'user_id' => $this->Auth->user('id'),
|
2011-07-14 14:49:25 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->Vote->create();
|
|
|
|
$this->Vote->save($vote);
|
|
|
|
$this->Session->setFlash(__('Vote added', true));
|
2011-08-21 00:54:22 +00:00
|
|
|
$this->redirect($this->referer());
|
2011-07-14 14:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 16:23:29 +00:00
|
|
|
function edit($id = null) {
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
$this->Session->setFlash(__('Invalid vote', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
if ($this->Vote->save($this->data)) {
|
|
|
|
$this->Session->setFlash(__('The vote has been saved', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($this->data)) {
|
|
|
|
$this->data = $this->Vote->read(null, $id);
|
|
|
|
}
|
|
|
|
$translations = $this->Vote->Translation->find('list');
|
|
|
|
$users = $this->Vote->User->find('list');
|
|
|
|
$this->set(compact('translations', 'users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete($id = null) {
|
|
|
|
if (!$id) {
|
|
|
|
$this->Session->setFlash(__('Invalid id for vote', true));
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
}
|
|
|
|
if ($this->Vote->delete($id)) {
|
|
|
|
$this->Session->setFlash(__('Vote deleted', true));
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
}
|
|
|
|
$this->Session->setFlash(__('Vote was not deleted', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
function admin_index() {
|
|
|
|
$this->Vote->recursive = 0;
|
|
|
|
$this->set('votes', $this->paginate());
|
|
|
|
}
|
|
|
|
|
|
|
|
function admin_view($id = null) {
|
|
|
|
if (!$id) {
|
|
|
|
$this->Session->setFlash(__('Invalid vote', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
$this->set('vote', $this->Vote->read(null, $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
function admin_add() {
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
$this->Vote->create();
|
|
|
|
if ($this->Vote->save($this->data)) {
|
|
|
|
$this->Session->setFlash(__('The vote has been saved', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$translations = $this->Vote->Translation->find('list');
|
|
|
|
$users = $this->Vote->User->find('list');
|
|
|
|
$this->set(compact('translations', 'users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function admin_edit($id = null) {
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
$this->Session->setFlash(__('Invalid vote', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
if ($this->Vote->save($this->data)) {
|
|
|
|
$this->Session->setFlash(__('The vote has been saved', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
$this->Session->setFlash(__('The vote could not be saved. Please, try again.', true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($this->data)) {
|
|
|
|
$this->data = $this->Vote->read(null, $id);
|
|
|
|
}
|
|
|
|
$translations = $this->Vote->Translation->find('list');
|
|
|
|
$users = $this->Vote->User->find('list');
|
|
|
|
$this->set(compact('translations', 'users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function admin_delete($id = null) {
|
|
|
|
if (!$id) {
|
|
|
|
$this->Session->setFlash(__('Invalid id for vote', true));
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
}
|
|
|
|
if ($this->Vote->delete($id)) {
|
|
|
|
$this->Session->setFlash(__('Vote deleted', true));
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
}
|
|
|
|
$this->Session->setFlash(__('Vote was not deleted', true));
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
|
|
|
}
|