Location: PHPKode > projects > CenterFlow > app/controllers/tasks_controller.php
<?

class TasksController extends AppController
{
	var $name = 'Tasks';
	var $scaffold;
	var $helpers = array('Html','Ajax','Javascript','Time');

	function beforeFilter()
	{
		$this->checkSession();
	}

	/*function index()
	{
	// initial view
	$allData =  $this->Task->findAll();
	$new_data = array();
	$inprogress_data = array();
	$completed_data = array();
	foreach($allData as $data)
	{
	$task = $data['Task'];
	$my_status = str_replace(' ','',strtolower($task['status']));
	$my_array = $my_status.'_data';
	${$my_array}[] = $data;
	}
	$this->set('new_data',$new_data);
	$this->set('inprogress_data',$inprogress_data);
	$this->set('completed_data',$completed_data);
	}*/

	function undelete($id)
	{
		$this->Task->undelete($id);
	}

	function undelete_listing($project_id)
	{
		$conditions = array('Task.project_id'=>$project_id,
		'Task.status'=>'deleted');
		$allData = $this->Task->findAll($conditions,null,'modified desc',null,1);
		$this->set('project_id',$project_id);
		$this->set('data',$allData);
	}

	function full_listing($project_id,$person_id = NULL)
	{
		$conditions = array('Task.project_id'=>$project_id);
		$conditions['Task.status'] = array('new','in progress','completed','on hold','ready');
		if($person_id != NULL)
		{
			$conditions['Task.person_id'] = $person_id;
			$conditions['Task.status'] = "<> 'deleted'";
		}
		$allData = $this->Task->findAll($conditions,null,'priority asc');
		$new_data = array();
		$inprogress_data = array();
		$ready_data = array();
		$completed_data = array();
		foreach($allData as $data)
		{
			$task = $data['Task'];
			$my_status = str_replace(' ','',strtolower($task['status']));
			$my_array = $my_status.'_data';
			${$my_array}[] = $data;
		}
		$this->set('project_id',$project_id);
		$this->set('my_person_id', $this->Session->read('Person.id'));
		$this->set('data',array_merge($inprogress_data,$new_data,$ready_data,$onhold_data,$completed_data));
		$this->render('listing');

	}
	
	function listing($project_id, $person_id = NULL)
	{
		$conditions = array('Task.project_id'=>$project_id);
		$conditions['Task.status'] = array('new','in progress','ready');
		if($person_id != NULL)
		{
			$conditions['Task.person_id'] = $person_id;
			$conditions['Task.status'] = "not in ('deleted')";
		}
		$allData = $this->Task->findAll($conditions,null,'priority asc');
		$new_data = array();
		$inprogress_data = array();
		$ready_data = array();
		$completed_data = array();
		foreach($allData as $data)
		{
			$task = $data['Task'];
			$my_status = str_replace(' ','',strtolower($task['status']));

			$due = false;
			$data['Task']['due'] = $due;

			$tasks_data[] = $data;
		}

		//$conditions['Task.status'] = 'completed';
		//$completed_data = $this->Task->findAll($conditions,null,'modified desc',5);

		$this->set('project_id',$project_id);
		$this->set('my_person_id', $this->Session->read('Person.id'));
		$this->set('data',$tasks_data);
	}

	function list_one($id)
	{
		$this->Task->id = $id;
		$data = $this->Task->findById($id);
		$this->set('my_person_id', $this->Session->read('Person.id'));
		$this->set('data',$data);
		$this->layout = 'ajax';
	}

	function add($project_id)
	{
		$this->Task->id = 0;
		$this->set('data', array());
		$this->set('project_id',$project_id);
		$this->set('userlist',$this->requestAction("/people/userlist/0",array('return')));
		$this->set('projectlist',$this->requestAction("/projects/projectlist/$project_id",array('return')));
		$this->render('view', 'ajax');
	}

	function view($id)
	{
		$this->Task->id = $id;
		$data = $this->Task->findById($id);

		//Defunct date formatting, using Cake's Time helper instead
		/*list($start,$finished,$created,$modified) = array($data['Task']['start'],$data['Task']['finished'],$data['Task']['created'],$data['Task']['modified']);
		$start = ($start == ZERO_DATE) ? 'Has not started yet' : date("F j, Y, g:i a",strtotime($start));
		$finished = ($finished == ZERO_DATE) ? 'Has not finished yet' : date("F j, Y, g:i a",strtotime($finished));
		$created  = date("F j, Y, g:i a",strtotime($created));
		$modified  = date("F j, Y, g:i a",strtotime($modified));
		list($data['Task']['start'],$data['Task']['finished'],$data['Task']['created'],$data['Task']['modified']) = array($start,$finished,$created,$modified);*/

		$person_id = $data['Person']['id'];
		$project_id = $data['Project']['id'];
		$this->set('data', $data);
		$this->set('userlist',$this->requestAction("/people/userlist/$person_id",array('return')));
		$this->set('projectlist',$this->requestAction("/projects/projectlist/$project_id",array('return')));
		$this->set('my_person_id', $this->Session->read('Person.id'));
		$this->render('view', 'ajax');
	}

	function save($id)
	{
		//uses('sanitize');
		//$mrClean = new Sanitize();
		//$mrClean->cleanArray($this->params['data']);

		if(!is_numeric($id)){ $id = 0; $this->data['Task']['id'] = $id;}
		//if($id != 0)
		//{
		//$this->Task->id = $id;

		//}
		if(isset($this->params['form']['send']) && $this->params['form']['send'] == 'on')
		{
			$this->Task->send_email = true;
		}
		//If the save goes through, re-render the Todolist
		if ($this->Task->save($this->data['Task']))
		{
			if($id == 0) //adding new task
			{
				//$task = $this->params['data']['Task'];
				/*$this->listing($task['project_id']);
				$this->render('listing','ajax');*/
				$this->list_one($this->Task->id);
				$this->render('list_one','ajax');
			}
			else
			{
				$this->list_one($id);
				$this->render('list_one','ajax');
			}
			$project_id = $this->data['Task']['project_id'];
			//$this->Task->reOrderPriority($project_id);
		}
		else
		{
			$this->validateErrors();
			$this->set('error_msg','Invalid input');
			$this->view($id);
		}
	}

	function delete($id)
	{
		// deletes task from database
		$this->Task->set_deleted($id);
		/*pr($this->params);
		$this->listing($this->params['data']['Task']['project_id']);
		$this->render('listing','ajax');*/
	}

}

?>
Return current item: CenterFlow