<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class RatingsController extends AppController {
var $name = 'Ratings';
var $helpers = array('Html', 'Form' );
var $uses = array('Rating');
function index() {
$this->Rating->recursive = 0;
$this->set('ratings', $this->paginate());
}
function view($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid Rating.');
$this->redirect(array('action'=>'index'), null, true);
}
$this->set('rating', $this->Rating->read(null, $id));
}
function add() {
if(!empty($this->data)) {
$this->cleanUpFields();
$rating = $this->Rating->findcount("`Rating`.user_id = " . $this->data["Rating"]["user_id"] . " and `Rating`.video_id = " . $this->data["Rating"]["video_id"]) ;
if ((int)$rating > 0 )
{
$this->Session->setFlash('Try Harder to rate again');
die();
}
$this->Rating->create();
if($this->Rating->save($this->data)) {
$this->Session->setFlash('The Rating has been saved');
Configure::write('debug', '0');
$this->layout= false;
$this->render('thankyou');
} else {
$this->Session->setFlash('The Rating could not be saved. Please, try again.');
}
}
$videos = $this->Rating->Video->find('list');
$users = $this->Rating->User->find('list');
$this->set(compact('videos', 'users'));
}
function edit($id = null) {
if(!$id && empty($this->data)) {
$this->Session->setFlash('Invalid Rating');
$this->redirect(array('action'=>'index'), null, true);
}
if(!empty($this->data)) {
$this->cleanUpFields();
if($this->Rating->save($this->data)) {
$this->Session->setFlash('The Rating saved');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The Rating could not be saved. Please, try again.');
}
}
if(empty($this->data)) {
$this->data = $this->Rating->read(null, $id);
}
$videos = $this->Rating->Video->find('list');
$users = $this->Rating->User->find('list');
$this->set(compact('videos','users'));
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid id for Rating');
$this->redirect(array('action'=>'index'), null, true);
}
if($this->Rating->del($id)) {
$this->Session->setFlash('Rating #'.$id.' deleted');
$this->redirect(array('action'=>'index'), null, true);
}
}
}
?>