<?php

class AdminUserForm extends PhonalisaRecord
{
    
    public $name;
    public $password;
    public $confirmPassword;
    public $firstname;
    public $lastname;
    public $extension;
    public $email;
    public $pin;
    

    public static function myAttributes()
    {
        return array(
            "name" => "name",
            "password" => "password",
            "confirmPassword" => "confirmPassword",
            "firstname" => "firstname",
            "lastname" => "lastname",
            "extension" => "extension",
            "email" => "email",
            "pin" => "pin"
        );
    }

    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function rules()
    {
        return array(
            
            
            array('firstname, lastname', 'safe'),
            array('extension, pin', 'numerical', 'integerOnly' => true),
            array('extension', 'length', 'min' => 2, 'max' => 10),
            array('pin', 'length', 'min' => 3, 'max' => 10),
            
            array('extension', 'ext.PhonalisaValidators.uniqueExtension'),
            array('password', 'ext.PhonalisaValidators.passwordStrength'),
            array('confirmPassword', 'compare', 'compareAttribute' => 'password', 'message' => __('USER_MODEL_PHONESETTINGS_CREDENTIALS_PASSWORD_REPEAT_ERROR_MESSAGE')),
            array(
                'extension',
                'match',
                'pattern' => '/^[1-9]/',
                'message' => __('USER_MODEL_SHOULD_NOT_START_WITH_ZERO_ERROR_MESSAGE')
            ),
            
            array('email', 'email'),
            array(
                'name',
                'match',
                'pattern' => '/^[1-9a-z]/',
                'message' => __('USER_MODEL_SHOULD_NOT_START_WITH_ZERO_OR_PUNCTUATION_CHARACTERS_ERROR_MESSAGE'),
            ),
            array(
                'name',
                'match',
                'pattern' => '/^[a-z0-9_.]{1,}$/',
                'message' => __('USER_MODEL_SHOULD_ONLY_CONTAIN_UNDERLINE_AND_DOT_PUNCTUATION_CHARACTERS_ERROR_MESSAGE'),
            ),
            
            
            array(
                'name,
                password,
                confirmPassword,
                extension,
                pin',
                'required'
            ),
            array("firstname, lastname", 'safe'),
        );
    }
    
    public function attributeLabels()
    {
        return array(
            'name' => __('USERS_MODEL_NAME'),
            'firstname' => __('USERS_MODEL_FIRSTNAME'),
            'lastname' => __('USERS_MODEL_LASTNAME'),
            'email' => __('USERS_MODEL_EMAIL'),
            'pin' => __('USERS_MODEL_PIN'),
            'extension' => __('USERS_MODEL_EXTENSION'),
            'password' => __('USERS_MODEL_PASSWORD'),
            'confirmPassword' => __('USERS_MODEL_CONFIRM_PASSWORD'),
        );
    }
    
    public function extensionOwner()
    {
        $admin = User::model()->findByAttributes(array("isSystemAdmin" => "1"));
        return $admin;
    }
}
