<?php
class User extends AppModel {

    var $name = 'User';
	var $displayField = 'username';
	var $validate = array(
		'username' => array(
			array('rule' => 'alphaNumeric', 'message' => 'Must be alhpanumeric'),
			array('rule' => array('minLength', 3), 'message' => 'Must be at least 3 characters long'),
			array('rule' => array('unique'), 'message' => 'Username already exists. Please, choose another one', 'on' => 'create'),
		),
		'password1' => array('rule' => 'notempty', 'on' => 'create'),
    );

	var $actsAs = array('Acl' => array('type' => 'requester'));

	var $belongsTo = array(
		'UserLevel' => array(
			'className' => 'UserLevel',
			'foreignKey' => 'user_level_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	function parentNode() {
		if (!$this->id && empty($this->data)) {
			return null;
		}
		$data = (!empty($this->data['User']['user_level_id']) ? $this->data : $this->read());
		if (empty($data['User']['user_level_id'])) {
			return null;
		} else {
			$this->UserLevel->id = $data['User']['user_level_id'];
			$levelNode = $this->UserLevel->node();
			return array('UserLevel' => array('id' => $levelNode[0]['Aro']['foreign_key']));
		}
	}
	
}
