<?php defined('SYSPATH') OR die('No direct access allowed.');

class Model_User extends Model_Auth_User {

	// Relationships
	protected $_has_many = array
		(
			'user_tokens' => array('model' => 'user_token'),
			'roles'       => array('model' => 'role', 'through' => 'roles_users'),
			'tasks' => array('model' => 'task')
		);
	
	public function __toString()
    {
        return $this->username;
    }
	
	public function validate_create(& $array) 
	{
		// Initialise the validation library and setup some rules		
		$array = Validate::factory($array)
						->rules('password', $this->_rules['password'])
						->rules('username', $this->_rules['username'])
						->rules('email', $this->_rules['email'])
						->rules('password_confirm', $this->_rules['password_confirm'])
						->filter('username', 'trim')
						->filter('email', 'trim')
						->filter('password', 'trim')
						->filter('password_confirm', 'trim');
						//->callback('username', array( $this, 'username_available' ) );
		/*
 //username_available
		#Executes username callbacks defined in parent		
		foreach($this->callbacks['username'] as $callback){
			$array->callback('username', array($this, $callback));
		}
 
                #Executes email callbacks defined in parent	
		foreach($this->callbacks['email'] as $callback){
			$array->callback('email', array($this, $callback));
		}		*/
 
		return $array;
	}
}
