<?php
class User extends AppModel {

    var $name = 'User';


    var $displayField = 'username';

    var $validate = array(
	    'first_name' => array('notEmpty'),
	    'email' => array('email')

    );

    var $order = 'first_name ASC';

    /* TO DO: Fix up this validation stuff
	var $validate = array(
		'username' => array(
		'rule' => 'unique', 
		'required' => true,
		'message' => 'Username must be unique'
		),
		
	//	'password' => array('maxlength'),
		'email' => array('email'),
	//	'job_title' => array('custom')
	);
    */
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $hasMany = array(
	    'Enquiry' => array('className' => 'Enquiry',
			    'foreignKey' => 'user_id',
			    'dependent' => false,
			    'conditions' => '',
			    'fields' => '',
			    'order' => '',
			    'limit' => '',
			    'offset' => '',
			    'exclusive' => '',
			    'finderQuery' => '',
			    'counterQuery' => ''
	    ),
	    'Email' => array('className'=> 'Email',
			    'foreignKey'=> 'user_id',
	    )
    );


    var $belongsTo = array(
	    'Principle' => array('className'=>'Principle',
			    'foreignKey' =>'principle_id',

	    ),
	    'Customer' => array('className'=>'Customer',
			    'foreignKey' =>'customer_id',

	    )
    );



	function getPrincipleContacts($principleID) {
	    return $this->find('all', array('conditions'=>array('User.principle_id'=>$principleID)));
	}

	function getUsersList() {
	    return $this->find('list', array('conditions'=>array('User.type'=>'user')));
	}

}
?>
