<?php
class AdvancedSearchRewardsForm extends Form {

    public function __construct($controller) {      
        $this->setName('advanced_search');
        $this->setActionForm($controller.".php");
        switch($controller){
            case 'CustomerRewards':
                $actionController = '';
                break;
            default:
                $actionController = 'list';
                break;
        }
        $this->setActionController($actionController);
        $this->setMethod('post');
        $this->setDefaultFormLabelsColSize('4');
        $this->setDefaultFormElementsColSize('8');
        parent::__construct();
        $this->init();
    }

    public function init() {         
        $append = "<span class = 'btn input-group-addon'><i class='fa fa-calendar'></i></span>";
        $this->addElement(array(
            'type' => 'text',
            'name' => 'startDate',
            'label'=>'Fecha inicio',
            'required'=>false,
            'append'=>$append
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'endDate',
            'label'=>'Fecha fin',
            'required'=>false,
            'append'=>$append
        ));               
        
        $this->addElement(array(
            'type' => 'submit',
            'name' => 'search',
            'value'=> $this->_getTranslation('Buscar'),
            'class'=>'btn btn-primary'
        ));
    }
    
    public function getCustomerRewardsStatus(){
        $shipingRequestRepo = new CustomerRewardsRepository();        
        $tramiteStatus = $shipingRequestRepo->getListStatus();
        
        $array = array('0'=>'Seleccionar una opcion...');
        foreach($tramiteStatus as $idStatus => $descriptionStatus){
            $array[$idStatus] = $descriptionStatus;
        }    
        
        return $array;        
    }    
       
    public function getStringFiltersForm($controller){
        $formString = '';
        switch($controller){   
           case 'CustomerRewards':
                $customerRewardForm = new CustomerRewardsForm();                 
                
                $this->addElement(array('type'=>'text','name'=>'phone','label'=>'Telefono','class'=>'_maskPhone','optionals'=>array('maxlength'=>'14')));
                $this->addElement(array('type'=>'text','name'=>'name','label'=>'Nombre'));                
                $this->addElement(array('type'=>'text','name'=>'date_of_birth_start','label'=>'Fecha nacimiento','col-size-label'=>'5','col-size-element'=>'7'));   
                $this->addElement(array('type'=>'text','name'=>'date_of_birth_end','label'=>'Fecha nacimiento fin','col-size-label'=>'5','col-size-element'=>'7'));   
                $this->addElement(array('type'=>'text','name'=>'email','label'=>'Email')); 
                $this->addElement(array('type'=>'select','name'=>'register_store','label'=>'Sucursal de registro')); 
                $this->addElement(array('type'=>'text','name'=>'creado_fecha_inicio','label'=>'Fecha registro inicio', 'col-size-label'=>'5','col-size-element'=>'7')); 
                $this->addElement(array('type'=>'text','name'=>'creado_fecha_fin','label'=>'Fecha registro fin', 'col-size-label'=>'5','col-size-element'=>'7')); 
                $this->addElement(array('type'=>'text','name'=>'rewards_total','label'=>'Total puntos','class'=>'mg_decimal')); 
                $this->addElement(array('type'=>'text','name'=>'rewards','label'=>'Puntos disponibles','class'=>'mg_decimal')); 
                $this->addElement(array('type'=>'select','name'=>'status','label'=>'Status'));
                $this->setPropiedad('status', array('multiOptions'=>$this->getCustomerRewardsStatus()));                               
               
                $arrayStores = $customerRewardForm->getListStores();
                if(!key_exists('0', $arrayStores)){$arrayStores[0] = 'Seleccionar una opcion...';}
                $this->setPropiedad('register_store', array('multiOptions'=>$arrayStores));                 
                             
                $formString .= $this->getElementString('phone');
                $formString .= $this->getElementString('name');  
                $formString .= $this->getElementString('date_of_birth_start');    
                $formString .= $this->getElementString('date_of_birth_end');
                $formString .= $this->getElementString('email');    
                $formString .= $this->getElementString('register_store');                 
                $formString .= $this->getElementString('creado_fecha_inicio');       
                $formString .= $this->getElementString('creado_fecha_fin');      
                $formString .= $this->getElementString('rewards_total');
                $formString .= $this->getElementString('rewards');
                $formString .= $this->getElementString('status');          
                
                break;         
        }       
        
        return $formString;
    }

}
