Location: PHPKode > projects > OSShare > osshare-project-v1.0.1/app/controllers/profiles_controller.php
<?php
/*
OsShare v1 , 
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class ProfilesController extends AppController {

	var $name = 'Profiles';
	var $helpers = array('Html', 'Form', 'Javascript','Ajax' );
	var $uses = array('Profile','Video','Pl','Alb','Picture','User');
	var $layout = "user";
	function index() {
		$this->Profile->recursive = 0;
		$this->set('profiles', $this->paginate());
	}

	function view($id = null) {
	
		$user = $this->dolayout();
		
		$profileofid = $this->Profile->findbyuser_id($id);
		$id = $profileofid["Profile"]["user_id"];
		
		if(!$id) {
			$this->Session->setFlash('Invalid Profile.');
			$this->redirect(array('action'=>'index'), null, true);
		}
		$lvideo = Cache::read('profile_lvideo'.$id);
		if($lvideo == false)
		{
		$lvideo = $this->Video->find("`Video`.is_encoded = 1 AND `Video`.user_id = " . $id , NULL  ,"`Video`.id DESC", NULL );
		Cache::write('profile_lvideo'.$id,$lvideo,'+1 hour');
		}
		//$lvideo = $this->Video->find("`Video`.is_encoded = 1 AND `Video`.user_id = " . $id , NULL  ,"`Video`.id DESC", NULL );
		$this->set('video',$lvideo);
		$allvideo = Cache::read('pro_allvid'.$id);
		if($allvideo == false)
		{
		$allvideo = $this->Video->findall("`Video`.is_encoded = 1 AND `Video`.user_id = " . $id,null,null,6,null);
		$allvideo = $this->fix_width($allvideo,'Video','name',10);
		$allvideo = $this->fix_width($allvideo,'User','username',5);		
		Cache::write('pro_allvid'.$id,$allvideo,'+1 hour');
		}
//		$allvideo = $this->Video->findall("`Video`.is_encoded = 1 AND `Video`.user_id = " . $id,null,null,6,null);
		$this->set('allvideo',$allvideo);
		$allplaylist = Cache::read('pro_allplay'.$id);
		if($allplaylist == false)
		{
		$allplaylist = $this->Pl->findallbyuser_id($id,null,null,10);
		Cache::write('pro_allplay'.$id,$allplaylist,'+1 hour');
		}
		//$allplaylist = $this->Pl->findallbyuser_id($id,null,null,10);
		$this->set('allplaylist',$allplaylist);
		$allalbum = Cache::read('pro_allalb'.$id);
		if($allalbum == false)
		{
			$allalbum = $this->Alb->findallbyuser_id($id,null,null,10);
			Cache::write('pro_allalb'.$id,$allalbum,'+1 hour');
		}
//		$allalbum = $this->Alb->findallbyuser_id($id,null,null,10);
		$this->set('allalbum',$allalbum);
		$favvideo = Cache::read('pro_favvideo'.$id);
		if($favvideo == false)
		{
		$favvideo = $this->Video->Favorite->findall("`Video`.is_encoded = 1 AND `Favorite`.user_id = " . $id,null,null,9,null );
		$favvideo = $this->fix_width($favvideo,'Video','name',10);
		$favvideo = $this->fix_width($favvideo,'User','username',5);
		Cache::write('pro_favvideo'.$id,$favvideo,'+1 hour');
		}
//		$favvideo = $this->Video->Favorite->findall("`Video`.is_encoded = 1 AND `Favorite`.user_id = " . $id,null,null,9,null );
		$this->set('favvideo',$favvideo);

		$this->set('profile', $this->Profile->read(null, $id));
		
		$this->set('user',$user);
		$this->set('photo', $this->User->read(null, $id));
		$this->set('settings',$this->ssettings);
	}

	function add() {
		if(!empty($this->data)) {
			$this->cleanUpFields();
			$this->Profile->create();
			print_r($this->data);
			die();
			if($this->Profile->save($this->data)) {
				$this->Session->setFlash('The Profile has been saved');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('The Profile could not be saved. Please, try again.');
			}
		}
		$users = $this->Profile->User->find('list');
		$this->set(compact('users'));
	}

	function edit($id = null) {
	
	$data = $this->dolayout();
	$priv = $data["privilege"];
	$this->set('user1', $this->User->read(null, $data["id"]));
	if ($priv=='user')
	{
		$profileofid = $this->Profile->findbyuser_id($data["id"]);
		$id = $profileofid["Profile"]["id"];
		$this->set('user',1);
	}
	else
	{
		if($id==null)
		{
		$profileofid = $this->Profile->findbyuser_id($data["id"]);
		$id = $profileofid["Profile"]["id"];
		$this->set('user',1);
		
		}
	}
	
		if(!$id && empty($this->data) && !$data ) {
			$this->Session->setFlash('Invalid Profile');
			$this->redirect(array('action'=>'index'), null, true);
		}
		
		
		if(!empty($this->data)) {
			$this->cleanUpFields();
			if($this->Profile->save($this->data)) {
				$this->Session->setFlash('The Profile saved');
				$this->redirect(array('profiles'=>'users','action'=>'edit'), null, true);
			} else {
				$this->Session->setFlash('The Profile could not be saved. Please, try again.');
			}
		}
		if(empty($this->data)) {
			$this->data = $this->Profile->read(null, $id);
		}
		
	}

	function delete($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid id for Profile');
			$this->redirect(array('action'=>'index'), null, true);
		}
		if($this->Profile->del($id)) {
			$this->Session->setFlash('Profile #'.$id.' deleted');
			$this->redirect(array('action'=>'index'), null, true);
		}
	}

}
?>
Return current item: OSShare