<?php
class ScheduleEmployeeForm extends Form {

    public function __construct() {
        $this->setActionForm('ScheduleEmployee.php');
        $this->setName('schedule_employee');
        $this->setClass('schedule_employee');
        $this->setMethod('post');
        $this->setDefaultFormLabelsColSize(4);
        $this->setDefaultFormElementsColSize(8);
        parent::__construct();
        $this->init();
    }

    public function init() {              
        $this->addElement(array(
            'type' => 'select',
            'name' => 'store_id',
            'label'=>'Sucursal',
            'multiOptions'=>$this->getListStores(),
            'required'=>true
         ));
        
        $this->addElement(array(
            'type' => 'select',
            'name' => 'period_id',
            'label'=>'Periodo',
            'multiOptions' => $this->getListPeriods(),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'hidden',
            'name' => 'start_period',
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'hidden',
            'name' => 'end_period',
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'hidden',
            'name' => 'scheduled_hours',
            'value'=>'0',
            'class'=>'mg_decimal',
            'required'=> true
        ));
    }
    
    public function getListPeriods(){
        $repository = new ScheduleEmployeeRepository();
        $list = $repository->getListPeriodsForScheduleEmployee();
         
        $array = array();
        if($list){
            foreach($list as $key => $value){
                $array[$key] = $value;
            }
        }       
        return $array;            
    }    
    
     public function getListStores(){
        $repo = new StoreRepository();
        $result = $repo->getListSelectStores();
        
        $login = new Login();
        $storeIdArray = $login->getStoreIdArray();
        
        if($login->getRole()!='1'){
            if ($result) {
                $array = array();
                foreach ($result as $key => $value) {
                    if(in_array($key, $storeIdArray)){$array[$key] = $value;}                    
                }
            }   
        }else{
            $array = array(''=>'Seleccionar una opcion...');
            if ($result) {               
                foreach ($result as $key => $value) {
                    $array[$key] = $value;
                }
            }   
        } 
        return $array;
    }
}
