<?php

class SpeedDial extends PhonalisaRecord
{

    const SPEED_DIAL_MAX_KEY_LENGTH = 4;

    public $id;
    public $key;
    public $owner;
    public $phoneNumber;
    public $description;
    public $profile_id;
    public $file;

    public static function myAttributes()
    {
        return array(
            'key' => 'key',
            'owner' => 'owner',
            'phoneNumber' => 'phoneNumber',
            'description' => 'description',
            'profile_id' => 'profile_id',
        );
    }

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return PhoneKey the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'speed_dial';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('key, phoneNumber', 'required'),
            array('key, owner, phoneNumber, description, profile_id', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, key, owner, phoneNumber, description, profile_id', 'safe', 'on' => 'search'),
            array('key', 'ext.PhonalisaValidators.isUnique', "aditionalComparePropertys" => array("profile_id"), "except" => array("createUserSpeedDial", "fileValidation")),
            array('key', 'ext.PhonalisaValidators.isUnique', "aditionalComparePropertys" => array("owner"), "on" => "createUserSpeedDial"),
            array('key', 'length', 'max' => SpeedDial::SPEED_DIAL_MAX_KEY_LENGTH)
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => __('SPEED_DIAL_MODEL_ID'),
            'key' => __('SPEED_DIAL_MODEL_KEY'),
            'owner' => __('SPEED_DIAL_MODEL_OWNER'),
            'phoneNumber' => __('SPEED_DIAL_MODEL_PHONE_NUMBER'),
            'description' => __('SPEED_DIAL_MODEL_DESCRIPTION'),
            'profile_id' => __('SPEED_DIAL_LIST_ID'),
        );
    }

    public function __toString()
    {
        return $this->id;
    }
}
