<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class PratingsController extends AppController {
var $name = 'Pratings';
var $helpers = array('Html', 'Form' );
var $uses = array('Prating');
function index() {
$this->Prating->recursive = 0;
$this->set('pratings', $this->paginate());
}
function view($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid rating.');
$this->redirect(array('action'=>'index'), null, true);
}
$this->set('prating', $this->Prating->read(null, $id));
}
function add() {
if(!empty($this->data)) {
$this->cleanUpFields();
$prating = $this->Prating->findcount("`Prating`.user_id = " . $this->data["Prating"]["user_id"] . " and `Prating`.picture_id = " . $this->data["Prating"]["picture_id"]) ;
if ((int)$prating > 0 )
{
$this->Session->setFlash('Try Harder to rate again');
die();
}
$this->Prating->create();
if($this->Prating->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.');
}
}
$pictures = $this->Prating->Picture->find('list');
$users = $this->Prating->User->find('list');
$this->set(compact('pictures', 'users'));
}
function edit($id = null) {
if(!$id && empty($this->data)) {
$this->Session->setFlash('Invalid Prating');
$this->redirect(array('action'=>'index'), null, true);
}
if(!empty($this->data)) {
$this->cleanUpFields();
if($this->Prating->save($this->data)) {
$this->Session->setFlash('The Prating saved');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The Prating could not be saved. Please, try again.');
}
}
if(empty($this->data)) {
$this->data = $this->Prating->read(null, $id);
}
$pictures = $this->Prating->Picture->find('list');
$users = $this->Prating->User->find('list');
$this->set(compact('pictures','users'));
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid id for Prating');
$this->redirect(array('action'=>'index'), null, true);
}
if($this->Prating->del($id)) {
$this->Session->setFlash('Prating #'.$id.' deleted');
$this->redirect(array('action'=>'index'), null, true);
}
}
}
?>