<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class FavoritesController extends AppController {
var $name = 'Favorites';
var $helpers = array('Html', 'Form','Javascript','ajax','Pagination' ,'Time' );
var $uses = array('Favorite','Video','Picture','Pfavorite','User');
var $components = array ('Pagination');
function index() {
$this->Favorite->recursive = 0;
$this->set('favorites', $this->paginate());
}
function view($id = null) {
$data = $this->dolayout();
if(!$id) {
$id = $data['id'];
}
$condition = "`Category`.id = " . $id;
// debug($this->Category->Video->findall("`Category`.id = " . $id));
$condition =" `Video`.is_encoded = 1 AND `Favorite`.user_id = " . $id;
list($order,$limit,$page) = $this->Pagination->init($condition,array(''=>$id),array('page'=>$this->page,'show'=>$this->show));
$temp = $this->Favorite->findall($condition,NULL,NULL,$limit,$page);
$this->set('favvideos',$temp);
$this->set('id',$id);
$user = $this->User->findbyid($id);
$this->set('username',$user['User']['username']);
//rss
if(isset($this->params["named"]["output"]))
{
Configure::write('debug', '0');
if($this->params["named"]["output"]=="rss")
{
$setting = $this->Sitesetting->findbyid(1);
$this->set("ssetting",$setting["Sitesetting"]);
$this->render('rss','rss');
}
}
}
function pview($id = null) {
$data = $this->dolayout();
if(!$id) {
$id = $data['id'];
}
$condition = "`Category`.id = " . $id;
// debug($this->Category->Video->findall("`Category`.id = " . $id));
$condition =" `Picture`.is_corrupted = 1 AND `Favorite`.user_id = " . $id;
list($order,$limit,$page) = $this->Pagination->init($condition,array(''=>$id),array('page'=>$this->page,'show'=>$this->show));
$this->set('favpictures',$this->Pfavorite->findall($condition,NULL,NULL,$limit,$page));
$this->set('id',$id);
$user = $this->User->findbyid($id);
$this->set('username',$user['User']['username']);
//rss
if(isset($this->params["named"]["output"]))
{
Configure::write('debug', '0');
if($this->params["named"]["output"]=="rss")
{
$setting = $this->Sitesetting->findbyid(1);
$this->set("ssetting",$setting["Sitesetting"]);
$this->render('rss','rss');
}
}
}
function add() {
if(!empty($this->data)) {
$this->cleanUpFields();
$favorite = $this->Favorite->findcount("`Favorite`.user_id = " . $this->data["Favorite"]["user_id"] . " and `Favorite`.video_id = " . $this->data["Favorite"]["video_id"]) ;
if ((int)$favorite > 0 )
{
$this->Session->setFlash('Try Harder to Favit again');
die();
}
$this->Favorite->create();
if($this->Favorite->save($this->data)) {
$this->Session->setFlash('The Favorite has been saved');
Configure::write('debug', '0');
$this->layout= false;
$this->render('thankyou');
} else {
$this->Session->setFlash('The Favorite could not be saved. Please, try again.');
}
}
$users = $this->Favorite->User->find('list');
$videos = $this->Favorite->Video->find('list');
$this->set(compact('users', 'videos'));
}
function edit($id = null) {
if(!$id && empty($this->data)) {
$this->Session->setFlash('Invalid Favorite');
$this->redirect(array('action'=>'index'), null, true);
}
if(!empty($this->data)) {
$this->cleanUpFields();
if($this->Favorite->save($this->data)) {
$this->Session->setFlash('The Favorite saved');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The Favorite could not be saved. Please, try again.');
}
}
if(empty($this->data)) {
$this->data = $this->Favorite->read(null, $id);
}
$users = $this->Favorite->User->find('list');
$videos = $this->Favorite->Video->find('list');
$this->set(compact('users','videos'));
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid id for Favorite');
$this->redirect(array('action'=>'index'), null, true);
}
$favorite = $this->Favorite->findbyid($id);
$data = $this->Session->read('User');
$priv = $data["privilege"];
if($data['id'] != $favorite["Favorite"]["user_id"])
die();
if($this->Favorite->del($id)) {
$this->Session->setFlash('Favorite #'.$id.' deleted');
Configure::write('debug', '0');
$this->layout= false;
$this->render('removed');
}
}
}
?>