<?php

class NumberTranslationScopeType {

    const preRouting = 0;
    const preFromGateway = 1;
    const preToGateway = 2;
    const preFromUser = 3;
    const preToUser = 4;
    const preFromQueue = 5;
    const preToQueue = 6;
    const preFromIVR = 7;
    const preToIVR = 8;
    const preFromExternalHost = 9;
    const preToExternalHost = 10;

}


class NumberTranslation extends PhonalisaRecord {

    public  $id;
    public  $sort;
    public  $active;
    public  $destination;
    public  $new_destination;
    public  $source_number;
    public  $new_source_number;
    //     public  $source_name;
    //     public  $new_source_name;
    public  $description;

    public  $sip_headers;
    public $scope;

    public static function myAttributes() {

        return array(
            //                 'id'=>'id',
            'active'=>'active',
            'sort'=>'sort',
            'scope' => 'scope',
            'destination'=>'destination',
            'new_destination'=>'new_destination',
            'source_number'=>'source_number',
            'new_source_number'=>'new_source_number',
            //                 'source_name'=>'source_name',
            //                 'new_source_name'=>'new_source_name',
            'description'=>'description',
            'sip_headers'=>'sip_headers',
        );
    }


    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Calendar 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 strtolower('NumberTranslation');
    }


    /**
     * @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('destination, new_destination, sort','required'),
            array('active','boolean'),
            array('source_number, new_source_number, source_name, new_source_name, description, sip_headers, scope','safe' ),
        );
    }


    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }


    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'active'=>__('NUMBERTRANSLATION_MODEL_ACTIVE'),
            'destination'=>__('NUMBERTRANSLATION_MODEL_DESTINATION'),
            'new_destination'=>__('NUMBERTRANSLATION_MODEL_NEW_DESTINATION'),
            'source_number'=>__('NUMBERTRANSLATION_MODEL_SOURCE_NUMBER'),
            'new_source_number'=>__('NUMBERTRANSLATION_MODEL_NEW_SOURCE_NUMBER'),
            //                 'source_name'=>__('NUMBERTRANSLATION_MODEL_SOURCE_NAME'),
            //                 'new_source_name'=>__('NUMBERTRANSLATION_MODEL_NEW_SOURCE_NAME'),
            'description'=>__('NUMBERTRANSLATION_MODEL_DESCRIPTION'),
            'sip_headers'=>__('NUMBERTRANSLATION_MODEL_SIP_HEADERS'),
            'scope'=>__('NUMBERTRANSLATION_MODEL_SCOPE'),
            'translatedScope'=>__('NUMBERTRANSLATION_MODEL_SCOPE'),
        );
    }


    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search($order = 'sort') {

        // Warning: Please modify the following code to remove attributes that
        // should not be searched.
        $arrayModels = $this->findAll();
        $dataProvider=new CArrayDataProvider($arrayModels, array(
				'id'=>'key',
				'sort'=>array('defaultOrder'=>'sort ASC'),
				// 'pagination'=>false,
				'pagination'=>array(
                    'pageSize'=> getGridPageSize('number-translation-grid'),
                ),
		));
		

		
        return $dataProvider;
    }
    


    public function getScopeOptions(){
        return array(
            NumberTranslationScopeType::preRouting => __('NUMBERTRANSLATION_MODEL_SCOPE_PREROUTING'), 
            NumberTranslationScopeType::preFromGateway => __('NUMBERTRANSLATION_MODEL_SCOPE_FROM_GATEWAY'),
            NumberTranslationScopeType::preToGateway => __('NUMBERTRANSLATION_MODEL_SCOPE_TO_GATEWAY'),
            NumberTranslationScopeType::preFromUser => __('NUMBERTRANSLATION_MODEL_SCOPE_FROM_USER'),
            NumberTranslationScopeType::preToUser => __('NUMBERTRANSLATION_MODEL_SCOPE_TO_USER'),
            NumberTranslationScopeType::preFromQueue => __('NUMBERTRANSLATION_MODEL_SCOPE_FROM_QUEUE'),
            NumberTranslationScopeType::preToQueue => __('NUMBERTRANSLATION_MODEL_SCOPE_TO_QUEUE'),
            NumberTranslationScopeType::preFromIVR => __('NUMBERTRANSLATION_MODEL_SCOPE_FROM_IVR'),
            NumberTranslationScopeType::preToIVR => __('NUMBERTRANSLATION_MODEL_SCOPE_TO_IVR'),
            NumberTranslationScopeType::preFromExternalHost => __('NUMBERTRANSLATION_MODEL_SCOPE_FROM_EXTERNAL_HOST'),
            NumberTranslationScopeType::preToExternalHost => __('NUMBERTRANSLATION_MODEL_SCOPE_TO_EXTERNAL_HOST'),
        );        
    }
    
    public function getTranslatedScope(){
        $scopeOptions = $this->getScopeOptions();
        return $scopeOptions[(int)$this->scope];
    }

}