Menu
Index > Helpers

todoValueStatus

todoValueStatus($data, $options = array())

Description:
Returns array:
array(
'status' => null
, 'class' => null
, 'complete' => false
,
)

Options:
(array) $data - the TodoValue with 'TodoValue' as an array key or the TodoValue.id
(array) $options - not employed.

Example:
//
$todoValueStatus= $this->Deals->todoValueStatus($data);
// Status - string
echo 'This Todo is ' . $todoValueStatus['status'] . '.';
// Class - string
echo 'This Todo is ' . $todoValueStatus['class'] . '.';
// Complete - Boolean
echo 'This Todo is ' . ($todoValueStatus['complete'] ? 'complete' : 'incomplete') . '.';

/**
 * A wrapper to use all the todoValue* checks.
 * 
 * $data	array() TodoValue
 * return	array()
 */
	public function todoValueStatus($data, $options = array()) {
		//
		$return		= array(
					'status'	=> null
					, 'class'	=> null
					, 'complete'	=> false
					,
				);
		//
		if (is_numeric($data)) {
			//
			$data	= $this->find(
					'first'
					, array(
						'conditions'	=> array(
							$this->alias . '.' . $this->primaryKey	=> $data
							,
						)
						, 'contain'	=> array(
							'Document'
							,
						)
						,
					)
				);
		}
		//
		if (!$data) {
			//
			return	$return;
		}
		//
		$defaults	= array();
		//
		$options	= am($defaults , $options);
		//
		if ($this->todoValueDone($data)) {
			//
			$return['status']	= 'complete';
			//
			$return['class']	= 'todo-value-status-complete';
			//
			$return['complete']	= true;
		// 
		} elseif ($this->todoValueLate($data)) {
			//
			$return['status']	= 'late';
			//
			$return['class']	= 'todo-value-status-late';
		// 
		} elseif ($this->todoValuePending($data)) {
			//
			$return['status']	= 'pending';
			//
			$return['class']	= 'todo-value-status-pending';
		// 
		} else { //if ($this->todoValueCurrent($data)) {
			//
			$return['status']	= 'current';
			//
			$return['class']	= 'todo-value-status-current';
		}
		//
		return		$return;
	}